# Is MidiDeviceInfo::identifier unique per unit?

**URL:** <https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382>\
**Category:** General JUCE discussion\
**Created:** [March 31, 2020, 8:00pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382 "2020-03-31T20:00:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [March 31, 2020, 8:00pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/1 "2020-03-31T20:00:16Z")

</div>

Hopefully a quick question - is the [`MidiDeviceInfo::identifier`](https://docs.juce.com/master/structMidiDeviceInfo.html#af52764963e8f05a74f1cba4feb5fc968) unique per individual unit? Or only unique per device model (or perhaps firmware version of the device)?

For example, if I have 2 Korg nanoKeys plugged in, will they each have the same `identifier`, or different ones?

If others are interested in figuring this out empirically, I would be happy to post some identifier strings here, and we can compare. I just don’t have 2 of the same model unit here to check this myself.

PS: There is some overlap with the questions posed in this thread, but I don’t see the issue squarely answered there either:

> [@Unique identifiers for duplicate MIDI devices](https://forum.juce.com/t/unique-identifiers-for-duplicate-midi-devices/31375/11):
>
> Having the same issue myself! It is also important that the same device connected via Bluetooth or USB can be distinguished. Edit: The above fix on the develop branch works perfectly for me! I need to be able to support multiple instances of the same “Device” via USB or BLE (since the device can be run wired or wirelessly). Switched to using getAvailableDevices() and everything works like expected.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [April 1, 2020, 9:28am UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/2 "2020-04-01T09:28:59Z")

</div>

Yes, the identifier will be unique per unit so you can distinguish between two of the same connected devices. You can’t rely on them being persistent though and on Windows at least the indentifier may change based on the port that the device is connected to.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [April 1, 2020, 4:38pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/3 "2020-04-01T16:38:11Z")

</div>

Thanks Ed for the clarification. And good to know about the Windows caveat.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [August 27, 2020, 7:29pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/4 "2020-08-27T19:29:51Z")

</div>

I have now done some further testing on this question, with 2 of the same device model (in this case, 2 Behringer X-Touch Mini controllers), on macOS.

As @ed95 says, the `MidiDeviceInfo::identifier` is “unique per unit”, but that is only true for a given moment in time. The identifier is not a property that is inherent to the unit itself. Instead, it is partly based on the USB port that the device is plugged into, so the identifier can change when the device is plugged into different ports… but also it doesn’t necessarily change just from changing ports.

So basically, I’m agreeing with what Ed said, and adding that it’s also true on macOS as well as Windows, that the identifier can change based on which port a MIDI device is plugged into.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [August 27, 2020, 7:50pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/5 "2020-08-27T19:50:30Z")

</div>

To show an actual example, here are the results from iterating the output of `MidiInput::getAvailableDevices()`, and writing `.name` , `.identifier` of each entry to the debug output.

I start by plugging in only one unit at a time, to different ports:

When X-Touch unit A is in USB port 1:  
`X-TOUCH MINI, 1878780887`

When X-Touch unit A is in USB port 2:  
`X-TOUCH MINI, 1878780887`

When X-Touch unit B is in USB port 1:  
`X-TOUCH MINI, 1878780887`

So, all the same so far, even though I’m swapping around units and ports, but now I try both at once…

When X-Touch unit A is in USB port 1, and X-Touch unit B is in USB port 2:  
`X-TOUCH MINI, -1779811009`  
`X-TOUCH MINI, 1878780887`

And, once it has assigned these different identifiers, if I return to plugging in only one unit at a time, then:

When X-Touch unit A is in USB port 1:  
`X-TOUCH MINI, 1878780887`

When X-Touch unit A is in USB port 2:  
`X-TOUCH MINI, -1779811009`

_Now_ it gives different identifiers to the different ports!

---

<div class="post-metadata">

**Author:** ![narrsam](https://avatars.discourse-cdn.com/v4/letter/n/e99b99/32.png) [@narrsam](https://forum.juce.com/u/narrsam)\
**Post date:** [August 28, 2020, 12:02am UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/6 "2020-08-28T00:02:08Z")

</div>

Will the input and output of the same controller have identical identifiers?

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [August 28, 2020, 4:31am UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/7 "2020-08-28T04:31:14Z")

</div>

Ah, good idea to check, but unfortunately not.

Remember, MIDI hardware can have any number (including zero) of input ports and output ports (well, I suppose it needs at least 1 port of some kind, or it doesn’t qualify as “MIDI hardware”). If a particular device had one MIDI input and two MIDI outputs, which one of the outputs would share an identifier with the input?

---

<div class="post-metadata">

**Author:** ![narrsam](https://avatars.discourse-cdn.com/v4/letter/n/e99b99/32.png) [@narrsam](https://forum.juce.com/u/narrsam)\
**Post date:** [August 28, 2020, 3:56pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/8 "2020-08-28T15:56:32Z")

</div>

> [@leigh](#):
>
> If a particular device had one MIDI input and two MIDI outputs, which one of the outputs would share an identifier with the input?

Well in my particular case, I would love them all to have the same identifier, thinking of it as a usb port number of some sort. I know it is not the case, and if -let say- the device has dedicated 5din Midi in and out this will present more complications.

But as the nature of the modern devices that the Juce app will run on generally happens to connect to the device via usb that would make some sense.

Java on android for example treats the device as a device class, with input and output properties, very straight forward. I wish Juce had some kind of a class that can help with this out-of-the-box

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [September 1, 2020, 6:31pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/9 "2020-09-01T18:31:06Z")

</div>

As a complete side issue - @t0m can you tell me why my original post in this thread shows as having been edited twice? First time by you, second time by @jrlanglois?

It looks like the content was not actually modified either time. As an admin, I suppose you have forum permissions to edit users’ posts, but why would another user be allowed to do this?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [September 1, 2020, 7:45pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/10 "2020-09-01T19:45:21Z")

</div>

I’m adding categories and tags to posts that are missing them to help users sift through the wads of them.

To add, it looks like doing this is intrusive in that it notifies the OP, as well as pushing the post upwards in the category as a new reply was added… I might avoid doing this unless it’s really necessary. Sorry for any noise and confusion!

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [September 1, 2020, 8:10pm UTC](https://forum.juce.com/t/is-midideviceinfo-identifier-unique-per-unit/38382/11 "2020-09-01T20:10:29Z")

</div>

Ah, I see. Innocuous enough! I had looked for an explanation in the forum FAQ but couldn’t find anything.
