标签: mido

如何从具有元组集和列表的现有字典创建嵌套字典

我已经解析了一个midi文件,并且我已经成功地得到了一个按乐器分解的音符字典。note_dict下面是一个简短的例子,为了这个问题的目的而被截断。

我的最终目标是拥有一个嵌套字典,为我提供曲目名称,然后将每个可能的音符作为键,然后将所有可能的“下一个”音符列表作为值。目的是将其用作Foxdot 中马尔可夫链,这是一个用于音乐生成的 Python 接口。

它应该看起来像:

{'track1': {note: [note1, note2, note3], note2: [note1, note2, note3]}, 'track2': {note: [note1, note2, note3], note2: [note1, note2, note3]}
Run Code Online (Sandbox Code Playgroud)

这是我所拥有的一个例子:

import itertools 

def pairwise(iterable):
    a, b = itertools.tee(iterable)
    next(b, None)
    return list(zip(a, b))

note_dict = {'Vocal': [-2, -2, -1, -2], 'Guitar': [1, 1, 4, 1, -2, 1]}

note_dict_updated = { track: [{ n for n in notes }, pairwise(notes), notes] for track, notes in note_dict.items() }
print(note_dict_updated)
Run Code Online (Sandbox Code Playgroud)

这给了我以下内容,其中第一组是所有不同的音符,元组列表是 的配对 …

python midi dictionary markov-chains mido

8
推荐指数
1
解决办法
144
查看次数

如何集成 Python mido 和 asyncio?

我有一个通过 MIDI 执行文件 I/O 的设备。我有一个使用 Mido 下载文件的脚本,但它是一堆全局变量。我想整理一下以正确使用 asyncio,但我不确定如何集成 mido 回调。我认为文档说我应该使用 Future 对象,但我不确定 mido 回调函数如何获取该对象。

python python-asyncio mido

5
推荐指数
1
解决办法
523
查看次数

Mido - 如何从不同端口实时获取 midi 数据

我创建了 2 个端口作为输入,用于从键盘和 midi 表面控制器(有一堆滑块和旋钮)捕获数据。虽然我不确定如何从两者获取数据

for msg1 in input_hw:
    if not msg1.type == "clock":
        print(msg1)
    # Play the note if the note has been triggered
    if msg1.type == 'note_on' or msg1.type == 'note_off' and msg1.velocity > 0:
        out.send(msg1)

for msg in input_hw2:
    #avoid to print the clock message
    if not msg.type == "clock":
        print(msg)
Run Code Online (Sandbox Code Playgroud)

第一个 For 循环有效,我在弹奏键盘时打开和关闭 MIDI 音符,该键盘与端口绑定input_hw,但第二个循环永远不会通过。

python mido

4
推荐指数
1
解决办法
1590
查看次数

在 Mac 上从 Python Mido 库输出 MIDI 声音

我正在尝试使用 python 和 mido 库向我的计算机内部扬声器输出注释。我有一台 Mac,我了解到默认情况下您需要通过 IAC 驱动程序才能将任何声音输出到扬声器。我启用 IAC 驱动程序并使用以下命令搜索正确的输出:

>>> mido.get_output_names()
['IAC Driver Bus 1']
Run Code Online (Sandbox Code Playgroud)

从那里我创建了简单的脚本:

进口美度

def main():

    outport = mido.open_output('IAC Driver Bus 1')
    outport.send(mido.Message('note_on', note=60, velocity = 100))

main()
Run Code Online (Sandbox Code Playgroud)

note=60 应该输出中音 C,力度是音量。

然而根本没有发出任何声音。我假设端口必须被识别,因为我没有收到错误,但同样没有声音输出。有人知道发生了什么事吗?

python macos midi mido

3
推荐指数
1
解决办法
2106
查看次数

Music21:获取音符的曲目索引

我有一个多轨 MIDI 文件,正在用 music21 读取:

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
Run Code Online (Sandbox Code Playgroud)

我想弄清楚该流中的每个音符属于哪个轨道。例如,当我在 GarageBand 中打开文件时,音符会组织成曲目:

在此输入图像描述

在 中mido,每个轨道 …

python midi music21 mido

2
推荐指数
1
解决办法
460
查看次数