summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-11 15:48:58 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-11 15:48:58 +0100
commit4c5f531300efe0faf2aea88dd6c78f05012934c8 (patch)
tree004e37b722698a73d033c9f2720313dfc58b7f97
parent445b696f43a9106f8871a67c077e990ce1ca14ab (diff)
Monitor MIDI byte stream
-rw-r--r--MIDI.cpp20
-rw-r--r--MIDI.h4
2 files changed, 18 insertions, 6 deletions
diff --git a/MIDI.cpp b/MIDI.cpp
index afcca28..278e810 100644
--- a/MIDI.cpp
+++ b/MIDI.cpp
@@ -1,6 +1,11 @@
#include "MIDI.h"
-MIDI::MIDI()
+MIDI::MIDI():
+ seq_handle{},
+ in_port{},
+ npfd{},
+ pfd{},
+ midi_event_parser{}
{
if (0 > snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, SND_SEQ_NONBLOCK))
{
@@ -64,10 +69,15 @@ MIDI::MIDI()
} else if (fd() <= 2) {
std::cout << "Warning: Bad MIDI fd: " << std::to_string(fd()) << std::endl;
}
+
+ if (0 > snd_midi_event_new(1024, &midi_event_parser)) {
+ throw std::runtime_error("snd_midi_event_new()");
+ }
}
MIDI::~MIDI()
{
+ snd_midi_event_free(midi_event_parser);
free(pfd);
}
@@ -91,7 +101,7 @@ snd_seq_event_t* MIDI::read(void)
snd_seq_event_t *ev = NULL;
if (0 > snd_seq_event_input(seq_handle, &ev))
{
- std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl;
+ std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl;
}
return ev;
@@ -153,8 +163,10 @@ void MIDI::process(snd_seq_event_t *ev)
log_cout << fmt::format("[{}] Unknown MIDI event: {}", timestamp_from_event(ev), ev->type) << std::endl;
}
- signal_count_events(snd_seq_event_length(ev));
- //log_cout << fmt::format("MIDI Bytes: {}", snd_seq_event_length(ev)) << std::endl;
+ unsigned char buf[1024]; // dummy
+ long midi_bytes {snd_midi_event_decode(midi_event_parser, buf, sizeof(buf), ev)};
+
+ signal_count_events(midi_bytes);
}
void MIDI::flush()
diff --git a/MIDI.h b/MIDI.h
index 9794e2c..ee01f5b 100644
--- a/MIDI.h
+++ b/MIDI.h
@@ -5,9 +5,8 @@
#include "log.h"
#include <boost/signals2.hpp>
-
+#include <alsa/asoundlib.h>
#include <fmt/format.h>
-
#include <iostream>
class MIDI
@@ -39,5 +38,6 @@ private:
int in_port;
int npfd;
struct pollfd* pfd;
+ snd_midi_event_t* midi_event_parser;
};