fbpx
Skip to main content

MIDI Forum

Ignoring MIDI event...
 
Notifications
Clear all

Ignoring MIDI events int SMF

4 Posts
3 Users
0 Reactions
17.2 K Views
Jan Kučera
Posts: 17
Eminent Member
Topic starter
 

Hello,

so my understanding is that if I don't support or don't know particular MIDI event, I can simply ignore it - and all the data following, until the next status byte. That also means losing the running status data, but that is probably fine. However, in SMF, if I start ignoring either status or even just normal messages/data, how am I supposed to recover? When I don't know how many bytes to ignore, I don't know whether I am still reading the message or already delta time of another one... and missing a delta time means the rest of the file will have wrong timing.

For example, let's say I run into this:
00 F4 05 02 40 7F 80 3C 40 ...

Well my intention was
00 | F4 05
02 | 40 7F
80 3C | 40 ...

But it could alo mean
00 | F4 05 02 40
7F | 80 3C 40 ...

What is the file reader supposed to do?

 
Posted : 31/01/2016 3:07 am
Clemens Ladisch
Posts: 324
 

In a 'raw' stream of MIDI bytes, status and data bytes can be differentiated by the most significant bit.

In SMF files, both status bytes and timestamps can use bytes with the MSB set, so parsing them requires knowing the length of messages.

F4 is invalid, and must not appear as an event in SMF files. (In theory, to send an F4 byte out of the MIDI port, an SMF file would have to use an escaped event (F7).)

When you encounter an invalid event, such as F4, the best you can do is to abort parsing and return an error.

 
Posted : 01/02/2016 11:44 pm
Yannick Duchêne
Posts: 12
Active Member
 

If I understand the question correctly, I would say you can't ignore any event, you can just ignore events by not interpreting it. To parse a Standard MIDI File, you need to know how many data bytes comes with a message. There are the one with variable length quantities, which can all be parsed the same way while not interpreting it. And there are the ones with a varying number of payload bytes, ranging from zero data byte to two data bytes. There are just a few of these, so that cost nothing for an application to know it.

To properly parse a Standard MIDI File, an application needs to be aware of the format of four cases: three variable length quantity messages (0xF0, 0xF7, 0xFF), height system messages (0xF2, 0xF3, 0xF6, 0xF8, 0xFA, 0xFB, 0xFC, 0xFE), seven channel messages (0x8n, 0x9n, 0xAn, 0xBn, 0xCn, 0xDn, 0xEn), channel message using running status data bytes (< 0x80 and be aware of running status cancellation condition). That's a bit simplified (0xF0 and 0xF7 needs to be distinguished), but close to the what it is.

Ignoring, yes, but not entirely, as minimum handling is required for parsing.

 
Posted : 26/02/2016 5:49 pm
Yannick Duchêne
Posts: 12
Active Member
 

[…]

When you encounter an invalid event, such as F4, the best you can do is to abort parsing and return an error.

There are five of these (as far as I know): 0xF1, 0xF4, 0xF5, 0xF9, 0xFD

 
Posted : 26/02/2016 5:53 pm
Share: