如何用Windows Multimedia识别MIDI设备的独特之处?

发布于 2025-01-17 18:31:24 字数 348 浏览 3 评论 0原文

我最近探索了MACOS和Windows上可用的MIDI API(分别分别是MIDI和Windows Multimedia)并注意到:

在MacOS上,在查询可用来源的数量后,每个源可以 emelly>唯一 通过检查属性kmidipropertyuniqueid的值来标识。

在Win32上,我找不到明确的选择 - 似乎输入设备的“ ID”不仅仅是连接设备列表中的索引,随着新设备的连接和断开连接,它们可能随时更改。功能结构中的信息也可以从设备请求也不是特别独特,因为同时使用两个相同的MIDI键盘将导致两个相同的功能集,直到产品名称。

是否有某种方法可以在Winmm中唯一识别这些设备?

I've been exploring the MIDI APIs available on macOS and Windows recently (Core MIDI and Windows Multimedia, respectively) and noticed:

On MacOS, after querying for the number of available sources, each source can be uniquely identified by checking the value of the property kMIDIPropertyUniqueID.

On Win32, I can't find a clear alternative - it seems that an input device's "ID" is no more than the index into the list of connected devices, which could change at any time as new devices are connected and disconnected. Information in the capabilities structure one can request from a device is also not particularly distinctive, as using two of the same MIDI keyboard at once would result in two identical capability sets right down to the product name.

Is there some way to uniquely identify these devices in WinMM?

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

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

发布评论

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

评论(2

孤檠 2025-01-24 18:31:24

简短的回答是

WinMM中设备的ID实际上只是设备列表中的一个索引。因此,如果您拔下一台设备并插入另一台具有相同属性(例如名称)的设备,您将无法确定您使用的设备是旧设备还是新设备。当然,名称可以相同,所以这不是一个选择。

因此,从编程角度来看,Windows 中无法区分两个具有相同属性的 MIDI 设备。在应用程序中,您可以提供“刷新设备”或“测试设备”等按钮,以便与当前设备保持最新状态,并能够确定 GUI 中的哪个对象对应于 MIDI 设备。

对于 macOS,kMIDIPropertyUniqueID 是一个选项,但存在细微差别。来自常量的文档

系统为所有对象分配唯一的 ID。你可以这样设置
虚拟端点上的属性;但是,如果 ID 为空,则这样做可能会失败
并不独特。

所以在某些情况下你可以获得不独特的价值。在我看来,在 macOS 中识别设备的最可靠方法是使用其引用。例如,当您使用 MIDIGetSource 获取源设备时,您将获得 MIDIEndpointRef 作为结果。事实上,它是一个在系统范围内真正唯一的 UInt32 数字。

所以我在我的.NET库中DryWetMIDI依靠MIDIEndpointRef来区分MIDI设备在 macOS 中。还可以提供 MIDI 设备观看(添加/删除)。但不幸的是,对于 Windows 来说这是不可能的。

Short answer is no.

ID of a device in WinMM is indeed just an index in the devices list. So if you unplug one device and plug another one with the same properties (name, for example), you won't be able to determine whether the device you work with is the old one or new. Name, of course, can be the same, so that's not an option.

So from programming side there is no way to distinguish two MIDI devices with the same properties in Windows. In an app you can provide a button like "Refresh devices" or "Test device" to be up to date with current devices and to be able to determine which object in GUI corresponds to a MIDI device to.

As for macOS, kMIDIPropertyUniqueID is an option, BUT there are nuances. From the documentation on the constant:

The system assigns unique IDs to all objects. You may set this
property on virtual endpoints; however, doing so may fail if the ID
isn’t unique.

So in some cases you can get not unique value. In my opinion, the most reliable way to identify a device in macOS is to use its reference. For example, when you get a source device with MIDIGetSource you get MIDIEndpointRef as the result. In fact it's a UInt32 number which is truly unique in the scope of the system.

So I in my .NET library DryWetMIDI rely on MIDIEndpointRef to distinguish MIDI devices in macOS. Also it's possible to provide MIDI devices watching (adding/removing). But for Windows it's not possible unfortunately.

青衫负雪 2025-01-24 18:31:24

不幸的是,WinMM 中没有类似的功能。

您能做的最好的事情就是打开设备来获取它的句柄。该句柄将是唯一的,并且始终引用打开的设备,即使添加和删除其他设备也是如此。

获得句柄后,您可以使用 midiInGetID()midiOutGetID() 来获取 ID(以防 ID 发生更改)。

Unfortunately there is no equivalent in WinMM.

The best you can do is open the device to get a handle to it. The handle will be unique and will always refer to the opened device, even if other devices are added and removed.

Once you have the handle, you can use midiInGetID() or midiOutGetID() to get the ID in case it has changed.

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