Loading...
Logo
Processing Forum
Hello,

This page provides Java classes to receive Magic Trackpad's data within a Java program under MacOS X. Would it require much work to adapt it to Processing (maybe as a library) ?

Thank you in advance.

Amundsen

Replies(6)

hi, this looked interesting so i gave it a try. i had tried  tongseng (a  TUIO wrapper for Mac OS X multitouch events for the touchpad) together with the tuio library before, but having it wrapped into a java library seems to make things easier. so here is what i did:

1) download GlulogicMT.jar and libGlulogicMT.jnilib from kenai.com/projects/macmultitouch/downloads (comes in a tar.gz file)
2) create a new processing sketch, save it, navigate to the folder i just saved the sketch to and create a subfolder code
3) copy GlulogicMT.jar and libGlulogicMT.jnilib into folder code
3.1) if you want to use GlulogicMT as a library located inside the libraries folder, create the following folder structure and place folder GlulogicMT inside the libraries folder instead of using the code folder
GlulogicMT
      library
            GlulogicMT.jar
            libGlulogicMT.jnilib
4) make example  SwingTest.java processing-compatible
5) the resulting sketch-code:

Copy code
  1. import com.alderstone.multitouch.mac.touchpad.*;

  2. Touchpad touchpad;

  3. void setup() {
  4.   size(800,600);
  5.   touchpad = new Touchpad(width,height);
  6.   noStroke();
  7.   smooth();
  8. }

  9. void draw() {
  10.   background(0);
  11.   touchpad.draw();
  12. }



  13. class Touchpad implements Observer {
  14.   
  15.   private static final int MAX_FINGER_BLOBS = 20;

  16.   private int width, height;
  17.   
  18.   TouchpadObservable tpo;
  19.   
  20.   Finger blobs[] = new Finger[MAX_FINGER_BLOBS];

  21.   public Touchpad(int width, int height) {
  22.     this.width = width;
  23.     this.height=height;
  24.     tpo = TouchpadObservable.getInstance();
  25.     tpo.addObserver(this);
  26.   }

  27.   // Multitouch update event 
  28.   public void update( Observable obj, Object arg ) {
  29.     // The event 'arg' is of type: com.alderstone.multitouch.mac.touchpad.Finger
  30.     Finger f = (Finger) arg;
  31.     int id = f.getID();
  32.     if (id <= MAX_FINGER_BLOBS)
  33.       blobs[id-1]= f;
  34.   }

  35.   public void update() {}

  36.   public void draw() {

  37.     for (int i=0; i<MAX_FINGER_BLOBS;i++) {
  38.       Finger f = blobs[i];
  39.       if (f != null && f.getState() == FingerState.PRESSED) {

  40.         int x     = (int) (width  * (f.getX()));
  41.         int y     = (int) (height * (1-f.getY()));
  42.         int xsize = (int) (10*f.getSize() * (f.getMajorAxis()/2));
  43.         int ysize = (int) (10*f.getSize() * (f.getMinorAxis()/2));
  44.         int ang   = f.getAngle();

  45.         
  46.         pushMatrix();
  47.         translate(x-xsize/2, y-ysize/2);
  48.         pushMatrix();
  49.         rotate(radians(-ang));  // convert degrees to radians
  50.         fill(255);
  51.         ellipse(0,0,xsize,ysize);
  52.         popMatrix();
  53.         fill(255,0,0);
  54.         text(""+i,0,0);
  55.         popMatrix();
  56.       }
  57.     }
  58.   }
  59. }
This is great. 

I guess the next logical question would be how to disable OSX gestures while playing with the gestures of a sketch.

Any thoughts?
Aren't these gestures disabled when Processing is the front application ?

Otherwise I think there are applications which can change functions of gestures and probably disable them.

Maybe this one ? http://mac.softpedia.com/get/System-Utilities/BetterTouchTool.shtml
Thanks Andreas, this is very useful! 

Following your instructions, it works with my internal MBP trackpad, but it doesn't work with the external Magic Trackpad. Is it possible to enable all connected trackpads or to target a specific device? 
The kenai.com link seems to be broken - at least I can't seem to connect,

At any rate, the  GlulogicMT.jar and libGlulogicMT.jnilib files can be downloaded from:


There's a bunch of other stuff in the download, and you'll have to dig the required files out, but once you arrange per andreas's instructions, everything works fine (at least for me).