as you know, I don't know much of Supercollider. My understanding is that
msg[0] is the OSC address (e.g.: /encoder)
msg[1] is the first argument, so in this case the encoder number (e.g.: 0, 1 up to the number of encoders you have)
msg[2] is the second argument, so in this case the value of the encoder.
as demonstrated by the below:
(
OSCdef.new(\any, {
arg msg, time, addr, port;
postf("ANY: %[%] is %\n", msg[0], msg[1], msg[2]);
}, '/encoder')
);
therefore I think what you are looking for is something like this:
(
OSCdef.new(\knob2, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\amp, msg[2].linexp(0.1,0.01,1)); // instead of msg[1]
}, '/encoder', nil, 5555, [2], )
);
vivian ERROR: OSC messages must have type tags.
I don't know where you are getting that error: I don't (but also I don't have all the encoders connected). As far as
know, the C++ code is OK. The OSC messages it sends are valid. However, you have a couple of errors in your Sc code:
(
OSCdef.new(\knob2, {
arg msg, time, addr, port;
x.set(\amp, msg[1].linexp(0.1,0.01,1));
}, '/encoder', 5555, [2], );
);
last line should be
}, '/encoder', nil, 5555, [2], );
also , you are missing one argument for linexp()
Then
(
OSCdef.new(\knob4, {
arg msg, time, addr, port;
x.set(\detune, msg[1].linexp(0,1,0.01,12));
}, '/encoder', \detune, 5555, [4], );
)
where you should take out \detune from the last line.
Also, remember that each encoder sends out an integer number corresponding to the current rotation, so you'll have to change the linexp/linlin range from 0, 1 to something like -50, 50 (unless you change the C++ side of things).
So, this works for me:
s.freeAll;
//open port
thisProcess.openUDPPort(5555);
//define control
OSCdef.freeAll
OSCdef.new(\any, { // catch all, for testing. each individual `OSCdef` will also print when matched
arg msg, time, addr, port;
postf("ANY: %[%] is %\n", msg[0], msg[1], msg[2]);
}, '/encoder')
);
(
OSCdef.new(\knob0, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\freq, msg[2].linexp(-50,50,20,500));
}, '/encoder', nil, 5555, [0], );
);
(
OSCdef.new(\knob1, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\pan, msg[2].linlin(-50, 50,-1,1));
}, '/encoder', nil, 5555, [1], );
);
(
OSCdef.new(\knob2, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\amp, msg[2].linexp(-50, 50, 0.01,1));
}, '/encoder', nil, 5555, [2], );
);
(
OSCdef.new(\knob3, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\nharm, msg[2].linlin(-50,50,1,50));
}, '/encoder', nil, 5555, [3], );
);
(
OSCdef.new(\knob4, {
arg msg, time, addr, port;
postf("%[%] is %\n", msg[0], msg[1], msg[2]);
x.set(\detune, msg[2].linexp(-50,50,0.01,12));
}, '/encoder', nil, 5555, [4], );
);
//compile synthdef
(
SynthDef.new(\example, {
arg freq=40, nharm=12, detune=0.2, gate=0,
pan=0, amp=1, out=0;
var sig, env;
env = EnvGen.kr(Env.adsr(0.05,0.1,0.5,3),gate);
sig = Blip.ar (
freq *
LFNoise1.kr(0.2!16).bipolar(detune.neg,detune).midiratio,
nharm
);
sig = sig * LFNoise1.kr(0.5!16).exprange(0.1,1);
sig = Splay.ar(sig);
sig = Balance2.ar(sig[0], sig[1], pan);
sig = sig * env * amp;
Out.ar(out, sig);
}).add
);
// open gate
x = Synth.new(\example, [\gate, 1]);
vivian also do you think this is a suitable way to edit the main.cpp parse to send floats or should i be more focused on how they are being recieved in SC?
no, that is parsing floats, not sending floats.