1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
+ MIDIClient {
*externalSources{
^MIDIClient.sources.select({ |src,i|
// src.device != "SuperCollider"
(src.uid >> 16) != this.getClientID;
})
}
*externalDestinations{
^MIDIClient.destinations.select({ |src,i|
// src.device != "SuperCollider"
(src.uid >> 16) != this.getClientID;
})
}
*getClientID {
_GetMIDIClientID;
^this.primitiveFailed;
}
}
+ MIDIIn{
*connectAll { |verbose=true|
if(MIDIClient.initialized.not,
{ MIDIClient.init(verbose: verbose) },
{ MIDIClient.disposeClient; MIDIClient.init(verbose: verbose); }
// on Linux, supercollider creates as many MIDI ports for SC as there are devices to connect to; MIDIClient.list will find the new sources, but there will not be a matching port initialized for SC to connect it to; therefor we reinitialize the client.
);
MIDIClient.externalSources.do({ |src,i|
MIDIIn.connect(i,src);
});
}
}
+ MIDIOut{
// uid is not set by connect, in order to enable several connections to one output. set the uid directly, if you only want to send data to one MIDI destination.
connect{ arg device = 0;
MIDIOut.connect( port, device );
/*
var cuid, dest;
if(device.isNumber, {
if(device >= 0, {
if(MIDIClient.initialized.not,{ MIDIClient.init });
if ( device > MIDIClient.destinations.size, {
cuid = device;
},{
dest = MIDIClient.destinations.at(device);
if(dest.isNil,{
"MIDIClient failed to init".warn;
},{
cuid = MIDIClient.destinations.at(device).uid;
})
})
},{
cuid = device;
});
},{
if(device.isKindOf(MIDIEndPoint), {cuid = device.uid}); // else error
});
MIDIOut.connectByUID( port,cuid );*/
}
disconnect{ |cuid|
var res;
MIDIOut.disconnect( port, cuid );
// MIDIOut.disconnectByUID(port,cuid);
// reset the uid to 0
// uid = 0;
}
*connect { arg outport=0, device=0;
var uid,dest;
if(MIDIClient.initialized.not,{ MIDIClient.init });
if(device.isNumber, {
if(device >= 0, {
if ( device > MIDIClient.destinations.size, {
dest = MIDIClient.destinations.select{ |it| it.uid == device }.first;
if(dest.isNil,{
("MIDI device with uid"+device+ "not found").warn;
},{
uid = dest.uid;
})
},{
dest = MIDIClient.destinations.at(device);
if(dest.isNil,{
"MIDIClient failed to init".warn;
},{
uid = MIDIClient.destinations.at(device).uid;
})
})
},{
uid = device;
});
},{
if(device.isKindOf(MIDIEndPoint), {uid = device.uid}); // else error
});
this.connectByUID(outport,uid);
}
*disconnect { arg outport=0, device=0;
var uid,dest;
if(device.isKindOf(MIDIEndPoint), {uid = device.uid});
if(device.isNumber, {
if(device.isPositive, {
if ( device > MIDIClient.destinations.size, {
dest = MIDIClient.destinations.select{ |it| it.uid == device }.first;
if(dest.isNil,{
("MIDI device with uid"+device+ "not found").warn;
},{
uid = dest.uid;
})
},{
uid = MIDIClient.destinations.at(device).uid
});
},{
uid = device;
});
});
this.disconnectByUID(outport,uid);
}
*connectByUID {arg outport, uid;
_ConnectMIDIOut
^this.primitiveFailed;
}
*disconnectByUID {arg outport, uid;
_DisconnectMIDIOut
^this.primitiveFailed;
}
}
|