如何使用python根据音符音高分割midi文件?

如何使用 python 根据音高分割 MIDI 文件?我尝试了 music21 库,但我真的不知道它是如何工作的......



陪伴而非守候
浏览 1611回答 1
1回答

慕无忌1623718

试试这个代码:import pretty_midiimport copypitch_cutoff = 65mid = pretty_midi.PrettyMIDI('my_file.mid')low_notes = copy.deepcopy(mid)high_notes = copy.deepcopy(mid)for instrument in low_notes.instruments:&nbsp; &nbsp; for note in instrument.notes:&nbsp; &nbsp; &nbsp; &nbsp; if note.pitch > pitch_cutoff:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; note.velocity = 0for instrument in high_notes.instruments:&nbsp; &nbsp; for note in instrument.notes:&nbsp; &nbsp; &nbsp; &nbsp; if note.pitch < pitch_cutoff:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; note.velocity = 0low_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”更改为您的文件名并尝试一下即可。如果您有任何疑问,请告诉我。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python