![](/img/trans.png)
[英]python mido how to get [note, starttime, stoptime, track] in a list?
[英]How to grab the note attribute from Message in mido?
我試圖在 .mid 文件中打印出 mido 輸出的每條消息中的 note 屬性。 現在,我的代碼如下所示:
for msg in mid.tracks[1]:
if not msg.is_meta:
print(msg.note)
但是,在運行代碼時,我收到錯誤:
AttributeError: 'Message' object has no attribute 'note'
我很困惑,因為文檔顯示相同的“msg.note”語法工作得很好。 任何幫助將非常感激。
有許多不同類型的 MIDI 信息,並不是所有的信息都有音符編號。
如果要打印所有筆記,則必須先檢查消息類型。 如果你想打印出所有的消息,你不能依賴那里的note
字段。
嘗試
if not msg.is_meta:
if msg.type == 'note_on':
print(msg.note)
這應該只產生數字注釋作為輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.