Skip to content

Commit bdef3c5

Browse files
authored
Merge pull request #11659 from adafruit/synthio-miditrack-running-status
synthio: support running status in MidiTrack
2 parents cd874a7 + ff05e5b commit bdef3c5

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎shared-module/synthio/MidiTrack.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,20 @@ static void decode_until_pause(synthio_miditrack_obj_t *self) {
100100
if (self->pos >= len) {
101101
break;
102102
}
103-
uint8_t status = buffer[self->pos++];
103+
uint8_t status = buffer[self->pos];
104+
if (status & 0x80) {
105+
self->pos++;
106+
// a channel message arms running status; a system one cancels it
107+
self->running_status = (status < 0xF0) ? status : 0;
108+
} else {
109+
// running status: the status byte is omitted and the previous
110+
// channel message is implied
111+
status = self->running_status;
112+
if (status == 0) {
113+
record_midi_stream_error(self);
114+
break;
115+
}
116+
}
104117
switch (status >> 4) {
105118
case 8: { // Note Off
106119
mp_obj_t note = parse_note(self);
@@ -136,6 +149,7 @@ static void decode_until_pause(synthio_miditrack_obj_t *self) {
136149
static void start_parse(synthio_miditrack_obj_t *self) {
137150
self->pos = 0;
138151
self->error_location = -1;
152+
self->running_status = 0;
139153
self->synth.span.dur = decode_duration(self);
140154
if (self->synth.span.dur == 0) {
141155
// the usual case: the file starts with some MIDI event, not a delay

‎shared-module/synthio/MidiTrack.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ typedef struct {
1717
size_t pos;
1818
mp_int_t error_location;
1919
uint32_t tempo;
20+
// last channel status byte, for events that omit it (running status)
21+
uint8_t running_status;
2022
} synthio_miditrack_obj_t;
2123

2224

0 commit comments

Comments
 (0)