Bug in Ops.Devices.Midi.MidiInputDevice_v2 - SOLVED

Hey,

I encountered the following bug in the MidiInputDevice_v2 op.

There is an iterator for loop which assigns the midi message handler function to the selected device. It looks like this:

  for (let input = inputs.next(); input && !input.done; input = inputs.next()) {
    if (input.value.name === name) {
      input.value.onmidimessage = onMIDIMessage;
    } else if (input.value.onmidimessage === onMIDIMessage) input.value.onmidimessage = null;
  }

The if statement inside the loop however is comparing two values which are for some controllers the same and for other controllers different. In other words for some controllers:

input.value.name === name

Would return true and for others it would return false.

This is because some controllers have different input and output device names. In my case the input device is called “nanoKONTROL2 SLIDER/KNOB” and the output device is called “nanoKONTROL2 CTRL”

This can be seen easily with the logs below (when the device input and output names are different):

console.log(input.value.name);
console.log(name);

Because the if statement above is comparing the input device name to the output device name it returns false.

The code needs to be rewritten so that both input.value.name and name refer to the input device name.

P.S. My hotfix (for the op clone I made for myself) looks like this:

  for (let input = inputs.next(); input && !input.done; input = inputs.next()) {
    if (input.value.name === "nanoKONTROL2 SLIDER/KNOB"){
      input.value.onmidimessage = onMIDIMessage;
    } else {
      if (input.value.name === name) {
        input.value.onmidimessage = onMIDIMessage;
      } else if (input.value.onmidimessage === onMIDIMessage) input.value.onmidimessage = null;
    }
    // console.log(input.value.name);
    // console.log(name);
  }

But obviously that’s not a midi device agnostic solution. :slight_smile:

Hey subline,

Thanks for reporting. I will look into this as soon as possible and get back to you!

Cheers,

Simo

Dear subline,

I pushed a fix. Can you check if it works for you? No output devices used in the MidiInputDevice anymore. You should only see your input devices.

Hey,

I tried it. It works.

Thanks for pushing the official fix!

I have a question about your solution:

From what I can tell you are basically assigning the input device name to the output device… Is there ever a situation where this name will need to be used to send the controller a midi message (ex. to change an LED light)? If so, would this solution potentially break the sending of midi to the device (since that’s not its real output name) OR will the output device name assigned in this iterator not be (re)used in such way?

Dear subline,

For the input device, you don’t need any of the output devices. This is the same for any DAW. If you use ableton, the only thing you need to control parameters is your input device.

If you want to trigger LEDs on your midi controller, you need to send back the midi messages you get from your input device. We have an op for that, it’s called MidiOutputDevice. It only retrieves the availible output devices.

It’s the same in ableton: You need to send back the data you receive from your device to your device to get LED feedback.

The bug was the following:
When assigning the input devices, the name parameter was retrieved from the outputs, not the inputs. (It was a few lines above the snippet you posted).

I understand. I started thinking the Midi output op might be responsible for this after I wrote my last response, but wasn’t 100% sure. Thanks for clarifying.