首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Music21:获取便笺的跟踪索引

Music21:获取便笺的跟踪索引
EN

Stack Overflow用户
提问于 2020-06-11 20:26:06
回答 1查看 304关注 0票数 2

我有一个多声道midi文件,我正在与music21一起阅读:

代码语言:javascript
复制
import music21

f = music21.midi.MidiFile()
f.open('1079-02.mid')
f.read()
stream = music21.midi.translate.midiFileToStream(f).flat
note_filter = music21.stream.filters.ClassFilter('Note')
for n in stream.recurse().addFilter(note_filter):
  offset = n.offset # offset from song start in beats
  note = n.pitch # letter of the note, e.g. C4, F5
  midi_note = n.pitch.midi # midi number of the pitch, e.g. 60, 72
  duration = n.duration # duration of the note in beats
  instrument = n.activeSite.getInstrument() # instrument voice

我想弄清楚这条小溪里的每一个音符都属于哪个音符。例如,当我在GarageBand中打开文件时,这些注释被组织成不同的轨道:

mido中,每个MidiFile都有一个tracks属性,其中包含每个曲目的注释列表。

有什么方法可以在music21中获得相同的结果吗?任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-19 02:24:00

音乐曲目被解析成单独的stream.Part对象,所以如果您避免将其扁平化(在这里,我刚刚用converter.parse()生成了一个流),您就可以遍历生成的stream.Score的各个部分了。

代码语言:javascript
复制
s = converter.parse('1079-02.mid')
for part in s.parts:
    for note in part.recurse().notes:
       print("I WAS IN PART ", part)

或查找包含的部分:

代码语言:javascript
复制
s = converter.parse('1079-02.mid')
for note in s.recurse().notes:
    part = note.sites.getObjByClass('Part')
    print("I WAS IN PART ", part)

我怀疑你真的需要把什么都压平。祝好运!

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62332985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档