diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-05-12 10:01:25 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-04-23 14:47:57 +0200 |
commit | 7924b3c3b64950758fbba5b0a68e9b3432b7a892 (patch) | |
tree | 2a3ca1e8395abc606348644ac8f9cbcb45d8a5b2 /drumgizmo/input | |
parent | 2f2cde95bce634f26e43cdcb94cae7b27e378544 (diff) |
Reduced some code redundancy
Diffstat (limited to 'drumgizmo/input')
-rw-r--r-- | drumgizmo/input/jackmidi.cc | 20 | ||||
-rw-r--r-- | drumgizmo/input/midifile.cc | 27 |
2 files changed, 13 insertions, 34 deletions
diff --git a/drumgizmo/input/jackmidi.cc b/drumgizmo/input/jackmidi.cc index 7c5cf1c..0839ae3 100644 --- a/drumgizmo/input/jackmidi.cc +++ b/drumgizmo/input/jackmidi.cc @@ -118,22 +118,14 @@ void JackMidiInputEngine::process(jack_nframes_t num_frames) { jack_midi_event_t event; jack_midi_event_get(&event, buffer, i); - if(event.size != 3) - { + + event_t out; + if (!midi_processor(event.size, event.buffer, out)) { + // unsupported event continue; } - if((event.buffer[0] & NOTE_ON) != NOTE_ON) - { - continue; - } - int key = event.buffer[1]; - int velocity = event.buffer[2]; - printf("Event key:%d vel:%d\n", key, velocity); - int k = mmap.lookup(key); - if(k != -1 && velocity) - { - events.push_back({TYPE_ONSET, (size_t)k, event.time, velocity / 127.f}); - } + out.offset = event.time; + events.push_back(out); } jack_midi_clear_buffer(buffer); pos += num_frames; diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc index 89ffa6b..6d09f36 100644 --- a/drumgizmo/input/midifile.cc +++ b/drumgizmo/input/midifile.cc @@ -146,27 +146,14 @@ void MidifileInputEngine::run(size_t pos, size_t len, std::vector<event_t>& even { if(!smf_event_is_metadata(current_event)) { - if((current_event->midi_buffer_length == 3) && - ((current_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && - (track == -1 || current_event->track_number == track) && - current_event->midi_buffer[2] > 0) - { - int key = current_event->midi_buffer[1]; - int velocity = current_event->midi_buffer[2]; - - events.emplace_back(); - auto& event = events.back(); - event.type = TYPE_ONSET; - size_t evpos = current_event->time_seconds * (samplerate / speed); - event.offset = evpos - pos; - - int i = mmap.lookup(key); - if(i != -1) - { - event.instrument = i; - event.velocity = velocity / 127.0; - } + event_t out; + if (!midi_processor(current_event->midi_buffer_length, current_event->midi_buffer, out)) { + // unsupported event + continue; } + std::size_t evpos = current_event->time_seconds * (samplerate / speed); + out.offset = evpos - pos; + events.push_back(out); } current_event = smf_get_next_event(smf); |