From c9edca027eb2d2e257ff4a13fc257385d7c64d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Mon, 25 Jan 2016 16:20:30 +0100 Subject: Base Midi-Engines on Midi-Engine Base Class (+ Minor Renaming) --- drumgizmo/input/jackmidi.cc | 50 ++++++++++++++++--------------------------- drumgizmo/input/jackmidi.h | 9 +++----- drumgizmo/input/midifile.cc | 21 ++++-------------- drumgizmo/input/midifile.h | 11 ++++------ drumgizmo/output/jackaudio.cc | 3 ++- drumgizmo/output/wavfile.cc | 3 ++- src/audioinputenginemidi.cc | 14 ++++++------ src/audioinputenginemidi.h | 2 +- 8 files changed, 41 insertions(+), 72 deletions(-) diff --git a/drumgizmo/input/jackmidi.cc b/drumgizmo/input/jackmidi.cc index 386adac..4aebf69 100644 --- a/drumgizmo/input/jackmidi.cc +++ b/drumgizmo/input/jackmidi.cc @@ -33,12 +33,10 @@ static int const NOTE_ON = 0x90; JackMidiInputEngine::JackMidiInputEngine(JackClient &client) - : AudioInputEngine{} + : AudioInputEngineMidi{} , JackProcess{} , client(client) , port{nullptr} - , midimap{} - , midi_mapper{} , pos{0u} , list{nullptr} , listsize{0u} @@ -46,30 +44,18 @@ JackMidiInputEngine::JackMidiInputEngine(JackClient &client) client.add(*this); } -JackMidiInputEngine::~JackMidiInputEngine() { client.remove(*this); } - -bool JackMidiInputEngine::isMidiEngine() { return true; } +JackMidiInputEngine::~JackMidiInputEngine() +{ + client.remove(*this); +} -bool JackMidiInputEngine::init(Instruments &instruments) +bool JackMidiInputEngine::init(Instruments& instruments) { - if (midimap == "") - { - std::cerr << "[JackMidiInputEngine] Missing midimap filename\n"; - return false; - } - MidiMapParser p{midimap}; - if (p.parse()) - { - std::cerr << "[JackmidiInputEngine] Failed to parse midimap '" << midimap + if (!loadMidiMap(midimap, instruments)) { + std::cerr << "[MidifileInputEngine] Failed to parse midimap '" << midimap << "'\n"; return false; } - midi_mapper.midimap = p.midimap; - for (auto i = 0u; i < instruments.size(); ++i) - { - auto name = instruments[i]->name(); - midi_mapper.instrmap[name] = i; - } port = std::make_unique(client, "drumgizmo_midiin", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput); return true; @@ -95,9 +81,13 @@ bool JackMidiInputEngine::start() return true; } -void JackMidiInputEngine::stop() {} +void JackMidiInputEngine::stop() +{ +} -void JackMidiInputEngine::pre() {} +void JackMidiInputEngine::pre() +{ +} event_t *JackMidiInputEngine::run(size_t pos, size_t len, size_t *nevents) { @@ -109,7 +99,9 @@ event_t *JackMidiInputEngine::run(size_t pos, size_t len, size_t *nevents) return l; } -void JackMidiInputEngine::post() {} +void JackMidiInputEngine::post() +{ +} void JackMidiInputEngine::process(jack_nframes_t num_frames) { @@ -132,7 +124,7 @@ void JackMidiInputEngine::process(jack_nframes_t num_frames) int key = event.buffer[1]; int velocity = event.buffer[2]; printf("Event key:%d vel:%d\n", key, velocity); - int k = midi_mapper.lookup(key); + int k = mmap.lookup(key); if (k != -1 && velocity) { list[listsize].type = TYPE_ONSET; @@ -145,9 +137,3 @@ void JackMidiInputEngine::process(jack_nframes_t num_frames) jack_midi_clear_buffer(buffer); pos += num_frames; } - -/* - DrumKit* kit; - size_t pos; - EventQueue *eventqueue; -*/ diff --git a/drumgizmo/input/jackmidi.h b/drumgizmo/input/jackmidi.h index e129071..10111a4 100644 --- a/drumgizmo/input/jackmidi.h +++ b/drumgizmo/input/jackmidi.h @@ -29,21 +29,20 @@ #include #include -#include "audioinputengine.h" +#include "audioinputenginemidi.h" #include "midimapper.h" #include "midimapparser.h" #include "../jackclient.h" class JackMidiInputEngine - : public AudioInputEngine + : public AudioInputEngineMidi , public JackProcess { public: JackMidiInputEngine(JackClient &client); ~JackMidiInputEngine(); - // based on AudioInputEngine - bool isMidiEngine() override; + // based on AudioInputEngineMidi bool init(Instruments& instruments) override; void setParm(std::string parm, std::string value) override; bool start() override; @@ -59,8 +58,6 @@ private: JackClient &client; std::unique_ptr port; - std::string midimap; - MidiMapper midi_mapper; std::size_t pos; event_t* list; diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc index 4e36c9d..7d27998 100644 --- a/drumgizmo/input/midifile.cc +++ b/drumgizmo/input/midifile.cc @@ -31,10 +31,10 @@ static int const NOTE_ON = 0x90; MidifileInputEngine::MidifileInputEngine() - : smf{nullptr} + : AudioInputEngineMidi{} + , smf{nullptr} , current_event{nullptr} , file{} - , midimap{} , speed{1.f} , track{-1} // all tracks , loop{false} @@ -50,11 +50,6 @@ MidifileInputEngine::~MidifileInputEngine() } } -bool MidifileInputEngine::isMidiEngine() -{ - return true; -} - bool MidifileInputEngine::init(Instruments& instruments) { if (file == "") @@ -74,19 +69,11 @@ bool MidifileInputEngine::init(Instruments& instruments) << "'\n"; return false; } - MidiMapParser p{midimap}; - if (p.parse()) - { + if (!loadMidiMap(midimap, instruments)) { std::cerr << "[MidifileInputEngine] Failed to parse midimap '" << midimap << "'\n"; return false; } - midi_mapper.midimap = p.midimap; - for (auto i = 0u; i < instruments.size(); ++i) - { - auto name = instruments[i]->name(); - midi_mapper.instrmap[name] = i; - } return true; } @@ -176,7 +163,7 @@ event_t *MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) size_t evpos = current_event->time_seconds * (44100.0 / speed); evs[num_events].offset = evpos - pos; - int i = midi_mapper.lookup(key); + int i = mmap.lookup(key); if (i != -1) { evs[num_events].instrument = i; diff --git a/drumgizmo/input/midifile.h b/drumgizmo/input/midifile.h index a7e4cf0..5eb84f0 100644 --- a/drumgizmo/input/midifile.h +++ b/drumgizmo/input/midifile.h @@ -30,19 +30,18 @@ #include #include -#include "audioinputengine.h" +#include "audioinputenginemidi.h" #include "midimapper.h" #include "midimapparser.h" class MidifileInputEngine - : public AudioInputEngine + : public AudioInputEngineMidi { public: MidifileInputEngine(); ~MidifileInputEngine(); - // based on AudioInputEngine - bool isMidiEngine() override; + // based on AudioInputEngineMidi bool init(Instruments& instruments) override; void setParm(std::string parm, std::string value) override; bool start() override; @@ -55,9 +54,7 @@ private: smf_t* smf; smf_event_t* current_event; - MidiMapper midi_mapper; - - std::string file, midimap; + std::string file; float speed; int track; bool loop; diff --git a/drumgizmo/output/jackaudio.cc b/drumgizmo/output/jackaudio.cc index f92f186..fd60a2a 100644 --- a/drumgizmo/output/jackaudio.cc +++ b/drumgizmo/output/jackaudio.cc @@ -30,7 +30,8 @@ #include "jackaudio.h" JackAudioOutputEngine::JackAudioOutputEngine(JackClient &client) - : client(client) + : AudioOutputEngine{} + , client(client) , channels{} , sema{"jackaudio"} { diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc index 678bbe3..faba69d 100644 --- a/drumgizmo/output/wavfile.cc +++ b/drumgizmo/output/wavfile.cc @@ -29,7 +29,8 @@ #include "wavfile.h" WavfileOutputEngine::WavfileOutputEngine() - : info{} + : AudioOutputEngine{} + , info{} , channels{} , file{"output"} { diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc index 7c1e13d..d8e3366 100644 --- a/src/audioinputenginemidi.cc +++ b/src/audioinputenginemidi.cc @@ -38,19 +38,19 @@ AudioInputEngineMidi::AudioInputEngineMidi() is_valid = false; } -bool AudioInputEngineMidi::loadMidiMap(std::string _f, Instruments &instruments) +bool AudioInputEngineMidi::loadMidiMap(std::string file, Instruments &instruments) { - std::string f = _f; + std::string f = file; if(refs.load()) { - if(_f.size() > 1 && _f[0] == '@') { - f = refs.getValue(_f.substr(1)); + if(file.size() > 1 && file[0] == '@') { + f = refs.getValue(file.substr(1)); } } else { ERR(drumkitparser, "Error reading refs.conf"); } - file = ""; + midimap = ""; is_valid = false; DEBUG(mmap, "loadMidiMap(%s, i.size() == %d)\n", f.c_str(), @@ -70,7 +70,7 @@ bool AudioInputEngineMidi::loadMidiMap(std::string _f, Instruments &instruments) mmap.instrmap[instruments[i]->name()] = i; } - file = _f; + midimap = file; is_valid = true; return true; @@ -78,7 +78,7 @@ bool AudioInputEngineMidi::loadMidiMap(std::string _f, Instruments &instruments) std::string AudioInputEngineMidi::midimapFile() { - return file; + return midimap; } bool AudioInputEngineMidi::isValid() diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h index 0868730..7dccf33 100644 --- a/src/audioinputenginemidi.h +++ b/src/audioinputenginemidi.h @@ -62,7 +62,7 @@ public: protected: MidiMapper mmap; - std::string file; + std::string midimap; bool is_valid; ConfigFile refs; -- cgit v1.2.3