MultiTouchPad communicates with multitouch enabled touchpads of MacBooks
Inherits from: Object
This class allows you to use the multitouch enabled touchpad available in various MacBook models. The touchpad support is not integrated into SC at this time, so you need to download, compile and install tongsengmod (an application forked from the tongseng project to be used with SC) to make use of this class. This class handles the execution and termination of the tongsengmod application behind the scenes, so all you need to do is to compile and install it once:
* Make sure you have Apple Developer Tools installed.
* Download tongsengmod source from: http://github.com/batuhan/tongsengmod (or download via git://github.com/batuhan/tongsengmod.git ).
* Extract the source archive (for example, to the desktop).
* From terminal:
$ cd ~/Desktop
$ cd <extracted folder name>
$ make
$ sudo make install
Tested on Leopard only so far.
Creation / Class Methods
*start
Starts the tongsengmod client and registers the responder to receive multitouch messages.
*stop
Terminates the tongsengmod client and unregisters the responder.
*setDevice(argDevice)
argDevice is \internal for internal trackpad (default) and \external for external trackpad.
*gui
A simple GUI to see if things are working fine.
MultiTouchPad.start;
MultiTouchPad.gui;
MultiTouchPad.stop; //don't forget to stop
Accessing Instance and Class Variables
touchAction
A function to be executed when a new finger touch is detected. The function is passed in two arguments: curID and xys. curID is a unique integer for the lifetime of a finger on the touchpad. xys is an array with three elements: [x position, y position, blob size]
MultiTouchPad.start;
MultiTouchPad.resetActions;
MultiTouchPad.touchAction = {|curID, xys| curID.postln; xys.postln; };
MultiTouchPad.stop; //don't forget to stop
untouchAction
A function to be executed when a finger leaves the touchpad. The function is passed in the ID of the raised finger that was previously registered with touchAction.
MultiTouchPad.start;
MultiTouchPad.resetActions;
MultiTouchPad.untouchAction = {|curID| curID.postln; };
MultiTouchPad.stop; //don't forget to stop
setAction
A function to be executed when fingers move on the touchpad surface. The function is passed in two arguments: curID and xys. curID is a unique integer for the lifetime of a finger on the touchpad. xys is an array with three elements: [x position, y position, blob size]
MultiTouchPad.start;
MultiTouchPad.resetActions;
MultiTouchPad.setAction = {|curID, xys| curID.postln; xys.postln; };
MultiTouchPad.stop; //don't forget to stop
resetAction
Resets all actions to empty functions. Handy to make sure all actions are cleared as you can't create new instances of this class.
An Example:
(
SynthDef(\mtFun,
{
arg impulseFreq, oscFreq, mul, pan, distort, decay;
var trig = Impulse.ar(impulseFreq);
var snd = SinOsc.ar(oscFreq, 0, Decay2.ar(trig, 0.01, 0.2 * decay));
Out.ar(0, Pan2.ar((tanh(snd * distort) / distort) * mul.lag(0.1), pan.lag(0.1)));
}).memStore;
)
(
var sDict = Dictionary.new;
MultiTouchPad.resetActions.start;
MultiTouchPad.touchAction =
{|curID, xys|
sDict.put(curID, Synth(\mtFun,
[
\impulseFreq, [1,2,3,4,6,8,9].choose,
\oscFreq, rrand(80, 880),
\mul, 1 - xys[1],
\pan, (xys[0] * 2) - 1,
\distort, xys[2] * 8,
\decay, xys[2]
])
);
};
MultiTouchPad.untouchAction =
{|curID|
sDict.at(curID).free;
sDict.removeAt(curID);
};
MultiTouchPad.setAction =
{|curID, xys|
sDict.at(curID).set
(
\mul, 1 - xys[1],
\pan, (xys[0] * 2) - 1,
\distort, xys[2] * 8,
\decay, xys[2]
);
};
MultiTouchPad.gui;
)
MultiTouchPad.stop;