summaryrefslogtreecommitdiff
path: root/drumgizmo/input
diff options
context:
space:
mode:
authorGoran Mekić <meka@tilda.center>2017-12-30 00:45:28 +0100
committerGoran Mekić <meka@tilda.center>2017-12-30 15:18:26 +0100
commit5bdf69cb2748ce9c83de3d9d45bea67d096fe04d (patch)
treef07490e219d4166c9e14214c87be04b5f18c612c /drumgizmo/input
parenta6343737453b34335a7a5494c8ac6b393d15604c (diff)
Get note and velocity
Diffstat (limited to 'drumgizmo/input')
-rw-r--r--drumgizmo/input/ossmidi.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/drumgizmo/input/ossmidi.cc b/drumgizmo/input/ossmidi.cc
index 56d77f0..4473557 100644
--- a/drumgizmo/input/ossmidi.cc
+++ b/drumgizmo/input/ossmidi.cc
@@ -32,6 +32,10 @@
#include <iostream>
+static int const NOTE_ON = 0x90;
+static int const NOTE_MASK = 0xF0;
+
+
OSSInputEngine::OSSInputEngine()
: AudioInputEngineMidi{}
, dev{"/dev/midi"}
@@ -95,15 +99,15 @@ 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)
{
- for (int i = 0; i < l; i++)
- {
- if (buf[i] & 0x80) /* Status byte */
- {
- std::cout << std::endl;
- }
- std::cout << buf[i];
+ int masked_note = buf[0] & NOTE_MASK;
+ if (masked_note == NOTE_ON) {
+ int note = buf[1];
+ int velocity = buf[2];
+ std::cout << "note = " << note << ", velocity = " << velocity << std::endl;
}
- std::cout << std::flush;
+ } else if (errno != EAGAIN) {
+ std::cerr << "Error code: " << errno << std::endl;
+ std::cerr << std::strerror(errno) << std::endl;
}
}