繁体   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