1 回答

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”更改為您的文件名并嘗試一下即可。如果您有任何疑問,請告訴我。
添加回答
舉報