File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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) {
136149static 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments