MIDI持续时间起的实际音符持续时间 [英] Actual note duration from MIDI duration

查看:334
本文介绍了MIDI持续时间起的实际音符持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实现一个应用程序,以对MIDI文件执行一些任务,而我目前的问题是将已阅读的音符输出到LilyPond文件中.

I'm currently implementing an application to perform some tasks on MIDI files, and my current problem is to output the notes I've read to a LilyPond file.

我已经将note_on和note_off事件合并到具有绝对开始和绝对持续时间的单个note对象,但是我真的看不到如何将持续时间转换为实际的音乐符号.我猜测持续时间376是我正在读取的文件中的四分音符,因为我知道这首歌,而显然188是八分音符,但这当然不能推广到所有MIDI文件.

I've merged note_on and note_off events to single notes object with absolute start and absolute duration, but I don't really see how to convert that duration to actual music notation. I've guessed that a duration of 376 is a quarter note in the file I'm reading because I know the song, and obviously 188 is an eighth note, but this certainly does not generalise to all MIDI files.

有什么想法吗?

推荐答案

默认情况下,MIDI文件的速度设置为120 bpm,文件中的MThd块将以每四分音符的脉冲数"告诉您分辨率"(ppqn).

By default a MIDI file is set to a tempo of 120 bpm and the MThd chunk in the file will tell you the resolution in terms of "pulses per quarter note" (ppqn).

例如,如果ppqn为96,那么96个滴答声的增量就是四分音符.

If the ppqn is, say, 96 than a delta of 96 ticks is a quarter note.

如果您对每种声音的真实持续时间(以秒为单位)感兴趣,还应该考虑可以通过事件"FF 51 03 tt tt tt"更改的速度";这三个字节是四分音符的微秒.

Should you be interested in the real duration (in seconds) of each sound you should also consider the "tempo" that can be changed by an event "FF 51 03 tt tt tt"; the three bytes are the microseconds for a quarter note.

使用这两个值,您应该找到所需的内容.请注意,midi文件中的持续时间可能是近似的,特别是如果该MIDI文件是人类演奏者的录音.

With these two values you should find what you need. Beware that the duration in the midi file can be approximate, especially if that MIDI file it's the recording of a human player.

很久以前,我已经建立了一个C库来读取/写入midifiles: https://github .com/rdentato/middl ,以防万一(可能要花很多时间,我不看代码,随时询问是否有不清楚的地方).

I've put together a C library to read/write midifiles a long time ago: https://github.com/rdentato/middl in case it may be helpful (it's quite some time I don't look at the code, feel free to ask if there's anything unclear).

我建议遵循这种方法:

  1. 选择与您的部门(例如1/128)兼容的最小备忘",并将其用作一种网格.
  2. 将每个音符与最接近的网格线对齐(即与最小节点的最接近整数倍)
  3. 将其转换为标准符号(例如,四分音符,点划线的八分音符等).

在您的情况下,将1/32作为最小音符,将384作为除法(即48个滴答声).对于376滴答声,您将得到376/48 = 7.8,并四舍五入为8(最接近的整数),而8/32 = 1/4.

In your case, take 1/32 as minimal note and 384 as division (that would be 48 ticks). For your note of 376 tick you'll have 376/48=7.8 which you round to 8 (the closest integer) and 8/32 = 1/4.

如果您发现持续时间为193个滴答音符的音符,则可以看到它是1/8音符,因为193/48是4.02(可以四舍五入为4)和4/32 = 1/8.

If you find a note whose duration is 193 ticks you can see it's a 1/8 note as 193/48 is 4.02 (which you can round to 4) and 4/32 = 1/8.

继续这种推理,您可以看到持续时间为671滴答的音符应该是双点划线的四分音符.

Continuing this reasoning you can see that a note of duration 671 ticks should be a double dotted quarter note.

实际上,671应该近似于672(48的最接近倍数),即14 * 48.所以您的音符是14/32-> 7/16->(1/16 + 2/16 + 4/16)-> 1/16 + 1/8 + 1/4.

In fact, 671 should be approximated to 672 (the closest multiple of 48) which is 14*48. So your note is a 14/32 -> 7/16 -> (1/16 + 2/16 + 4/16) -> 1/16 + 1/8 + 1/4.

如果您习惯使用二进制数,您可能会注意到14是1110,并从那里直接得出1/16、1/4和1/8的存在.

If you are comfortable using binary numbers, you could notice that 14 is 1110 and from there, directly derive the presence of 1/16, 1/4 and 1/8.

再举一个例子,持续时间为480滴答的音符是四分音符,再加上1/16音符,因为480 = 48 * 10,而10是二进制的1010.

As a further example, a note of 480 ticks of duration is a quarter note tied with a 1/16 note since 480=48*10 and 10 is 1010 in binary.

小标题和其他小组会使事情变得更加复杂.并非偶然,最常见的除法值是96(3 * 2 ^ 5),192(3 * 2 ^ 6)和384(3 * 2 ^ 7);这样,三胞胎可以用整数的刻度来表示.

Triplets and other groups would make things a little bit more complex. It's not by chance that the most common division values are 96 (3*2^5), 192 (3*2^6) and 384 (3*2^7); this way triplets can be represented with an integer number of ticks.

在某些情况下,您可能不得不猜测或简化,这就是为什么没有"midi to standard notation"程序可以做到100%准确的原因.

You might have to guess or simplify in some situations, that's why no "midi to standard notation" program can be 100% accurate.

这篇关于MIDI持续时间起的实际音符持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆