120 lines
2.3 KiB
Python
120 lines
2.3 KiB
Python
|
|
|
|
// 1d - fader, radial
|
|
// 2d - xy, radar
|
|
// button
|
|
// radio
|
|
|
|
|
|
TouchOSCControl {
|
|
var <url, <value, apply, scale;
|
|
|
|
*new { | url, scale, apply |
|
|
^super.new.init(url, scale, apply)
|
|
}
|
|
|
|
init { | aurl, ascale, aapply |
|
|
url = aurl;
|
|
scale = ascale;
|
|
apply = aapply;
|
|
value = scale.default;
|
|
OSCdef.new(
|
|
'osc' ++ url,
|
|
{ | msg |
|
|
value = scale.tovalue(msg[1]);
|
|
apply.value(value)
|
|
},
|
|
url
|
|
);
|
|
}
|
|
}
|
|
|
|
// inheritance is too awkward or I don't understand it well enough
|
|
|
|
TouchOSCControl2d {
|
|
var <url, <value, scale1, scale2, apply;
|
|
|
|
*new { | url, scale1, scale2, apply |
|
|
^super.new.init(url, scale1, scale2, apply)
|
|
}
|
|
|
|
init { | aurl, ascale1, ascale2, aapply |
|
|
url = aurl;
|
|
scale1 = ascale1;
|
|
scale2 = ascale2;
|
|
apply = aapply;
|
|
value = [ scale1.default, scale2.default ];
|
|
OSCdef.new(
|
|
'osc' ++ url,
|
|
{ | msg |
|
|
value[0] = scale1.tovalue(msg[1]);
|
|
value[1] = scale2.tovalue(msg[2]);
|
|
apply.value(value);
|
|
},
|
|
url
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchOSCScale {
|
|
var <min, <max, <default;
|
|
|
|
*new { | min, max, default |
|
|
^super.new.init(min, max, default)
|
|
}
|
|
|
|
init { | amin, amax, adefault |
|
|
min = amin;
|
|
max = amax;
|
|
default = adefault;
|
|
}
|
|
|
|
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) }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ~ctrlset = { | self, msg | self.v = msg[1].linlin(0, 1, self.min, self.max); };
|
|
//
|
|
// ~ctrlget = { | self | self.v.linlin(self.min, self.max, 0, 1) };
|
|
//
|
|
// ~ctrlexpset = { | self, msg | self.v = msg[1].linexp(0, 1, self.min, self.max); };
|
|
//
|
|
// ~ctrlexpget = { | self | self.v.linlin(self.min, self.max, 0, 1) };
|
|
//
|
|
//
|
|
// // getter and setter for an x-y control - the default, max and min are arrays
|
|
// // of [ x, y ] pairs
|
|
//
|
|
// // note: msg is what we get from the OSC and x = 1, y = 2
|
|
//
|
|
// ~ctrlxyset = {
|
|
// | self, msg |
|
|
// self.v[0] = msg[1].linlin(0, 1, self.min[0], self.max[0]);
|
|
// self.v[1] = msg[2].linlin(0, 1, self.min[1], self.max[1]);
|
|
// };
|
|
//
|
|
// ~ctrlxyget = {
|
|
// | self |
|
|
// var vals = [ 0, 0 ];
|
|
// vals[0] = self.v[0].linlin(self.min[0], self.max[0], 0, 1);
|
|
// vals[1] = self.v[1].linlin(self.min[1], self.max[1], 0, 1);
|
|
// vals;
|
|
// };
|