diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-11 15:48:58 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-11 15:48:58 +0100 |
commit | 4c5f531300efe0faf2aea88dd6c78f05012934c8 (patch) | |
tree | 004e37b722698a73d033c9f2720313dfc58b7f97 | |
parent | 445b696f43a9106f8871a67c077e990ce1ca14ab (diff) |
Monitor MIDI byte stream
-rw-r--r-- | MIDI.cpp | 20 | ||||
-rw-r--r-- | MIDI.h | 4 |
2 files changed, 18 insertions, 6 deletions
@@ -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() @@ -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; }; |