1 回答

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
試試這個(gè)代碼:
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 文件拆分為兩個(gè)不同的文件。名為“high_notes.mid”的文件將僅在您設(shè)置變量的內(nèi)容上方包含注釋pitch_cutoff,而“l(fā)ow_notes.mid”僅在其下方包含注釋。只需將“my_file.mid”更改為您的文件名并嘗試一下即可。如果您有任何疑問,請(qǐng)告訴我。
添加回答
舉報(bào)