SC code Ipson


Code example for driving the OSC-CV convertor in Sonology BEA-5

//Start code:
/// BEA5 OSC Connector provides a GUI with 8 sliders that are used to send data to the patch bay in BEA5. /
/// Each slider is mapped to an OSC value between 0 and 4095. ///
/// These are then converted in the patch bay to a voltage of 0-5 V ///
/// User Instructions: ///
/// 1. Run the Global Vars code ///
/// 2. Run the GUI code ///
/// 3. Run the Routine ///
/// 4. Play with the sliders ///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Global Vars ///
(
~host = “10.1.60.34”; /// BEA5 ip
~port = 10001; ///// BEA5 port
~netAddr = NetAddr.new(~host, ~port);
~speed = 50 //in Hz
)

/// GUI ///
(
~sliders = [0, 0, 0, 0, 0, 0, 0, 0];

n = ~sliders.size;
w = Window(“BEA5 OSC COnnector”, Rect(700, 300, 530, 370));
m = MultiSliderView(w,Rect(10,10,510,350));
m.value= ~sliders;
m.isFilled_(true);
m.indexThumbSize_(60);
m.gap_(4);
w.front;
m.action = { arg q;
~sliders = (q.value * 4095).asInteger;
};
)

/// Routine sends data to Patch Bay ///
(
Routine.new({
inf.do({
var values, outgoingMsg;
values = [0, 0, 0, 0];

4.do({ arg i;
var s1, s2, value;
s1 = (~sliders[i*2] & 4095) << 16;
s2 = ~sliders[(i*2)+1] & 4095;
value = s1 + s2;
values.put(i, value);
});

outgoingMsg = [‘/1’, values[0], values[1], values[2], values[3]];
outgoingMsg.postln;

~netAddr.sendMsg(*outgoingMsg);
(1/~speed).wait;
})
}).play();
)

//EndCode