# Fix for Linux ALSA MIDI Input devices with multiple inputs

**URL:** <https://forum.juce.com/t/fix-for-linux-alsa-midi-input-devices-with-multiple-inputs/3462>\
**Category:** Linux\
**Created:** [December 18, 2008, 7:33pm UTC](https://forum.juce.com/t/fix-for-linux-alsa-midi-input-devices-with-multiple-inputs/3462 "2008-12-18T19:33:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CPB](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@CPB](https://forum.juce.com/u/CPB)\
**Post date:** [December 18, 2008, 7:33pm UTC](https://forum.juce.com/t/fix-for-linux-alsa-midi-input-devices-with-multiple-inputs/3462/1 "2008-12-18T19:33:13Z")

</div>

Bit of an obscure one, but there is a problem with Linux ALSA MIDI Input devices when you have devices with multiple ports with the same name. For example, the drivers for my Axiom 25 have 2 ports (one for USB, one for the 5pin MIDI connector.)

In juce\_linux\_Midi.cpp iterateDevices, you do detect this situation and resolve it with a swift call to appendNumbersToDuplicates. This is fine when iterateDevices is called to iterateDevices, but when this function is called to retrieve a handle to a specific device, the while loop terminates with a break when a match is found. This causes a problem because it means the list doesn’t contain every device, which means duplicates aren’t detected, which means the name given to a device is different depending on the value of the deviceIndexToOpen parameter.

It’s an easy fix: remove the break at line 116.

` returnedHandle = seqHandle;
                                            break;`

Should be

` returnedHandle = seqHandle;
                                           `

Removing it doesn’t appear to be cause any other problems. I did however notice that this fix means that the portInfo for the selected device is now free’d, where before it wasn’t (which I strongly suspect was a memory leak.)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 18, 2008, 8:44pm UTC](https://forum.juce.com/t/fix-for-linux-alsa-midi-input-devices-with-multiple-inputs/3462/2 "2008-12-18T20:44:02Z")

</div>

Ah! That certainly is obscure, but many thanks for the fix!
