是否有一个算法,从一系列的音符得到一首歌曲的规模和重点?一首、音符、算法、有一个

2023-09-11 22:59:14 作者:稳妥@

我有一系列的存储阵列中的MIDI音符编号的形式MIDI音符。是否有一个算法,将让我通过这些笔记psented歌曲重新$ P $的关键和规模?

I've got a series of MIDI notes stored in array in the form of MIDI note number. Is there an algorithm that would get me the key and scale of the song represented by these notes?

推荐答案

如果您正在使用Python,你可以使用music21工具包来做到这一点:

If you're using Python you can use the music21 toolkit to do this:

import music21
score = music21.converter.parse('filename.mid')
key = score.analyze('key')
print key.tonic.name, key.mode

如果你关心的主要发现特定的算法,可以使用通用的关键的他们,而不是:

if you care about specific algorithms for key finding, you can use them instead of the generic "key":

key1 = score.analyze('Krumhansl')
key2 = score.analyze('AardenEssen')

等。所有这些方法会为和弦也。 (免责声明:music21是我的项目,所以我当然在促进它的既得利益,但你可以看看music21.analysis.discrete模块采取从那里的想法为其他项目/语言。如果你有一个MIDI分析器,该Krumhansl算法并不难实现)。

etc. Any of these methods will work for chords also. (Disclaimer: music21 is my project, so of course I have a vested interest in promoting it; but you can look at the music21.analysis.discrete module to take ideas from there for other projects/languages. If you have a MIDI parser, the Krumhansl algorithm is not hard to implement).