以编程方式配置 Mac OS X MIDI

发布于 2024-11-05 07:16:26 字数 652 浏览 2 评论 0原文

我正在编写一个将 OSC 转换为 MIDI 的程序,允许启用 OSC 的应用程序(如我的 iPhone 上的 touchOSC)来控制启用 MIDI 的应用程序(Sibelius、Ableton Live 等)。

我正在使用 Python 创建 OSC 服务器并将 OSC 转换为 MIDI。为了将 MIDI 传输到相关应用程序,我将 MIDI 输出到 Apple IAC 驱动程序,然后在相关程序中将其启用为输入。

有谁知道以编程方式配置 Mac MIDI 设备的方法吗?特别是,我需要启用 IAC 驱动程序,该驱动程序默认情况下处于禁用状态。

使用 FileMon,我观察到 Audio Midi Setup.app 在启用/禁用 IAC 驱动程序时修改了此文件:

~/Preferences/ByHost/com.apple.MIDI.0017f2cxxxxx.plist

数字 0017f2cxxxxx 是我的系统 IOPlatformUUID。这是一个简单的 XML 属性列表,但我对直接写入它持谨慎态度。即使我这样做了,大概我也需要哄骗 midi 服务器进程以某种方式重新读取它?

最后,我越来越意识到使用 IAC 驱动程序根本就是一个相当蹩脚的解决方案 - 首先它只能在 Mac 上运行!理想情况下,我会编写一个环回 MIDI 驱动程序,然后我所有的问题都将得到解决......

I'm writing a program that converts OSC into MIDI, allowing OSC enabled applications (like touchOSC on my iPhone) to control MIDI enabled applications (Sibelius, Ableton Live and so on).

I'm using Python to create an OSC server and convert from OSC to MIDI. To get MIDI to the application in question, I'm outputting MIDI to the Apple IAC driver, which is then enabled as an input within the program in question.

Does anyone know of a means to programmatically configure Mac MIDI devices programmatically? In particular, I need to enable the IAC driver, which is disabled by default.

Using FileMon, I have observed that Audio Midi Setup.app modifies this file when enabling/disabling the IAC driver:

~/Preferences/ByHost/com.apple.MIDI.0017f2cxxxxx.plist

The number 0017f2cxxxxx is my system IOPlatformUUID. It's a simple XML property list, but I'm wary of writing to it directly. Even if I did, presumably I would need to cajole the midi server process into re-reading it somehow?

Finally, I'm becoming more and more aware that using the IAC driver at all is a pretty naff solution - for a start it only works on Mac! Ideally, I would write a loopback MIDI driver and all my problems would be solved...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只怪假的太真实 2024-11-12 07:16:26

您对直接写入 plist 的预感是正确的——您可能不应该这样做。我对此不是 100% 确定,但我有一种感觉,plist 反映了 MIDI 设备的状态,但更改它不会根据您的需要打开或关闭该 MIDI 设备。

要实际打开 MIDI 设备,您可以使用 pygame 之类的东西。我已经将它用于一些与音频相关的项目,并且该 SDK 非常简单且易于使用。由于 python 没有直接对 MIDI 提供很好的支持,这可能是你最好的选择(除非你自己编写 python C 模块,这将是相当痛苦的)。

至于 IAC,很遗憾其他操作系统没有配备这样的虚拟 MIDI 设备。 IAC 非常有用并且擅长它的工作。因此,虽然依赖 IAC 来完成类似的事情不会是跨平台的,但您可以编写一个抽象层来操作环回设备。对于 Windows 用户,您可以推荐免费 MIDI 环回设备与您的软件一起使用。

Your hunch about writing directly to the plist is correct -- you probably shouldn't do it. I'm not 100% sure about this, but I have a feeling that the plist reflects the state of the MIDI device, but altering it will not open or close that MIDI device as you need.

To actually open the MIDI device, you could use something like pygame. I have used it for some audio-related projects, and the SDK is very straightforward and easy to work with. As python doesn't have great support for MIDI directly, this is probably your best bet (short of writing the python C module yourself, which would be rather painful).

As for IAC, it's a shame that other OS's don't come with virtual MIDI devices like this. IAC is very useful and good at what it does. So while relying on IAC for something like this would not be cross-platform, you could write an abstraction layer for manipulating the loopback device. For Windows users, you could recommend a free MIDI loopback device to be used with your software.

浅笑依然 2024-11-12 07:16:26

如果您想将 OSC 发送到 MIDI,那么您最好在软件中创建虚拟 Midi 端口,而不是尝试远程配置 IAC。该虚拟端口将显示在 Ableton 等中,因此您可以让它以编程方式控制事物。

您可以使用 rtmidi-python 库(或更旧且略有不同的 pyrtmidi) - 均基于跨平台rtmidi lib,它提供直接发送 MIDI 控制和注释:

import rtmidi_python as rtmidi

vmidi_out = rtmidi.MidiOut()
vmidi_out.open_virtual_port('My Virtual MIDI Output Port')

vmidi_out.send_message([0x90, 48, 100]) # Note on
vmidi_out.send_message([176, 7, 100]) # Control Change - Volume 

If you want to send OSC to MIDI then you're best off creating a Virtual Midi port in software rather trying to remotely configure an IAC. This virtual port will show up in Ableton etc so you can then have it control things programmatically.

You can do this using the rtmidi-python library (or older and slightly different pyrtmidi) - both based on the cross-platform rtmidi lib which provides for straightforward sending of MIDI Control and Notes:

import rtmidi_python as rtmidi

vmidi_out = rtmidi.MidiOut()
vmidi_out.open_virtual_port('My Virtual MIDI Output Port')

vmidi_out.send_message([0x90, 48, 100]) # Note on
vmidi_out.send_message([176, 7, 100]) # Control Change - Volume 
谎言 2024-11-12 07:16:26

PyGame 本身在底层使用 PortMidi 。如果您不需要所有 PyGame 库,也许这对您有用。

PyGame itself uses PortMidi under the hood. If you don't need all PyGame library, maybe this can be useful for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文