Tidied up the api, added times to control sends, setting a controls value now calls its apply function

main
Mike Lynch 2022-04-24 16:38:10 +10:00
parent e272a34dfe
commit 4849ff7a68
2 changed files with 32 additions and 10 deletions

View File

@ -17,27 +17,41 @@ TouchOSC {
net.sendMsg(url, *oargs) net.sendMsg(url, *oargs)
} }
addbutton { | url, default, apply | button { | url, default, apply |
var ctrl = TouchOSCControl(this, url, apply, default); var ctrl = TouchOSCControl(this, url, apply, default);
ctrl.init(); ctrl.init();
controls.put(url, ctrl); controls.put(url, ctrl);
^ctrl; ^ctrl;
} }
addslider { | url, default, scale, apply | slider { | url, default, scale, apply |
var ctrl = TouchOSCControlScale(this, url, apply, default, scale); var ctrl = TouchOSCControlScale(this, url, apply, default, scale);
ctrl.init(); ctrl.init();
controls.put(url, ctrl); controls.put(url, ctrl);
^ctrl; ^ctrl;
} }
addxy { | url, default, scale1, scale2, apply | xy { | url, default, scale1, scale2, apply |
var ctrl = TouchOSCControlXY(this, url, apply, default, scale1, scale2); var ctrl = TouchOSCControlXY(this, url, apply, default, scale1, scale2);
ctrl.init(); ctrl.init();
controls.put(url, ctrl); controls.put(url, ctrl);
^ctrl; ^ctrl;
} }
v { | url |
^if( controls.at(url).isNil.not, {
controls.at(url).value
},
nil
);
}
v_ { | url, v |
^if( controls.at(url).isNil.not, {
controls.at(url).value_(v)
},
nil);
}
} }

View File

@ -10,17 +10,19 @@ TouchOSCControl {
init { init {
OSCdef.new( OSCdef.new(
'osc' ++ url, 'osc' ++ url,
{ | msg | { | msg, time |
value = msg[1]; value = msg[1];
apply.value(value) apply.value(value, time)
}, },
url url
); );
apply.value(value, 0);
this.send(); this.send();
} }
value_ { |newval| value_ { |newval|
value = newval; value = newval;
apply.value(value, 0);
this.send(); this.send();
} }
@ -39,15 +41,20 @@ TouchOSCControlScale : TouchOSCControl {
init { init {
OSCdef.new( OSCdef.new(
'osc' ++ url, 'osc' ++ url,
{ | msg | { | msg, time |
value = scale.tovalue(msg[1]); value = scale.tovalue(msg[1]);
apply.value(value); apply.value(value, time);
}, },
url url
); );
apply.value(value, 0);
this.send(); this.send();
} }
send {
touchOSC.send(url, scale.toctrl(value));
}
} }
TouchOSCControlXY : TouchOSCControl { TouchOSCControlXY : TouchOSCControl {
@ -60,18 +67,19 @@ TouchOSCControlXY : TouchOSCControl {
init { init {
OSCdef.new( OSCdef.new(
'osc' ++ url, 'osc' ++ url,
{ | msg | { | msg, time |
value[0] = scale1.tovalue(msg[1]); value[0] = scale1.tovalue(msg[1]);
value[1] = scale2.tovalue(msg[2]); value[1] = scale2.tovalue(msg[2]);
apply.value(value); apply.value(value, time);
}, },
url url
); );
apply.value(value, 0);
this.send(); this.send();
} }
send { send {
touchOSC.send(url, value[0], value[1]); touchOSC.send(url, scale1.toctrl(value[0]), scale2.toctrl(value[1]));
} }
} }