簡體   English   中英

如何使用 Python 中的長笛樂器從音符中制作 MIDI 文件(music21 庫)

[英]How to make MIDI file from notes with Flute instrument in Python (music21 library)

我有一些筆記,我想要的是用長笛樂器創建 MIDI 文件。 但結果是輸出 MIDI 文件播放鋼琴而不是長笛。 我試過其他樂器,但總是一樣的,鋼琴。 到底是怎么回事?

(...)
new_note = note.Note(pattern)
new_note.offset = offset
new_note.storedInstrument = instrument.Piano()
output_notes.append(new_note)
(...)
midi_stream = stream.Stream(output_notes)
midi_stream.write('midi', fp='output.midi')

根據 文檔,唯一具有storedInstrument屬性的類是note.Unpitched

和:

Unpitched對象當前不執行任何操作,不應使用。

無論如何, music21/midi/translate.pytestMidiProgramChangeA / B函數展示了這是如何完成的:只需將樂器對象添加到應該使用它的Note之前的Stream

output_notes.append(instrument.Flute())
new_note = ...
output_notes.append(new_note)
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM