如何计算 MIDI 文件的时间长度
我正在使用名为 midas 的有用库的帮助下读取 as3 (flash cs5) 中的 midi 文件 ( http://code.google.com/p/midas3/) - midi- as3 库。
我试图找出一种简单的方法来计算 MIDI 文件的整个持续时间(例如 - 4 分钟或 6 分钟的总时间...)。我假设我可以计算每个曲目的最后一个音符+检查速度并找出答案,但我想知道:
midi 文件的持续时间是否写在数据中的某处,我可以直接拉出并使用?
或者
是否有一种简单的方法可以计算它而无需运行整个文件并比较最后的音符/节奏。
I am reading midi files in as3 (flash cs5) with the help of the helpful library that is called midas
( http://code.google.com/p/midas3/) - the midi-as3 library.
I am trying to figure out a simple way to calculate the whole duration of the midi file (for example - total time of 4 minutes or 6 minutes...). I assume I could calculate the last note of each track + check the tempo and figure it out, but I was wondering if:
Is the duration of the midi file is written somewhere in the data that I could just pull out and use?
or
Is there an easy way to calculate it without running through the whole file and compare last-notes/tempos.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您需要阅读整个文件并确定阅读最后一个音符的时间。 MIDI 文件本质上是流数据,因此文件头中没有“长度”字段。
编辑:经过进一步思考,“流式传输”并不是描述 MIDI 文件的好方法。 MIDI 文件确实具有固定的字节长度,该长度存储在 IFF 块标头中。但是,没有关于文件长度(以秒为单位)的属性,但假设您可以将所有字节读入序列中(并且不要忘记考虑速度变化!),这应该不会太困难确定文件的长度(以秒为单位)。
Nope, you need to read the entire file and determine the time when you read the last note. MIDI files are essentially streaming data, so there is no "length" field in the file's header.
Edit: Upon further thought, "streaming" isn't exactly a great way to describe MIDI files. MIDI files do have a fixed length in bytes, which is is stored in the IFF chunk header. However, there is no property as for the length of the file in seconds, but assuming that you can read all of the bytes into a sequence (and don't forget to take tempo changes into account!), it should not be too difficult to determine the length of the file in seconds.