RedInfoSms read data from sudden motion sensor
Only works on newer portable Mac models running OS X (10.4 or newer).
Using UniMotion 0.4.1 (http://unimotion.sourceforge.net/) by Lincoln Ramsay
Version notes:
This version the prefered version. RedInfoSms2 and RedInfoSms3 are less refined and use integer data.
Warning:
Don't expect the xyz directions to be the same on all Mac portables. Apple changed x axis a few times.
see also: RedInfoSms2 RedInfoSms3 RedInfoBat RedInfoLmu
*kr(trig)
returns 3 channels. x, y and z sensor data (floats).
zeros if no sensors installed.
trig asks for a new reading. the faster you ask, the more cpu it will require.
note: there is only one reading function internally. a trigger will cause global reading for all ugens.
it makes little sense to have this ugen running in multiple synths. use busses.
//--
s.boot;
{RedInfoSms.kr(Impulse.kr(2)).poll; DC.ar(0)}.play; //update twice a second
//very sensitive but will require a bit extra of the cpu
{Mix(SinOsc.ar(RedInfoSms.kr(Impulse.kr(50))*500+500, 0, 0.4))}.play;
//less cpu with lower trig rate and using ramp to smooth data
{Mix(SinOsc.ar(Ramp.kr(RedInfoSms.kr(Impulse.kr(10)))*500+500, 0, 0.4))}.play;
//--gui test
(
var w= Window("RedInfoSms", Rect(100, 200, 300, 120));
var c= [-2, 2, 'lin', 0, 0].asSpec;
var x= EZSlider(w, Rect(0, 10, 280, 20), "x", c);
var y= EZSlider(w, Rect(0, 40, 280, 20), "y", c);
var z= EZSlider(w, Rect(0, 70, 280, 20), "z", c);
w.view.background= Color.red(0.75);
w.front;
SynthDef(\suddenmotionsensor, {|rate= 15| //update rate
var trig= Impulse.kr(rate);
SendReply.kr(trig, 'xyz', RedInfoSms.kr(trig));
}).play(s);
OSCresponder(s.addr, 'xyz', {|t, resp, m|
{
x.value= m[3];
y.value= m[4];
z.value= m[5];
}.defer;
}).add;
)