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 = (); controls = ();
} }
add { | name, control | add1d { | url, min, max, default, apply |
controls.put(name, control) 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 // // TODO: each of these needs to be able to write its value back
// // to its TouchOSC control - this should be a fairly simple // // to its TouchOSC control - this should be a fairly simple
// // method like ~ctrlset and ~ctrlget // // method like ~ctrlset and ~ctrlget

View File

@ -1,6 +1,4 @@
// fader, xy, radial, encoder, radar, radio, group, pager, grid
// 1d - fader, radial // 1d - fader, radial
// 2d - xy, radar // 2d - xy, radar
@ -8,38 +6,90 @@
// radio // radio
// OSCControl { TouchOSCControl {
// var <name, <url, <min, <max, <default, value, apply, set, get, send; 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 | // ~ctrlget = { | self | self.v.linlin(self.min, self.max, 0, 1) };
// ^super.new.init(name, url, min, max, default, apply)
// }
// //
// init { | aname, aurl, amin, amax, adefault, aapply | // ~ctrlexpset = { | self, msg | self.v = msg[1].linexp(0, 1, self.min, self.max); };
// name = aname; //
// url = aurl; // ~ctrlexpget = { | self | self.v.linlin(self.min, self.max, 0, 1) };
// min = amin;
// max = amax;
// default = adefault;
// apply = aapply;
// value = adefault;
// OSCdef.new(
// 'osc' ++ name,
// { | msg |
// // msg => value
// apply.value(value)
// }
// }
// //
// //
// OSCdef.new( // // getter and setter for an x-y control - the default, max and min are arrays
// 'osc' ++ name, // // of [ x, y ] pairs
// { | msg |
// settings.at(name).ctrlset(msg);
// settings.at(name).apply() },
// url
// );
// //
// // 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;
// };