summaryrefslogtreecommitdiff
path: root/drumgizmo
diff options
context:
space:
mode:
Diffstat (limited to 'drumgizmo')
-rw-r--r--drumgizmo/input/jackmidi.cc20
-rw-r--r--drumgizmo/input/midifile.cc27
-rw-r--r--drumgizmo/input/ossmidi.cc25
3 files changed, 12 insertions, 60 deletions
diff --git a/drumgizmo/input/jackmidi.cc b/drumgizmo/input/jackmidi.cc
index 8459e67..cf4dc6c 100644
--- a/drumgizmo/input/jackmidi.cc
+++ b/drumgizmo/input/jackmidi.cc
@@ -30,9 +30,6 @@
#include "cpp11fix.h" // required for c++11
#include "jackmidi.h"
-static int const NOTE_ON = 0x90;
-static int const NOTE_MASK = 0xF0;
-
JackMidiInputEngine::JackMidiInputEngine(JackClient& client)
: AudioInputEngineMidi{}
, JackProcess{}
@@ -119,22 +116,7 @@ void JackMidiInputEngine::process(jack_nframes_t num_frames)
{
jack_midi_event_t event;
jack_midi_event_get(&event, buffer, i);
- if(event.size != 3)
- {
- continue;
- }
- if((event.buffer[0] & NOTE_MASK) != 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({EventType::OnSet, (size_t)k, event.time, velocity / 127.f});
- }
+ processNote(event.buffer, event.size, event.time, events);
}
jack_midi_clear_buffer(buffer);
pos += num_frames;
diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc
index 562ed37..c0b8e73 100644
--- a/drumgizmo/input/midifile.cc
+++ b/drumgizmo/input/midifile.cc
@@ -29,9 +29,6 @@
#include "midifile.h"
-static int const NOTE_ON = 0x90;
-static int const NOTE_MASK = 0xF0;
-
MidifileInputEngine::MidifileInputEngine()
: AudioInputEngineMidi{}
, smf{nullptr}
@@ -147,26 +144,12 @@ 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_MASK) == NOTE_ON) &&
- (track == -1 || current_event->track_number == track) &&
- current_event->midi_buffer[2] > 0)
+ if(track == -1 || current_event->track_number == track)
{
- int key = current_event->midi_buffer[1];
- int velocity = current_event->midi_buffer[2];
-
- events.emplace_back();
- auto& event = events.back();
- event.type = EventType::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;
- }
+ processNote(current_event->midi_buffer,
+ current_event->midi_buffer_length,
+ current_event->time_seconds * (samplerate / speed),
+ events);
}
}
diff --git a/drumgizmo/input/ossmidi.cc b/drumgizmo/input/ossmidi.cc
index 325a83d..7c7757e 100644
--- a/drumgizmo/input/ossmidi.cc
+++ b/drumgizmo/input/ossmidi.cc
@@ -32,10 +32,6 @@
#include <iostream>
-static int const NOTE_ON = 0x90;
-static int const NOTE_MASK = 0xF0;
-
-
OSSInputEngine::OSSInputEngine()
: AudioInputEngineMidi{}
, dev{"/dev/midi"}
@@ -100,21 +96,12 @@ void OSSInputEngine::run(size_t pos, size_t len, std::vector<event_t>& events)
unsigned char buf[128];
if ((l = read (fd, buf, sizeof (buf))) != -1)
{
- int masked_note = buf[0] & NOTE_MASK;
- if (masked_note == NOTE_ON) {
- int note = buf[1];
- int velocity = buf[2];
- event_t event;
- event.instrument = mmap.lookup(note);
- if(event.instrument != -1)
- {
- event.velocity = velocity / 127.0;
- event.type = 0;
- event.offset = 0;
- events.push_back(event);
- }
- }
- } else if (errno != EAGAIN) {
+ processNote(buf, l,
+ 0, // No time information available? play as soon as possible
+ events);
+ }
+ else if (errno != EAGAIN)
+ {
std::cerr << "Error code: " << errno << std::endl;
std::cerr << std::strerror(errno) << std::endl;
}