diff options
-rw-r--r-- | drumgizmo/Makefile.am | 13 | ||||
-rw-r--r-- | drumgizmo/enginefactory.cc | 14 | ||||
-rw-r--r-- | drumgizmo/enginefactory.h | 19 | ||||
-rw-r--r-- | drumgizmo/input/inputdummy.cc | 36 | ||||
-rw-r--r-- | drumgizmo/input/inputdummy.h | 4 | ||||
-rw-r--r-- | drumgizmo/input/jackmidi.cc | 16 | ||||
-rw-r--r-- | drumgizmo/input/jackmidi.h | 10 | ||||
-rw-r--r-- | drumgizmo/input/midifile.cc | 44 | ||||
-rw-r--r-- | drumgizmo/input/midifile.h | 11 | ||||
-rw-r--r-- | drumgizmo/jackclient.cc | 26 | ||||
-rw-r--r-- | drumgizmo/jackclient.h | 2 | ||||
-rw-r--r-- | drumgizmo/output/alsa.cc | 33 | ||||
-rw-r--r-- | drumgizmo/output/alsa.h | 9 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio.cc | 41 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio.h | 10 | ||||
-rw-r--r-- | drumgizmo/output/outputdummy.h | 5 | ||||
-rw-r--r-- | drumgizmo/output/wavfile.cc | 5 | ||||
-rw-r--r-- | drumgizmo/output/wavfile.h | 7 |
18 files changed, 203 insertions, 102 deletions
diff --git a/drumgizmo/Makefile.am b/drumgizmo/Makefile.am index 61eef4a..01a69af 100644 --- a/drumgizmo/Makefile.am +++ b/drumgizmo/Makefile.am @@ -13,9 +13,7 @@ drumgizmo_LDFLAGS = drumgizmo_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) \ -I$(top_srcdir)/include -I$(top_srcdir)/src \ -I$(top_srcdir)/hugin -DWITH_HUG_MUTEX -DWITH_HUG_FILTER \ - $(JACK_CFLAGS) $(SSEFLAGS) \ - -DINPUT_PLUGIN_DIR=\"${INPUT_PLUGIN_DIR}\" \ - -DOUTPUT_PLUGIN_DIR=\"${OUTPUT_PLUGIN_DIR}\" + $(JACK_CFLAGS) $(SSEFLAGS) drumgizmo_CFLAGS = -DWITH_HUG_MUTEX -DWITH_HUG_FILTER @@ -71,6 +69,13 @@ endif # HAVE_OUTPUT_JACKAUDIO EXTRA_DIST = \ drumgizmoc.h \ jackclient.h \ - enginefactory.h + enginefactory.h \ + input/inputdummy.h \ + input/jackmidi.h \ + input/midifile.h \ + output/alsa.h \ + output/jackaudio.h \ + output/outputdummy.h \ + output/wavfile.h endif # ENABLE_CLI diff --git a/drumgizmo/enginefactory.cc b/drumgizmo/enginefactory.cc index b5368ac..e88f679 100644 --- a/drumgizmo/enginefactory.cc +++ b/drumgizmo/enginefactory.cc @@ -29,9 +29,11 @@ #include "cpp11fix.h" // required for c++11 #include "enginefactory.h" -EngineFactory::EngineFactory() : input{}, output {} +EngineFactory::EngineFactory() + : input{} + , output{} #ifdef USE_JACK -, jack { nullptr } + , jack { nullptr } #endif { // list available input engines @@ -70,18 +72,18 @@ void EngineFactory::prepareJack() } #endif -std::list<std::string> const &EngineFactory::getInputEngines() const +const std::list<std::string>& EngineFactory::getInputEngines() const { return input; } -std::list<std::string> const &EngineFactory::getOutputEngines() const +const std::list<std::string>& EngineFactory::getOutputEngines() const { return output; } std::unique_ptr<AudioInputEngine> -EngineFactory::createInput(std::string const &name) +EngineFactory::createInput(const std::string& name) { #ifdef HAVE_INPUT_DUMMY if (name == "dummy") @@ -110,7 +112,7 @@ EngineFactory::createInput(std::string const &name) } std::unique_ptr<AudioOutputEngine> -EngineFactory::createOutput(std::string const &name) +EngineFactory::createOutput(const std::string& name) { #ifdef HAVE_OUTPUT_DUMMY if (name == "dummy") diff --git a/drumgizmo/enginefactory.h b/drumgizmo/enginefactory.h index 2d8da80..02a84ae 100644 --- a/drumgizmo/enginefactory.h +++ b/drumgizmo/enginefactory.h @@ -67,7 +67,16 @@ class EngineFactory { -private: +public: + EngineFactory(); + + const std::list<std::string>& getInputEngines() const; + const std::list<std::string>& getOutputEngines() const; + + std::unique_ptr<AudioInputEngine> createInput(const std::string& name); + std::unique_ptr<AudioOutputEngine> createOutput(const std::string& name); + +protected: std::list<std::string> input, output; // available engines #ifdef USE_JACK @@ -76,12 +85,4 @@ private: 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); }; diff --git a/drumgizmo/input/inputdummy.cc b/drumgizmo/input/inputdummy.cc index f2d33b7..20ffd08 100644 --- a/drumgizmo/input/inputdummy.cc +++ b/drumgizmo/input/inputdummy.cc @@ -26,24 +26,42 @@ */ #include "inputdummy.h" -DummyInputEngine::DummyInputEngine() {} +DummyInputEngine::DummyInputEngine() +{ +} -DummyInputEngine::~DummyInputEngine() {} +DummyInputEngine::~DummyInputEngine() +{ +} -bool DummyInputEngine::init(Instruments &instruments) { return true; } +bool DummyInputEngine::init(Instruments& instruments) +{ + return true; +} -void DummyInputEngine::setParm(std::string parm, std::string value) {} +void DummyInputEngine::setParm(std::string parm, std::string value) +{ +} -bool DummyInputEngine::start() { return true; } +bool DummyInputEngine::start() +{ + return true; +} -void DummyInputEngine::stop() {} +void DummyInputEngine::stop() +{ +} -void DummyInputEngine::pre() {} +void DummyInputEngine::pre() +{ +} -event_t *DummyInputEngine::run(size_t pos, size_t len, size_t *nevents) +event_t* DummyInputEngine::run(size_t pos, size_t len, size_t* nevents) { nevents = 0u; return nullptr; } -void DummyInputEngine::post() {} +void DummyInputEngine::post() +{ +} diff --git a/drumgizmo/input/inputdummy.h b/drumgizmo/input/inputdummy.h index fb84443..30d0599 100644 --- a/drumgizmo/input/inputdummy.h +++ b/drumgizmo/input/inputdummy.h @@ -34,11 +34,11 @@ public: ~DummyInputEngine(); // based on AudioInputEngine - bool init(Instruments &instruments) override; + bool init(Instruments& instruments) override; void setParm(std::string parm, std::string value) override; bool start() override; void stop() override; void pre() override; - event_t *run(size_t pos, size_t len, size_t *nevents) override; + event_t* run(size_t pos, size_t len, size_t* nevents) override; void post() override; }; diff --git a/drumgizmo/input/jackmidi.cc b/drumgizmo/input/jackmidi.cc index 5ae6add..386adac 100644 --- a/drumgizmo/input/jackmidi.cc +++ b/drumgizmo/input/jackmidi.cc @@ -30,11 +30,18 @@ #include "cpp11fix.h" // required for c++11 #include "jackmidi.h" -int const NOTE_ON = 0x90; +static int const NOTE_ON = 0x90; JackMidiInputEngine::JackMidiInputEngine(JackClient &client) - : AudioInputEngine{}, JackProcess{}, client(client), port{nullptr}, - midimap{}, midi_mapper{}, pos{0u}, list{nullptr}, listsize{0u} + : AudioInputEngine{} + , JackProcess{} + , client(client) + , port{nullptr} + , midimap{} + , midi_mapper{} + , pos{0u} + , list{nullptr} + , listsize{0u} { client.add(*this); } @@ -96,8 +103,7 @@ event_t *JackMidiInputEngine::run(size_t pos, size_t len, size_t *nevents) { *nevents = listsize; event_t *l = list; - printf("Owning raw pointer at drumgizmo/input/jackmidi.cc - GET RID OF " - "THEM!\n"); + // todo: get rid of malloc list = (event_t *)malloc(sizeof(event_t) * 1000); listsize = 0; return l; diff --git a/drumgizmo/input/jackmidi.h b/drumgizmo/input/jackmidi.h index 41a3e55..e129071 100644 --- a/drumgizmo/input/jackmidi.h +++ b/drumgizmo/input/jackmidi.h @@ -34,7 +34,9 @@ #include "midimapparser.h" #include "../jackclient.h" -class JackMidiInputEngine : public AudioInputEngine, public JackProcess +class JackMidiInputEngine + : public AudioInputEngine + , public JackProcess { public: JackMidiInputEngine(JackClient &client); @@ -42,12 +44,12 @@ public: // based on AudioInputEngine bool isMidiEngine() override; - bool init(Instruments &instruments) override; + bool init(Instruments& instruments) override; void setParm(std::string parm, std::string value) override; bool start() override; void stop() override; void pre() override; - event_t *run(size_t pos, size_t len, size_t *nevents) override; + event_t* run(size_t pos, size_t len, size_t* nevents) override; void post() override; // based on JackProcess @@ -61,6 +63,6 @@ private: MidiMapper midi_mapper; std::size_t pos; - event_t *list; + event_t* list; size_t listsize; }; diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc index 0cc9dea..4e36c9d 100644 --- a/drumgizmo/input/midifile.cc +++ b/drumgizmo/input/midifile.cc @@ -28,13 +28,17 @@ #include "midifile.h" -int const NOTE_ON = 0x90; +static int const NOTE_ON = 0x90; MidifileInputEngine::MidifileInputEngine() - : smf{nullptr}, current_event{nullptr}, file{}, midimap{}, speed{1.f}, - track{-1} // all tracks - , - loop{false}, offset{0.0} + : smf{nullptr} + , current_event{nullptr} + , file{} + , midimap{} + , speed{1.f} + , track{-1} // all tracks + , loop{false} + , offset{0.0} { } @@ -46,9 +50,12 @@ MidifileInputEngine::~MidifileInputEngine() } } -bool MidifileInputEngine::isMidiEngine() { return true; } +bool MidifileInputEngine::isMidiEngine() +{ + return true; +} -bool MidifileInputEngine::init(Instruments &instruments) +bool MidifileInputEngine::init(Instruments& instruments) { if (file == "") { @@ -119,11 +126,18 @@ void MidifileInputEngine::setParm(std::string parm, std::string value) } } -bool MidifileInputEngine::start() { return true; } +bool MidifileInputEngine::start() +{ + return true; +} -void MidifileInputEngine::stop() {} +void MidifileInputEngine::stop() +{ +} -void MidifileInputEngine::pre() {} +void MidifileInputEngine::pre() +{ +} event_t *MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) { @@ -151,8 +165,7 @@ event_t *MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) if (evs == nullptr) { - printf("Owning raw pointer at drumgizmo/input/midifile.cc - GET RID " - "OF THEM!\n"); + // todo: get rid of malloc evs = (event_t *)malloc(sizeof(event_t) * 1000); } @@ -193,8 +206,7 @@ event_t *MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) { if (evs == nullptr) { - printf("Owning raw pointer at drumgizmo/input/midifile.cc - GET RID OF " - "THEM!\n"); + // todo: get rid of malloc evs = (event_t *)malloc(sizeof(event_t) * 1000); } evs[num_events].type = TYPE_STOP; @@ -206,4 +218,6 @@ event_t *MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) return evs; } -void MidifileInputEngine::post() {} +void MidifileInputEngine::post() +{ +} diff --git a/drumgizmo/input/midifile.h b/drumgizmo/input/midifile.h index 5efcc72..a7e4cf0 100644 --- a/drumgizmo/input/midifile.h +++ b/drumgizmo/input/midifile.h @@ -34,7 +34,8 @@ #include "midimapper.h" #include "midimapparser.h" -class MidifileInputEngine : public AudioInputEngine +class MidifileInputEngine + : public AudioInputEngine { public: MidifileInputEngine(); @@ -42,17 +43,17 @@ public: // based on AudioInputEngine bool isMidiEngine() override; - bool init(Instruments &instruments) override; + bool init(Instruments& instruments) override; void setParm(std::string parm, std::string value) override; bool start() override; void stop() override; void pre() override; - event_t *run(size_t pos, size_t len, size_t *nevents) override; + event_t* run(size_t pos, size_t len, size_t* nevents) override; void post() override; private: - smf_t *smf; - smf_event_t *current_event; + smf_t* smf; + smf_event_t* current_event; MidiMapper midi_mapper; diff --git a/drumgizmo/jackclient.cc b/drumgizmo/jackclient.cc index eb35bf6..042329c 100644 --- a/drumgizmo/jackclient.cc +++ b/drumgizmo/jackclient.cc @@ -32,11 +32,10 @@ JackProcess::~JackProcess() {} // -------------------------------------------------------------------- -JackPort::JackPort(JackClient &client, std::string const &name, +JackPort::JackPort(JackClient &client, const std::string &name, const char *type, JackPortFlags flags) - : client{client.client} // register jack port for given client - , - port{jack_port_register(this->client, name.c_str(), type, flags, 0)} + : client{client.client} // register jack port for given client + , port{jack_port_register(this->client, name.c_str(), type, flags, 0)} { } @@ -51,12 +50,15 @@ JackPort::~JackPort() // -------------------------------------------------------------------- -int _wrap_jack_process(jack_nframes_t nframes, void *arg) +static int _wrap_jack_process(jack_nframes_t nframes, void *arg) { return static_cast<JackClient *>(arg)->process(nframes); } -JackClient::JackClient() : client{nullptr}, processes{}, is_active{false} +JackClient::JackClient() + : client{nullptr} + , processes{} + , is_active{false} { jack_status_t status; client = jack_client_open("DrumGizmo", JackNullOption, &status); @@ -71,9 +73,15 @@ JackClient::~JackClient() } } -void JackClient::add(JackProcess &process) { processes.insert(&process); } +void JackClient::add(JackProcess &process) +{ + processes.insert(&process); +} -void JackClient::remove(JackProcess &process) { processes.erase(&process); } +void JackClient::remove(JackProcess &process) +{ + processes.erase(&process); +} void JackClient::activate() { @@ -86,7 +94,7 @@ void JackClient::activate() int JackClient::process(jack_nframes_t num_frames) { - for (auto &ptr : processes) + for (auto& ptr : processes) { ptr->process(num_frames); } diff --git a/drumgizmo/jackclient.h b/drumgizmo/jackclient.h index ebfc28d..b35c978 100644 --- a/drumgizmo/jackclient.h +++ b/drumgizmo/jackclient.h @@ -47,7 +47,7 @@ public: // RAII-wrapper for jack_port_t struct JackPort { - JackPort(JackClient &client, std::string const &name, const char *type, + JackPort(JackClient &client, const std::string &name, const char *type, JackPortFlags flags); ~JackPort(); diff --git a/drumgizmo/output/alsa.cc b/drumgizmo/output/alsa.cc index 26cb0cf..c577c72 100644 --- a/drumgizmo/output/alsa.cc +++ b/drumgizmo/output/alsa.cc @@ -33,11 +33,11 @@ int const BUFFER_SIZE = 40960; struct AlsaInitError { int const code; - std::string const msg; + const std::string msg; - AlsaInitError(int op_code, std::string const &msg) : code{code}, msg{msg} {} + AlsaInitError(int op_code, const std::string &msg) : code{code}, msg{msg} {} - static inline void test(int code, std::string const &msg) + static inline void test(int code, const std::string &msg) { if (code < 0) { @@ -47,8 +47,13 @@ struct AlsaInitError }; AlsaOutputEngine::AlsaOutputEngine() - : handle{nullptr}, params{nullptr}, data{}, num_channels{0u}, - dev{"default"}, srate{44100}, frames{32} + : handle{nullptr} + , params{nullptr} + , data{} + , num_channels{0u} + , dev{"default"} + , srate{44100} + , frames{32} { } @@ -144,11 +149,18 @@ void AlsaOutputEngine::setParm(std::string parm, std::string value) } } -bool AlsaOutputEngine::start() { return true; } +bool AlsaOutputEngine::start() +{ + return true; +} -void AlsaOutputEngine::stop() {} +void AlsaOutputEngine::stop() +{ +} -void AlsaOutputEngine::pre(size_t nsamples) {} +void AlsaOutputEngine::pre(size_t nsamples) +{ +} void AlsaOutputEngine::run(int ch, sample_t *samples, size_t nsamples) { @@ -165,4 +177,7 @@ void AlsaOutputEngine::post(size_t nsamples) snd_pcm_writei(handle, data.data(), nsamples); } -size_t AlsaOutputEngine::samplerate() { return srate; } +size_t AlsaOutputEngine::samplerate() +{ + return srate; +} diff --git a/drumgizmo/output/alsa.h b/drumgizmo/output/alsa.h index 81d83cc..70b3f1f 100644 --- a/drumgizmo/output/alsa.h +++ b/drumgizmo/output/alsa.h @@ -34,7 +34,8 @@ #include "audiooutputengine.h" -class AlsaOutputEngine : public AudioOutputEngine +class AlsaOutputEngine + : public AudioOutputEngine { public: AlsaOutputEngine(); @@ -46,13 +47,13 @@ public: bool start() override; void stop() override; void pre(size_t nsamples) override; - void run(int ch, sample_t *samples, size_t nsamples) override; + void run(int ch, sample_t* samples, size_t nsamples) override; void post(size_t nsamples) override; size_t samplerate() override; private: - snd_pcm_t *handle; - snd_pcm_hw_params_t *params; + snd_pcm_t* handle; + snd_pcm_hw_params_t* params; std::vector<sample_t> data; size_t num_channels; diff --git a/drumgizmo/output/jackaudio.cc b/drumgizmo/output/jackaudio.cc index 2c80080..f92f186 100644 --- a/drumgizmo/output/jackaudio.cc +++ b/drumgizmo/output/jackaudio.cc @@ -30,12 +30,17 @@ #include "jackaudio.h" JackAudioOutputEngine::JackAudioOutputEngine(JackClient &client) - : client(client), channels{}, sema{"jackaudio"} + : client(client) + , channels{} + , sema{"jackaudio"} { client.add(*this); } -JackAudioOutputEngine::~JackAudioOutputEngine() { client.remove(*this); } +JackAudioOutputEngine::~JackAudioOutputEngine() +{ + client.remove(*this); +} bool JackAudioOutputEngine::init(Channels data) { @@ -61,7 +66,9 @@ bool JackAudioOutputEngine::init(Channels data) return true; } -void JackAudioOutputEngine::setParm(std::string parm, std::string value) {} +void JackAudioOutputEngine::setParm(std::string parm, std::string value) +{ +} bool JackAudioOutputEngine::start() { @@ -69,9 +76,13 @@ bool JackAudioOutputEngine::start() return true; } -void JackAudioOutputEngine::stop() {} +void JackAudioOutputEngine::stop() +{ +} -void JackAudioOutputEngine::pre(size_t nsamples) {} +void JackAudioOutputEngine::pre(size_t nsamples) +{ +} void JackAudioOutputEngine::run(int ch, sample_t *samples, size_t nsamples) { @@ -81,7 +92,10 @@ void JackAudioOutputEngine::run(int ch, sample_t *samples, size_t nsamples) } } -void JackAudioOutputEngine::post(size_t nsamples) { sema.wait(); } +void JackAudioOutputEngine::post(size_t nsamples) +{ + sema.wait(); +} void JackAudioOutputEngine::process(jack_nframes_t num_frames) { @@ -99,14 +113,21 @@ void JackAudioOutputEngine::process(jack_nframes_t num_frames) sema.post(); } -size_t JackAudioOutputEngine::getBufferSize() { return client.getBufferSize(); } +size_t JackAudioOutputEngine::getBufferSize() +{ + return client.getBufferSize(); +} -size_t JackAudioOutputEngine::samplerate() { return client.getSampleRate(); } +size_t JackAudioOutputEngine::samplerate() +{ + return client.getSampleRate(); +} JackAudioOutputEngine::Channel::Channel(JackClient &client, - std::string const &name, + const std::string &name, std::size_t buffer_size) - : port{client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput}, samples{} + : port{client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput} + , samples{} { samples.resize(buffer_size); } diff --git a/drumgizmo/output/jackaudio.h b/drumgizmo/output/jackaudio.h index dc66978..e15dede 100644 --- a/drumgizmo/output/jackaudio.h +++ b/drumgizmo/output/jackaudio.h @@ -31,7 +31,9 @@ #include "audiooutputengine.h" #include "../jackclient.h" -class JackAudioOutputEngine : public AudioOutputEngine, public JackProcess +class JackAudioOutputEngine + : public AudioOutputEngine + , public JackProcess { public: JackAudioOutputEngine(JackClient &client); @@ -43,7 +45,7 @@ public: bool start() override; void stop() override; void pre(size_t nsamples) override; - void run(int ch, sample_t *samples, size_t nsamples) override; + void run(int ch, sample_t* samples, size_t nsamples) override; void post(size_t nsamples) override; size_t getBufferSize() override; size_t samplerate() override; @@ -57,11 +59,11 @@ private: JackPort port; std::vector<sample_t> samples; - Channel(JackClient &client, std::string const &name, + Channel(JackClient& client, const std::string &name, std::size_t buffer_size); }; - JackClient &client; + JackClient& client; std::vector<Channel> channels; Semaphore sema; }; diff --git a/drumgizmo/output/outputdummy.h b/drumgizmo/output/outputdummy.h index cfb3754..a5ac6c9 100644 --- a/drumgizmo/output/outputdummy.h +++ b/drumgizmo/output/outputdummy.h @@ -27,7 +27,8 @@ #pragma once #include "audiooutputengine.h" -class DummyOutputEngine : public AudioOutputEngine +class DummyOutputEngine + : public AudioOutputEngine { public: DummyOutputEngine(); @@ -39,6 +40,6 @@ public: bool start() override; void stop() override; void pre(size_t nsamples) override; - void run(int ch, sample_t *samples, size_t nsamples) override; + void run(int ch, sample_t* samples, size_t nsamples) override; void post(size_t nsamples) override; }; diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc index 9d4deb1..678bbe3 100644 --- a/drumgizmo/output/wavfile.cc +++ b/drumgizmo/output/wavfile.cc @@ -28,7 +28,10 @@ #include "wavfile.h" -WavfileOutputEngine::WavfileOutputEngine() : info{}, channels{}, file{"output"} +WavfileOutputEngine::WavfileOutputEngine() + : info{} + , channels{} + , file{"output"} { info.frames = 0; info.samplerate = 44100; diff --git a/drumgizmo/output/wavfile.h b/drumgizmo/output/wavfile.h index 7bc7666..9ed8ca7 100644 --- a/drumgizmo/output/wavfile.h +++ b/drumgizmo/output/wavfile.h @@ -32,7 +32,8 @@ #include "audiooutputengine.h" -class WavfileOutputEngine : public AudioOutputEngine +class WavfileOutputEngine + : public AudioOutputEngine { public: WavfileOutputEngine(); @@ -44,13 +45,13 @@ public: bool start() override; void stop() override; void pre(size_t nsamples) override; - void run(int ch, sample_t *samples, size_t nsamples) override; + void run(int ch, sample_t* samples, size_t nsamples) override; void post(size_t nsamples) override; size_t samplerate() override; private: SF_INFO info; - std::vector<SNDFILE *> channels; + std::vector<SNDFILE*> channels; size_t num_channels; std::string file; |