Compare commits

...

10 Commits

Author SHA1 Message Date
Mike Lynch 2df49cdac8 Send to control 2023-09-30 15:01:51 +10:00
Mike Lynch 464412494a TouchOSCLabel class 2023-04-15 15:48:42 +10:00
Mike Lynch 61130aa239 Improved warning messages when getting or setting a control that
hasn't been defined
2023-04-15 15:48:28 +10:00
Mike Lynch 4849ff7a68 Tidied up the api, added times to control sends, setting a controls value now calls its apply function 2022-04-24 16:38:10 +10:00
Mike Lynch e272a34dfe Used a Dictionary instead of an Environment to store the controls 2022-04-02 15:09:03 +11:00
Mike Lynch 5d3dd866eb Setting, getting and sending buttons, sliders and x-y controls 2022-04-02 14:58:49 +11:00
Mike Lynch 95a32d81c7 Added a TouchOSCControlButton which will handle radio and single
button controls
2022-03-27 13:00:45 +11:00
Mike Lynch 2350e9cf6b 2-d control binding is working 2022-03-27 12:44:53 +11:00
Mike Lynch 94be9f50f7 Receiving messages from a basic linear control 2022-03-27 12:05:42 +11:00
Mike Lynch 2cfe624ff7 Renaming etc 2022-03-27 11:04:56 +11:00
2 changed files with 198 additions and 8 deletions

View File

@ -1,19 +1,71 @@
// Class for binding to a TouchOSC interface
//
// I don't feel well enough to actually code this today so here are some notes.
// - bind a /url to a function
// - provide builtins for linear and exponential controls
// - provide builtins for X-Y and modal/radio buttons
//
//
TouchOSC {
var <>ip, <>port;
var <net, <controls;
*new { | ip, port |
^super.new.init(ip, port)
}
init { | ip, port |
net = NetAddr(ip, port);
controls = Dictionary();
}
send { | url ... oargs |
net.sendMsg(url, *oargs)
}
label { | url, default |
var ctrl = TouchOSCLabel(this, url, default);
ctrl.init();
controls.put(url, ctrl);
^ctrl;
}
button { | url, default, apply |
var ctrl = TouchOSCControl(this, url, apply, default);
ctrl.init();
controls.put(url, ctrl);
^ctrl;
}
slider { | url, default, scale, apply |
var ctrl = TouchOSCControlScale(this, url, apply, default, scale);
ctrl.init();
controls.put(url, ctrl);
^ctrl;
}
xy { | url, default, scale1, scale2, apply |
var ctrl = TouchOSCControlXY(this, url, apply, default, scale1, scale2);
ctrl.init();
controls.put(url, ctrl);
^ctrl;
}
v { | url |
^if( controls.at(url).isNil.not,
{ controls.at(url).value },
{ ("v: No control with url" + url).postln }
);
}
v_ { | url, v |
^if( controls.at(url).isNil.not,
{ controls.at(url).value_(v) },
{ ("v_: No control with url" + url).postln }
);
}
s_ { | url, v |
^if( controls.at(url).isNil.not,
{ controls.at(url).send_(v) },
{ ("s_: No control with url" + url).postln }
);
}
}

View File

@ -0,0 +1,138 @@
TouchOSCControl {
var <touchOSC, <url, apply, <value;
*new { | touchOSC, url, apply, value |
^super.newCopyArgs(touchOSC, url, apply, value)
}
init {
OSCdef.new(
'osc' ++ url,
{ | msg, time |
value = msg[1];
apply.value(value, time)
},
url
);
apply.value(value, 0);
this.send();
}
value_ { |newval|
value = newval;
apply.value(value, 0);
this.send();
}
send {
touchOSC.send(url, value);
}
send_ { |newval|
value = newval;
this.send();
}
}
TouchOSCControlScale : TouchOSCControl {
var scale;
*new { | touchOSC, url, apply, value, scale |
^super.newCopyArgs(touchOSC, url, apply, value, scale)
}
init {
OSCdef.new(
'osc' ++ url,
{ | msg, time |
value = scale.tovalue(msg[1]);
apply.value(value, time);
},
url
);
apply.value(value, 0);
this.send();
}
send {
touchOSC.send(url, scale.toctrl(value));
}
}
TouchOSCControlXY : TouchOSCControl {
var scale1, scale2;
*new { | touchOSC, url, apply, value, scale1, scale2 |
^super.newCopyArgs(touchOSC, url, apply, value, scale1, scale2)
}
init {
OSCdef.new(
'osc' ++ url,
{ | msg, time |
value[0] = scale1.tovalue(msg[1]);
value[1] = scale2.tovalue(msg[2]);
apply.value(value, time);
},
url
);
apply.value(value, 0);
this.send();
}
send {
touchOSC.send(url, scale1.toctrl(value[0]), scale2.toctrl(value[1]));
}
}
TouchOSCLabel {
var <touchOSC, <url, <value;
*new { | touchOSC, url, value |
^super.newCopyArgs(touchOSC, url, value)
}
init {
this.send();
}
value_ { |newval|
value = newval;
this.send();
}
send {
touchOSC.send(url, value);
}
}
TouchOSCScale {
var <min, <max;
*new { | min, max |
^super.newCopyArgs(min, max)
}
tovalue { | c | ^c.linlin(0, 1, min, max) }
toctrl { | v | ^v.linlin(min, max, 0, 1) }
}
// todo - better validation so that you can't set min as 0
TouchOSCScaleExp : TouchOSCScale {
tovalue { | c | ^c.linexp(0, 1, min, max) }
toctrl { | v | ^v.explin(min, max, 0, 1) }
}