summaryrefslogtreecommitdiff
path: root/drumgizmo/input
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-01-25 16:20:30 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-02-09 09:03:17 +0100
commitc9edca027eb2d2e257ff4a13fc257385d7c64d39 (patch)
treef2f003225fc5177fa45bb61e8058aa5acb3be798 /drumgizmo/input
parentd3554736c13531898fb720b34772a595620e661a (diff)
Base Midi-Engines on Midi-Engine Base Class (+ Minor Renaming)
Diffstat (limited to 'drumgizmo/input')
-rw-r--r--drumgizmo/input/jackmidi.cc50
-rw-r--r--drumgizmo/input/jackmidi.h9
-rw-r--r--drumgizmo/input/midifile.cc21
-rw-r--r--drumgizmo/input/midifile.h11
4 files changed, 29 insertions, 62 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<JackPort>(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 <jack/jack.h>
#include <jack/midiport.h>
-#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<JackPort> 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 <event.h>
#include <smf.h>
-#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;