[英]How to split midi file based on notes pitch using python?
How can I split midi files based on their pitch using python?如何使用 python 根据音高拆分 midi 文件? I tried the music21 library, but I don't really know how this works...
我试过 music21 图书馆,但我真的不知道它是如何工作的......
Try this code:试试这个代码:
import pretty_midi
import copy
pitch_cutoff = 65
mid = pretty_midi.PrettyMIDI('my_file.mid')
low_notes = copy.deepcopy(mid)
high_notes = copy.deepcopy(mid)
for instrument in low_notes.instruments:
for note in instrument.notes:
if note.pitch > pitch_cutoff:
note.velocity = 0
for instrument in high_notes.instruments:
for note in instrument.notes:
if note.pitch < pitch_cutoff:
note.velocity = 0
low_notes.write("low_notes.mid")
high_notes.write("high_notes.mid")
it uses the pretty_midi
module to split a midi file into two different files.它使用
pretty_midi
模块将 midi 文件拆分为两个不同的文件。 The file called "high_notes.mid" will only have notes above what you set the pitch_cutoff
variable to, and "low_notes.mid" will only have notes below that.名为“high_notes.mid”的文件只会有高于您设置的
pitch_cutoff
变量的音符,而“low_notes.mid”只会有低于它的音符。 Just change "my_file.mid" to whatever the name of your file is and try it out.只需将“my_file.mid”更改为您文件的任何名称并尝试一下。 Let me know if you have any questions.
如果您有任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.