TouchOSC/classes/TouchOSC.sc

108 lines
2.5 KiB
Python

// Class for binding to a TouchOSC interface
TouchOSC {
var <ip, <port=9000, controls;
*new { | ip, port |
^super.new.init(ip, port)
}
init { | aip, aport |
ip = aip;
port = aport;
controls = ();
}
add { | name, control |
controls.put(name, control)
}
}
// // 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
//
// // then call all of those on an iterator at startup to write the
// // defaults to the controller
//
// ~mset = {
// | name, oscurl, min, max, default, apply=({}), ctrlset=(~ctrlset), ctrlget=(~ctrlget), ctrlsend=(~ctrlsend) |
// ~sets.put(name, (
// name: name,
// oscurl: oscurl,
// default: default,
// min: min,
// max: max,
// v: default,
// ctrlset: ctrlset,
// ctrlget: ctrlget,
// ctrlsend: ctrlsend,
// apply: apply
// ));
// OSCdef.new(
// 'osc' ++ name,
// { | msg |
// ~sets.at(name).ctrlset(msg);
// ~sets.at(name).apply() },
// oscurl
// );
// };
//
//
//
//
//
// }
//
//
//
//
// ~sets = ();
//
// // The following two functions are the default methods for going from
// // touchOSC control settings (0-1) to setting values as defined by min,max.
// // Default uses linlin - for linexp or fancier stuff, override them.
// // It's up to you to make sure they're mathematically inverse.
//
//
//
// ~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;
// };
//
//
// // ~ctrlsend sends the current self.v back to the TouchOSC control,
// // for when we send the defaults or load a patch
//
// ~ctrlsend = {
// | self |
// var ctrlval = self.ctrlget();
// [ "ctrlsend", self.oscurl, ctrlval ].postln;
// ~touchosc.sendMsg(self.oscurl, ctrlval);
// };