通过 MacOS 上的端口发送 MIDI 数据到数码钢琴
Send MIDI data via port on MacOS to Digital Piano
我想通过端口从我的计算机 (运行 MacOS) 将 midi 数据发送到我的数码钢琴。
我希望能够播放 MIDI 文件,在特定的持续时间内播放特定的音符并可能更改乐器。
我完全不知道如何实现这一点,也无法在网上找到任何资源。
请在您的解决方案中提供代码,因为它会有很大帮助。
我正在使用 USB-to-Host 发送数据 --> 不确定这是否意味着什么。
不确定这算不算是一个不错的堆栈溢出问题。互联网上有很多关于 MIDI 的资源。
搜索 'Python MIDI' 会出现此存储库 python-midi。
如果你阅读了 README,它似乎可以做你想做的事。
手动使用 Garageband:
- 将数码钢琴连接到电脑(MacOS)并打开。
- 使用 Garageband 打开 midi 文件,通常在 MacOS 设备上可用。
- 然后转到 Gargageband->首选项->'Audio/Midi'->'Output Device' 下拉菜单
- 如果数码钢琴被电脑识别,它应该列在下拉列表中。 Select它。
- 单击 Garageband 上的 'play' 图标。 MIDI 文件应与来自数码钢琴的输出一起播放。
以编程方式使用 Mido:
将数码钢琴连接到电脑(MacOS)并打开。
安装 mido python 包
pip install mido
获取mido可识别的midi端口列表:
python -c "import mido; print(mido.get_output_names())"
输出应该是这样的:
['Digital Keyboard', 'IAC Driver Bus 1']
在此示例中,'Digital Keyboard' 是您的键盘。
您的实际键盘可能有不同的名称。
注意:'IAC Driver Bus 1' 是标准的 MacOS midi 输出端口。
通过将 'Digital Keyboard' 更改为 #3 中 mido 显示的键盘名称来更新以下 play-midi.py 脚本。将 *.mid 文件更新为您的 *.mid 文件的名称。
import mido
# This will list the available ports
print(mido.get_output_names())
# Open the midi link to your keyboard
outport = mido.open_output('Digital Keyboard')
# Open the mid file to be played
mid = mido.MidiFile('my_midi_file.mid', clip=True)
# Play the file out to your keyboard
for msg in mid.play():
outport.send(msg)
- 运行 脚本。声音应该从您的键盘中播放。
美度参考资源:
https://github.com/mido/mido
https://mido.readthedocs.io/en/latest/midi_files.html
我想通过端口从我的计算机 (运行 MacOS) 将 midi 数据发送到我的数码钢琴。 我希望能够播放 MIDI 文件,在特定的持续时间内播放特定的音符并可能更改乐器。
我完全不知道如何实现这一点,也无法在网上找到任何资源。 请在您的解决方案中提供代码,因为它会有很大帮助。
我正在使用 USB-to-Host 发送数据 --> 不确定这是否意味着什么。
不确定这算不算是一个不错的堆栈溢出问题。互联网上有很多关于 MIDI 的资源。
搜索 'Python MIDI' 会出现此存储库 python-midi。
如果你阅读了 README,它似乎可以做你想做的事。
手动使用 Garageband:
- 将数码钢琴连接到电脑(MacOS)并打开。
- 使用 Garageband 打开 midi 文件,通常在 MacOS 设备上可用。
- 然后转到 Gargageband->首选项->'Audio/Midi'->'Output Device' 下拉菜单
- 如果数码钢琴被电脑识别,它应该列在下拉列表中。 Select它。
- 单击 Garageband 上的 'play' 图标。 MIDI 文件应与来自数码钢琴的输出一起播放。
以编程方式使用 Mido:
将数码钢琴连接到电脑(MacOS)并打开。
安装 mido python 包
pip install mido
获取mido可识别的midi端口列表:
python -c "import mido; print(mido.get_output_names())"
输出应该是这样的:
['Digital Keyboard', 'IAC Driver Bus 1']
在此示例中,'Digital Keyboard' 是您的键盘。
您的实际键盘可能有不同的名称。
注意:'IAC Driver Bus 1' 是标准的 MacOS midi 输出端口。通过将 'Digital Keyboard' 更改为 #3 中 mido 显示的键盘名称来更新以下 play-midi.py 脚本。将 *.mid 文件更新为您的 *.mid 文件的名称。
import mido
# This will list the available ports
print(mido.get_output_names())
# Open the midi link to your keyboard
outport = mido.open_output('Digital Keyboard')
# Open the mid file to be played
mid = mido.MidiFile('my_midi_file.mid', clip=True)
# Play the file out to your keyboard
for msg in mid.play():
outport.send(msg)
- 运行 脚本。声音应该从您的键盘中播放。
美度参考资源:
https://github.com/mido/mido
https://mido.readthedocs.io/en/latest/midi_files.html