From aaafcea7e26791acbf5b9612e3fb396edcdfcc8f Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 4 Jan 2025 10:25:25 +0100 Subject: Fill UI --- MIDI.h | 88 ++++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'MIDI.h') diff --git a/MIDI.h b/MIDI.h index 96c9eb7..e24c18a 100644 --- a/MIDI.h +++ b/MIDI.h @@ -107,60 +107,62 @@ public: std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl; } + return ev; + } + + uint64_t timestamp_from_event(const snd_seq_event_t *ev) + { + return ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick; + } + + // returns if click starts + void process(snd_seq_event_t *ev) + { + uint64_t timestamp = timestamp_from_event(ev); // original timestamp + // TODO: fix timestamp to be set automatically struct timespec t; if (TIME_UTC != timespec_get(&t, TIME_UTC)) { - std::cerr << "Error: timespec_get()" << std::endl; + log_cout << "Error: timespec_get()" << std::endl; } else { ev->time.time.tv_sec = t.tv_sec; ev->time.time.tv_nsec = t.tv_nsec; } - return ev; - } - - uint64_t timestamp_from_event(const snd_seq_event_t *ev) - { - return ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick; - } - // returns if click starts - void process(const snd_seq_event_t *ev) - { - if ((ev->type == SND_SEQ_EVENT_NOTEON) ||(ev->type == SND_SEQ_EVENT_NOTEOFF)) { - uint64_t timestamp = timestamp_from_event(ev); - const char *type = (ev->type == SND_SEQ_EVENT_NOTEON) ? "on " : "off"; - debug_cout << fmt::format("[{}] Note {}: {:2x} vel({:2x}), ch {:2x}\n", timestamp, - type, - ev->data.note.note, - ev->data.note.velocity, - ev->data.control.channel); - if (ev->type == SND_SEQ_EVENT_NOTEON) { - signal_note(ev->data.control.channel, ev->data.note.note, timestamp); - } - } - else if (ev->type == SND_SEQ_EVENT_CONTROLLER) - { - debug_cout << fmt::format("[{}] Control: {:2x} val({:2x})\n", timestamp_from_event(ev), - ev->data.control.param, - ev->data.control.value); - } - else if (ev->type == SND_SEQ_EVENT_SENSING) - { - signal_active_sensing(); - debug_cout << fmt::format("[{}] Active Sensing\n", timestamp_from_event(ev)) << std::endl; - } - else if (ev->type == SND_SEQ_EVENT_CLOCK) - { - signal_clock(); - debug_cout << fmt::format("[{}] Clock\n", timestamp_from_event(ev)) << std::endl; - } - else - { - log_cout << fmt::format("[{}] Unknown MIDI event: {}\n", timestamp_from_event(ev), ev->type) << std::endl; - } + if ((ev->type == SND_SEQ_EVENT_NOTEON) ||(ev->type == SND_SEQ_EVENT_NOTEOFF)) { + const char *type = (ev->type == SND_SEQ_EVENT_NOTEON) ? "on " : "off"; + debug_cout << fmt::format("[{}] Note {}: {:2x} vel({:2x}), ch {:2x}\n", timestamp, + type, + ev->data.note.note, + ev->data.note.velocity, + ev->data.control.channel); + if (ev->type == SND_SEQ_EVENT_NOTEON) { + signal_note(ev->data.control.channel, ev->data.note.note, timestamp); + } + } + else if (ev->type == SND_SEQ_EVENT_CONTROLLER) + { + debug_cout << fmt::format("[{}] Control: {:2x} val({:2x})\n", timestamp_from_event(ev), + ev->data.control.param, + ev->data.control.value); + } + else if (ev->type == SND_SEQ_EVENT_SENSING) + { + signal_active_sensing(); + debug_cout << fmt::format("[{}] Active Sensing\n", timestamp_from_event(ev)) << std::endl; + } + else if (ev->type == SND_SEQ_EVENT_CLOCK) + { + signal_clock(); + debug_cout << fmt::format("[{}] Clock\n", timestamp_from_event(ev)) << std::endl; + } + else + { + log_cout << fmt::format("[{}] Unknown MIDI event: {}\n", timestamp_from_event(ev), ev->type) << std::endl; + } } void flush() -- cgit v1.2.3