28#ifndef SBL_PROTOCOL_MIDI_MONITOR_HPP_
29#define SBL_PROTOCOL_MIDI_MONITOR_HPP_
31#ifdef SBL_MIDI_MONITOR
43inline int format_event(
char* buf,
size_t size,
const MidiEvent& e) {
44 uint8_t ch = e.channel + 1;
47 case MessageType::NoteOn:
48 return log::format(buf, size,
"#MIDI ch=%u type=note_on num=%u vel=%u\r\n", ch, e.note(), e.velocity());
49 case MessageType::NoteOff:
50 return log::format(buf, size,
"#MIDI ch=%u type=note_off num=%u vel=%u\r\n", ch, e.note(), e.velocity());
51 case MessageType::ControlChange:
52 return log::format(buf, size,
"#MIDI ch=%u type=cc num=%u val=%u\r\n", ch, e.cc_number(), e.cc_value());
53 case MessageType::PitchBend:
54 return log::format(buf, size,
"#MIDI ch=%u type=pb val=%u\r\n", ch, e.pitch_bend_raw());
55 case MessageType::ProgramChange:
return log::format(buf, size,
"#MIDI ch=%u type=pc val=%u\r\n", ch, e.data1);
56 case MessageType::ChannelPressure:
return log::format(buf, size,
"#MIDI ch=%u type=cp val=%u\r\n", ch, e.data1);
57 case MessageType::PolyPressure:
58 return log::format(buf, size,
"#MIDI ch=%u type=pp num=%u val=%u\r\n", ch, e.data1, e.data2);
61 case MessageType::Clock:
return log::format(buf, size,
"#MIDI type=clock\r\n");
62 case MessageType::Start:
return log::format(buf, size,
"#MIDI type=start\r\n");
63 case MessageType::Continue:
return log::format(buf, size,
"#MIDI type=continue\r\n");
64 case MessageType::Stop:
return log::format(buf, size,
"#MIDI type=stop\r\n");
65 case MessageType::ActiveSensing:
return log::format(buf, size,
"#MIDI type=active_sensing\r\n");
66 case MessageType::SystemReset:
67 return log::format(buf, size,
"#MIDI type=system_reset\r\n");
70 case MessageType::SongPosition:
71 return log::format(buf, size,
"#MIDI type=song_pos val=%u\r\n",
72 (
static_cast<uint16_t
>(e.data2) << 7) | e.data1);
73 case MessageType::SongSelect:
return log::format(buf, size,
"#MIDI type=song_sel val=%u\r\n", e.data1);
74 case MessageType::TuneRequest:
return log::format(buf, size,
"#MIDI type=tune_req\r\n");
int format(char *buf, size_t size, const char *fmt,...)
Format a string into a buffer (snprintf-style)
MIDI parser, encoder, SMF and sequencer.