我如何知道一个字节何时是表示 MIDI 增量时间的字节序列的第一个字节?

How do I know when a byte is the first of a sequence of bytes representing MIDI delta time?

我想在字节(和位级别)读取和编码 MIDI .mid 文件。读取 .mid 文件时,如何识别特定字节是增量时间值的第一个字节?

例如,下面是 Mandal 的 多媒体信号和系统 中的图 2.12 .mid 文件的轨道块图:

我怎么知道 010178000000 是增量时间字节,鉴于它们所附加的事件具有不同的字节长度? (例如,乐器变化似乎超出增量时间字节两个字节,而第一个音符打开事件似乎包含超出增量时间字节的 3 个字节)。它是基于解释增量时间字节后面的内容吗?如果是这样,那么第二个 Note On 事件让我很困惑:为什么在增量时间字节之后似乎只有两个字节?

它没有出现在 Mandel 的示例中,但我希望能得到一个针对多字节增量时间澄清这一点的答案。

当然,我感谢您就如何改进我的问题提出意见。

最后,我 不是 要求库自动读取 .mid 文件。这些很好(耶!)但我想了解如何将文件格式读取到字节级别。

在知道下一个增量时间从哪里开始之前,您确实必须对 MIDI 消息进行解码。

实际 Standard MIDI Files specification 表示:

<MTrk event> = <delta-time> <event>

<delta-time> is stored as a variable-length quantity. It represents the amount of time before the following event. If the first event in a track occurs at the very beginning of a track, or if two events occur simultaneously, a delta-time of zero is used. Delta-times are always present.
[…]

<event> = <MIDI event> | <sysex event> | <meta-event>

<MIDI event> is any MIDI channel message. Running status is used: status bytes of MIDI channel messages may be omitted if the preceding event is a MIDI channel message with the same status. The first event in each MTrk chunk must specify status. Delta-time is not considered an event itself: it is an integral part of the syntax for an MTrk event. Notice that running status occurs across delta-times.