summaryrefslogtreecommitdiffhomepage
path: root/MIDI.h
diff options
context:
space:
mode:
Diffstat (limited to 'MIDI.h')
-rw-r--r--MIDI.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/MIDI.h b/MIDI.h
index 23024c3..96c9eb7 100644
--- a/MIDI.h
+++ b/MIDI.h
@@ -32,7 +32,7 @@ public:
throw std::runtime_error("MIDI port couldn't be opened");
}
- log_cout << "in_port: " << std::to_string(in_port) << std::endl;
+ debug_cout << "in_port: " << std::to_string(in_port) << std::endl;
#if 1
snd_seq_addr_t sender, dest;
@@ -80,7 +80,7 @@ public:
free(pfd);
}
- boost::signals2::signal<void(int, int)> signal_note;
+ boost::signals2::signal<void(int, int, uint64_t)> signal_note;
boost::signals2::signal<void()> signal_active_sensing;
boost::signals2::signal<void()> signal_clock;
@@ -121,40 +121,45 @@ public:
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", ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick,
+ 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);
+ 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",
- ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick,
+ 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", ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick) << std::endl;
+ 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", ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_REAL) ? ev->time.time.tv_sec : ev->time.tick) << std::endl;
+ debug_cout << fmt::format("[{}] Clock\n", timestamp_from_event(ev)) << std::endl;
}
else
{
- log_cout << fmt::format("[{}] Unknown MIDI event: {}\n", ev->time.tick, ev->type) << std::endl;
+ log_cout << fmt::format("[{}] Unknown MIDI event: {}\n", timestamp_from_event(ev), ev->type) << std::endl;
}
}