python - 使用 Music 21 和 Python 输出不止一种乐器
问题描述
我正在使用 Python 和 Music21 编写一种算法,该算法从输入的小提琴音乐文件和钢琴作品组成旋律。我的问题是,当我输入一个包含两种乐器的 midi 文件时,输出只有一种乐器。我目前可以将输出乐器更改为吉他、小号等,即使这些乐器不在我的原始输入文件中。我想知道我是否可以编写一些代码来识别输入文件中的仪器并输出那些特定的仪器。或者,有什么方法可以为两个输出仪器而不是一个编码?我已经厌倦了用另一个仪器复制现有代码,但算法只输出代码中检测到的最后一个仪器。下面是我当前运行的代码:
def convert_to_midi(prediction_output):
offset=0
output_notes=[]
#Create note and chord objects based on the values generated by the model
for pattern in prediction_output:
#Pattern is a chord
if ('.' in pattern) or pattern.isdigit():
notes_in_chord=pattern.split('.')
notes=[]
for current_note in notes_in_chord:
output_notes.append(instrument.Guitar())
cn=int(current_note)
new_note=note.Note(cn)
notes.append(new_note)
new_chord=chord.Chord(notes)
new_chord.offset=offset
output_notes.append(new_note)
#Pattern is a note
else:
output_notes.append(instrument.Guitar())
new_note=note.Note(pattern)
new_note.offset=offset
output_notes.append(new_note)
解决方案
Instrument 对象直接进入 Stream 对象,而不是 Note,并且每个 Part 一次只能有一个 Instrument 对象处于活动状态。
推荐阅读
- azure-data-explorer - Azure 数据资源管理器获取不同的值并按顺序排列
- reactjs - 从一个组件获取表单数据到另一个组件
- python - 在文本文件中找到最小的数字(python)
- outlook - Sharepoint 365:显示来自 Outlook 365 的未读电子邮件数量
- php - 如何将“删除”操作委托给 Cakephp4 中的另一个模型?
- maven - “mvn test”运行 testng 而不是 Junit
- python - 在python中创建对称矩阵的最快方法,元素如下
- python - 如何在外部源和 azure 突触分析之间传输数据
- yarnpkg - 如何在不删除锁定文件的情况下取消设置纱线分辨率?
- android - 需要 touchAction.tap 在所有不同尺寸的移动设备上工作