Noob: MIDI srcID handling

I have 2 MIDI devices on my Mac, MIDIClient.init gives this:

MIDI Sources:
	MIDIEndPoint("IAC-Treiber", "IAC-Bus 1")
	MIDIEndPoint("Midi Fighter Twister", "Midi Fighter Twister")
MIDI Destinations:
	MIDIEndPoint("IAC-Treiber", "IAC-Bus 1")
	MIDIEndPoint("Midi Fighter Twister", "Midi Fighter Twister")

So far I’ve been using
MIDIIn.connect(inport: 0, device: 1);
to connect just to the MIDI Fighter as input device.

This way, my MIDIDef isn’t using the srcID keyword, it just looks at all incoming MIDI data, which is just coming from MIDI Fighter due to MIDIIn.connect(inport: 0, device: 1);

Now I want to listen to incoming MIDI from both IAC and MIDI Fighter, but want specific MIDIDefs to listen to either IAC or MIDIFighter. So I need to do
MIDIIn.connectAll;
first, right?

Then I thought that the srcID keyword inside the MIDIDef would allow to tell a MIDIDef to listen either to the IAC or the MIDI Fighter. But regardless of srcID being 0 or 1, the MIDIDef does no longer react.

Please, what am I do wrong?

Furthermore, MIDIOut allows a .newByName message, which is more fool-proof than a device ID. Is there something like that for MIDIDefs?

Sorry for having so many questions, thanks much in advance!

OK, I think I found my mistake: I confused the srcID with the device ID from the MIDIClient.init list.

The section “MIDIFunc and MIDIdef: Filtering based on device or message data” in the Using MIDI guide gives these 2 methods to find out the srcID.

Via the device ID:
MIDIClient.sources[1].uid;

Via the endpoint name:
MIDIClient.sources.detect { |e| e.device.contains ("Midi Fighter Twister") }.uid;

Here I found yet another method, also via the endpoint name:
MIDIIn.findPort("Midi Fighter Twister", "Midi Fighter Twister").uid;

So glad I found it! :slight_smile:

The device ID and the source UID you are referring to are the exact same thing, I believe.

MIDI is handled by the OS, which makes it very tricky to deal with, in certain cases.

The best way is to very carefully test each aspect of what you’re trying to do in isolation & after a full restart of SC.

…and if something appears strange then you must be be as thorough as possible, though usually restarting the OS will force quit everything for you.

Try connecting both controllers separately and achieving success this way before attempting to connect them both in tandem.

And remember to use MIDIdef.trace often.

One more thing… and while it’s generally not recommended, for debugging purposes, you can try:

MIDIIn.noteOn_

{
    |uid chnl note veloc|

    uid . switch
    
    { 0 } { "IAC" }
    { 1 } { "MFT" }
    /*
    {uid} { "else behavior" } */

    ;  Post <<* [ note , veloc ] << $\n << $\n 

    ;
}
1 Like

Small note on switch: an else branch doesn’t need a dummy condition. If the number of items (arguments) is odd, not including the receiver, then the last function serves as an “else” – so { uid } may be omitted here.

Agreed that MIDI can be delicate. I once had to reboot my machine onstage because the stage crew had put the machine to sleep before my piece, and this killed the MIDI connection :astonished: (but that was years ago…).

hjh

1 Like