1 回答
![?](http://img1.sycdn.imooc.com/5458620000018a2602200220-100-100.jpg)
TA贡献1744条经验 获得超4个赞
试试这个代码:
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")
它使用该pretty_midi模块将 MIDI 文件拆分为两个不同的文件。名为“high_notes.mid”的文件将仅在您设置变量的内容上方包含注释pitch_cutoff,而“low_notes.mid”仅在其下方包含注释。只需将“my_file.mid”更改为您的文件名并尝试一下即可。如果您有任何疑问,请告诉我。
添加回答
举报