Created
July 11, 2019 11:04
-
-
Save jarmitage/8c2628bea419351a4850a493e98a69af to your computer and use it in GitHub Desktop.
Bela SuperCollider Printing Sensors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( // connect to the already-running remote belaserver | |
Server.default = s = Server("belaServer", NetAddr("192.168.7.2", 57110)); | |
s.options.maxLogins = 4; // should match the settings on the Bela | |
s.initTree; | |
s.startAliveThread; | |
); | |
( | |
// msgArray = [button, fsr, knob] // every three SendTrig's | |
~msgArray = [0,0,0]; | |
~count = 3; | |
~counter = 0; | |
o = OSCresponderNode(s.addr, '/tr', { arg time,resp,msg; | |
// msg[ /tr, nodeID, id, value] | |
if (msg[2] == 0, // button | |
{~msgArray.put(0, msg[3].asStringPrec(0))}, | |
{} | |
); | |
if (msg[2] == 1, // fsr | |
{ | |
msg[3] = msg[3] / 0.78; | |
~msgArray.put(1, msg[3].asStringPrec(2)) | |
}, | |
{} | |
); | |
if (msg[2] == 2, // knob | |
{ | |
msg[3] = msg[3] / 0.83; | |
~msgArray.put(2, msg[3].asStringPrec(2))}, | |
{} | |
); | |
~counter = ~counter + 1; | |
if (~counter == ~count, | |
{ | |
"[Bela] Button: ".post; | |
~msgArray[0].post; | |
" FSR: ".post; | |
~msgArray[1].post; | |
" Knob: ".post; | |
~msgArray[2].postln; | |
~counter = 0; | |
}, | |
{} | |
); | |
}).add; | |
// o.remove; | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
("/path/to/bela_startup.scd").load; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
SynthDef("synth",{ arg out=0; | |
var button = DigitalIn.kr(0); | |
var fsr = AnalogIn.ar(0); | |
var knob = AnalogIn.ar(1); | |
// Do not delete SendTrig: this enables printing to the console | |
SendTrig.kr(Impulse.kr(10), [0,1,2], [button,fsr,knob]); | |
Out.ar(out, | |
SinOsc.ar( 400, [0,0], 0.1) | |
) | |
}).send(s); | |
); | |
a = Synth.new("synth", target: s).postln; | |
a.free; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Messy code. Note this uses the deprecated
OSCresponderNode
, should be replaced withOSCdef
/OSCFunc
.