Week5 - SuperCollider - MIDIIn
Here is a post of my code for accepting MIDI input data from the JV-30 to control SuperCollider code. It is not completely accurate yet, but is fairly close. I managed to get some of my code working with the MIDIIn help file. I suspect that it is my "Connect by Device ID" that is correct, and that there is possibly something simple wrong with the instance of the synth.
MIDIClient.prList;
(MIDIClient.init;) //Initialises MIDI services
(MIDIClient.restart;) //Restart MIDI services
(
//Connect by Device ID (UID)
MIDIIn.connectByUID(
inport: 0,
uid: -382154081);
)
(
//Phasing
SynthDef(
\phasing,
{
//Arguments
arg carFreq = 440,
panPos = 0;
//Variables
var carrier,
env;
//Carrier
carrier = SinOsc.ar(carFreq, 0, 0.5);
//Envelope
env = carrier * EnvGen.kr(Env.perc, 1.0, doneAction:2);
//Output
Out.ar(0, Pan2.ar(env, panPos));
}
).send(s)
)
(//Create instance of synth
b = Synth("phasing");
//Setup MIDI Controller
MIDIIn.control = {
arg uid, //Device ID
chan, //MIDI channel
num, //Controller number
val, //Controller value
newVal; //New Controller value
//Scale value to MIDI range
if(num == 16, {
//Map value ranges
newVal = val.linlin(
inMin: 0,
inMax: 127,
outMin: 500,
outMax: 1000);
//Change frequency
b.set(
\carFreq, newVal );
}
);
});
Sometimes I think that Christian does not tell us everything, yet when we see his code it always works.
0 Comments:
Post a Comment
<< Home