diff options
-rw-r--r-- | drumgizmo/drumgizmoc.cc | 20 | ||||
-rw-r--r-- | drumgizmo/enginefactory.cc | 56 | ||||
-rw-r--r-- | drumgizmo/enginefactory.h | 54 |
3 files changed, 101 insertions, 29 deletions
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc index 14ebe64..25012f8 100644 --- a/drumgizmo/drumgizmoc.cc +++ b/drumgizmo/drumgizmoc.cc @@ -24,6 +24,8 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <iostream> + #include <config.h> #include <getopt.h> @@ -226,9 +228,19 @@ int CliMain::run(int argc, char *argv[]) return 1; } - JackClientPtr client{nullptr}; - - auto ie = createInputEngine(client, inputengine); + EngineFactory factory; + std::cout << "Available Input Engines = { "; + for (auto const & name: factory.getInputEngines()) { + std::cout << name << " "; + } + std::cout << "}\n"; + std::cout << "Available Output Engines = { "; + for (auto const & name: factory.getOutputEngines()) { + std::cout << name << " "; + } + std::cout << "}\n"; + + auto ie = factory.createInput(inputengine); if(ie == NULL) { printf("Invalid input engine: %s\n", inputengine.c_str()); @@ -267,7 +279,7 @@ int CliMain::run(int argc, char *argv[]) return 1; } - auto oe = createOutputEngine(client, outputengine); + auto oe = factory.createOutput(outputengine); if(oe == NULL) { printf("Invalid output engine: %s\n", outputengine.c_str()); diff --git a/drumgizmo/enginefactory.cc b/drumgizmo/enginefactory.cc index 8c40a28..121abdd 100644 --- a/drumgizmo/enginefactory.cc +++ b/drumgizmo/enginefactory.cc @@ -29,31 +29,53 @@ #include "enginefactory.h" #include "jackclient.h" +EngineFactory::EngineFactory() + : input{} + , output{} +#ifdef USE_JACK + , jack{nullptr} +#endif +{ + // list available input engines #ifdef HAVE_INPUT_DUMMY -#include "input/inputdummy.h" + input.push_back("inputdummy"); #endif - #ifdef HAVE_INPUT_MIDIFILE -#include "input/midifile.h" + input.push_back("midifile"); #endif - + + // list available output engines #ifdef HAVE_OUTPUT_DUMMY -#include "output/outputdummy.h" + output.push_back("outputdummy"); #endif - #ifdef HAVE_OUTPUT_WAVFILE -#include "output/wavfile.h" + output.push_back("wavfile"); #endif - #ifdef HAVE_OUTPUT_ALSA -#include "output/alsa.h" + output.push_back("alsa"); #endif - #ifdef HAVE_OUTPUT_JACKAUDIO -#include "output/jackaudio.h" + output.push_back("jackaudio"); +#endif +} + +#ifdef USE_JACK +void EngineFactory::prepareJack() { + if (jack == nullptr) { + jack = std::make_unique<JackClient>(); + } +} #endif -InputEnginePtr createInputEngine(JackClientPtr& jack, std::string const & name) { +std::list<std::string> const & EngineFactory::getInputEngines() const { + return input; +} + +std::list<std::string> const & EngineFactory::getOutputEngines() const { + return output; +} + +std::unique_ptr<AudioInputEngine> EngineFactory::createInput(std::string const & name) { #ifdef HAVE_INPUT_DUMMY if (name == "dummy") { return std::make_unique<DummyInputEngine>(); @@ -67,11 +89,11 @@ InputEnginePtr createInputEngine(JackClientPtr& jack, std::string const & name) // todo: add more engines - std::cerr << "Unsupported input engine '" << name << "'\n"; + std::cerr << "[EngineFactory] Unsupported input engine '" << name << "'\n"; return nullptr; } -OutputEnginePtr createOutputEngine(JackClientPtr& jack, std::string const & name) { +std::unique_ptr<AudioOutputEngine> EngineFactory::createOutput(std::string const & name) { #ifdef HAVE_OUTPUT_DUMMY if (name == "dummy") { return std::make_unique<DummyOutputEngine>(); @@ -89,15 +111,13 @@ OutputEnginePtr createOutputEngine(JackClientPtr& jack, std::string const & name #endif #ifdef HAVE_OUTPUT_JACKAUDIO if (name == "jackaudio") { - if (jack.get() == nullptr) { - jack = std::make_unique<JackClient>(); - } + prepareJack(); return std::make_unique<JackaudioOutputEngine>(*jack); } #endif // todo: add more engines - std::cerr << "Unsupported output engine '" << name << "'\n"; + std::cerr << "[EngineFactory] Unsupported output engine '" << name << "'\n"; return nullptr; } diff --git a/drumgizmo/enginefactory.h b/drumgizmo/enginefactory.h index 93ce67b..c599040 100644 --- a/drumgizmo/enginefactory.h +++ b/drumgizmo/enginefactory.h @@ -25,18 +25,58 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #pragma once +#include <list> +#include <string> #include <memory> #include "cpp11fix.h" // required for c++11 #include "audioinputengine.h" #include "audiooutputengine.h" -// todo: ifdef jack enabled -#include "jackclient.h" +#if defined(HAVE_INPUT_JACKMIDI) || defined(HAVE_OUTPUT_JACKAUDIO) + #define USE_JACK + #include "jackclient.h" +#endif -using JackClientPtr = std::unique_ptr<JackClient>; -using InputEnginePtr = std::unique_ptr<AudioInputEngine>; -using OutputEnginePtr = std::unique_ptr<AudioOutputEngine>; +#ifdef HAVE_INPUT_DUMMY + #include "input/inputdummy.h" +#endif -InputEnginePtr createInputEngine(JackClientPtr& jack, std::string const & name); -OutputEnginePtr createOutputEngine(JackClientPtr& jack, std::string const & name); +#ifdef HAVE_INPUT_MIDIFILE + #include "input/midifile.h" +#endif + +#ifdef HAVE_OUTPUT_DUMMY + #include "output/outputdummy.h" +#endif + +#ifdef HAVE_OUTPUT_WAVFILE + #include "output/wavfile.h" +#endif + +#ifdef HAVE_OUTPUT_ALSA + #include "output/alsa.h" +#endif + +#ifdef HAVE_OUTPUT_JACKAUDIO + #include "output/jackaudio.h" +#endif + +class EngineFactory { + private: + std::list<std::string> input, output; // available engines +#ifdef USE_JACK + std::unique_ptr<JackClient> jack; + + void prepareJack(); +#endif + + public: + EngineFactory(); + + std::list<std::string> const & getInputEngines() const; + std::list<std::string> const & getOutputEngines() const; + + std::unique_ptr<AudioInputEngine> createInput(std::string const & name); + std::unique_ptr<AudioOutputEngine> createOutput(std::string const & name); +}; |