summaryrefslogtreecommitdiffhomepage
path: root/MIDI.h
diff options
context:
space:
mode:
Diffstat (limited to 'MIDI.h')
-rw-r--r--MIDI.h88
1 files changed, 45 insertions, 43 deletions
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()