ModalityTeam / Modality-toolkit

A SuperCollider toolkit to simplify the creation of personal (electronic) instruments utilising hardware and software controllers of any kind.
http://modalityteam.github.io/
87 stars 26 forks source link

MIDIMKtlDevice should use .indexOfEqual on Linux too #372

Closed elgiano closed 4 years ago

elgiano commented 4 years ago

If a midi device is unplugged and then re-plugged, it's impossible to .closeDevice and thus to .openDevice. This is because the new destDevice is not identical to the old one, even though they are equal. In my tests, a simple change from .indexOf to .indexOfEqual would fix it:

diff --git a/Modality/Classes/MIDI/MIDIMKtlDevice.sc b/Modality/Classes/MIDI/MIDIMKtlDevice.sc
index 51f19ac..87fde2b 100644
--- a/Modality/Classes/MIDI/MIDIMKtlDevice.sc
+++ b/Modality/Classes/MIDI/MIDIMKtlDevice.sc
@@ -55,7 +55,7 @@ MIDIMKtlDevice : MKtlDevice {
                this.cleanupElementsAndCollectives;
                destination.notNil.if {
                        if ( thisProcess.platform.name == \linux ) {
-                               midiOut.disconnect( MIDIClient.destinations.indexOf(destination) )
+                               midiOut.disconnect( MIDIClient.destinations.indexOfEqual(destination) )
                        };
                        midiOut = nil;
                };
@@ -254,7 +254,7 @@ MIDIMKtlDevice : MKtlDevice {
                destination.notNil.if {
                        if ( thisProcess.platform.name == \linux ) {
                                midiOut = MIDIOut( 0 );
-                               midiOut.connect( MIDIClient.destinations.indexOf(destination) )
+                               midiOut.connect( MIDIClient.destinations.indexOfEqual(destination) )
                        } {
                                midiOut = MIDIOut( MIDIClient.destinations.indexOfEqual(destination), dstID );
                        };
LFSaw commented 4 years ago

@adcxyz / @sensestage would this break code?

adcxyz commented 4 years ago

should be fine AFAICT, but I can't test on linux

elgiano commented 4 years ago

Sure! Btw, I see you had already patched midiout init in this direction in b8b75f420337b0cf69a6a510668057f3bfe29338