Receiving messages from a basic linear control

main
Mike Lynch 2022-03-27 12:05:42 +11:00
parent 2cfe624ff7
commit 94be9f50f7
2 changed files with 92 additions and 32 deletions

View File

@ -14,11 +14,21 @@ TouchOSC {
controls = ();
}
add { | name, control |
controls.put(name, control)
add1d { | url, min, max, default, apply |
var scale = TouchOSCScale(min, max, default);
controls.put(url, TouchOSCControl(url, scale, apply));
}
add2d { | name, scale1, scale2, apply |
}
addradio { | name, apply |
}
}
// // TODO: each of these needs to be able to write its value back
// // to its TouchOSC control - this should be a fairly simple
// // method like ~ctrlset and ~ctrlget

View File

@ -1,6 +1,4 @@
// fader, xy, radial, encoder, radar, radio, group, pager, grid
// 1d - fader, radial
// 2d - xy, radar
@ -8,38 +6,90 @@
// radio
// OSCControl {
// var <name, <url, <min, <max, <default, value, apply, set, get, send;
TouchOSCControl {
var <url, <scale, <value, apply;
*new { | url, scale, apply |
^super.new.init(url, scale, apply)
}
init { | aurl, ascale, aapply |
url = aurl;
scale = ascale;
apply = aapply;
value = scale.default;
this.oscdef();
}
oscdef {
OSCdef.new(
'osc' ++ url,
{ | msg |
value = scale.tovalue(msg[1]);
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); };
//
// *new { | name, url, min, max, default, apply |
// ^super.new.init(name, url, min, max, default, apply)
// }
// ~ctrlget = { | self | self.v.linlin(self.min, self.max, 0, 1) };
//
// init { | aname, aurl, amin, amax, adefault, aapply |
// name = aname;
// url = aurl;
// min = amin;
// max = amax;
// default = adefault;
// apply = aapply;
// value = adefault;
// OSCdef.new(
// 'osc' ++ name,
// { | msg |
// // msg => value
// apply.value(value)
// }
// }
// ~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) };
//
//
// OSCdef.new(
// 'osc' ++ name,
// { | msg |
// settings.at(name).ctrlset(msg);
// settings.at(name).apply() },
// url
// );
// // 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;
// };