Tramontana Multitouch Event

I hope someone has experience with the Tramontana library for Processing. While normal Touch recognition seems to work well, it seems I am unable to get the values for multitouch,

All the other values are accessible, but I can only print out the ArrayList as a whole.

void onMultiTouchDownEvent(String ipAddress, ArrayList touches, int numTouches) {
  println("MultiTouchDown");
  println(ipAddress);
  println(numTouches);
  println(touches);

  println(touches.get(0));
  
  println(touches.get(0).x);
  
  TVector [] tva;
  tva = touches.toArray();
}

the source code shows, that the TVector class has the fields x Andy, yet I cannot access them.

package tramontana.library;

public class TVector{
	public int x;
	public int y;
	public TVector(int x, int y)
	{
		this.x=x;
		this.y=y;
	}	
}

in the Tramontana.java file a new ArrayList of TVectors is created:

workingArray = new ArrayList();

yet, I can add a tvector to the array, but cannot get one out of the list.
processing tells me that java.langObject[] does not match with tramontana.library,TVector[]

Has anyone ever successfully used Multitouch from the Tramontana library and can give me some directions ?

1 Like

Interesting. I’m installing for the first time. You didn’t mention the device on which you run though.

Hello, we got help from the guys who developed it. Happy to share:
The coordinates can be obtained by using:

touchedDrag.x =((TVector)touches.get(0)).x;

(Where touchedDrag is a PVector made by myself.)

2 Likes

Could you post a small working sketch?

Hello, it is not too small, because I included touch, touchdown and touch drag into it.
Also I have noticed that drag events stop when you reduce the number of fingers while dragging.
In addition, updating the values from Tramontana can sometimes overrule what you draw in the middle of the drawing - when the number of touches changes.
So I have tried to comment the code extensively to explain what I did and why…

Hope it works for you…

/****
 Tramontana Multitouch Example for Processing - adapted by Thomas Lorenz - www.ambientartlab.at
 Tramontana is a tool for interactive spaces. It communicates with iOS devices. 
 You can download the app here: https://itunes.apple.com/us/app/tramontana/id1121069555?mt=8
 made by Pierluigi Dalla Rosa
 ***/

import tramontana.library.*;
import websockets.*;
Tramontana t;
FloatList touchedDownX, touchedDownY; //--- storing the values that come from Tramontana here
FloatList touchedX, touchedY;
FloatList touchedDragX, touchedDragY;
int rDeviceW, rDeviceH; //-------------- dimensions of the remote input device
int rDeviceLeft, rDeviceTop; //--------- so we can calibrate the incoming coordinates to the sketch size
String deviceIP; //--------------------- the IP Adress of the remote device
//---------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------- SETUP
void setup() {
  size (720, 1280, P2D);
  noStroke();
  fill(0);
  //------------------ put the dimensions of the input device here, so it can be mapped onto the sketch size
  //------------------ it is also useful for dealing with the edges of the device, if the finger does not completely reach it
  //------------------ if we get only 5 as the lowest value on the left side, rDeviceLeft could be set to 5
  rDeviceLeft = 0;
  rDeviceW = 1080;
  rDeviceTop = 0;
  rDeviceH = 1920;
  //------------------ write the IP the App on your device tells you here
  deviceIP = "192.168.0.17";
  //------------------------------------------
  t = new Tramontana(this, deviceIP);
  //------------------ subscribe to the tramontana server on your device
  //------------------ in the case of multitouch there has to be (true) in the brackets
  t.subscribeTouch(true);
  t.subscribeTouchDrag(true);
  //------------------ initialize the lists for the different coordinates
  //------------------ could probably be an Array List or an Array of PVectors too
  //------------------ being lazy i used FloatLists :-)
  touchedDownX = new FloatList();
  touchedDownY = new FloatList();
  touchedX = new FloatList();
  touchedY = new FloatList();
  touchedDragX = new FloatList();
  touchedDragY = new FloatList();
}
//--------------------------------------------------------------------------------------------------- 
//---------------------------------------------------------------------------------------------- DRAW
void draw() {
  background(255);
  //------------------ draw something on Touch 
  //------------------ for the time being it seems that the Events from Tramontana can sometimes overtake the content (and size) of the coordinates in the list
  //------------------ sometimes if there are 3 touches on the display and we lift a finger, the numbers do not fit, resulting in an error
  //------------------ these are filtered out by the (ugly) usage of try/catch
  //------------------ seemingly - for the same reason - dragging keeps working when more touches are added, but stops when the number of fingers on the display becomes lower
  if (touchedX.size()>0) {
    for (int i = 0; i < touchedX.size(); i++) {
      try {
        drawOnTouch(touchedX.get(i), touchedY.get(i));
      } 
      catch (Exception e) {
        println("The number of items in the List did not match the number of Touches");
      }
    }
  }
  //------------------ draw something on Drag 
  if (touchedDragX.size()>0) {
    for (int i = 0; i < touchedDragX.size(); i++) {
      try {
        drawOnDrag(touchedDragX.get(i), touchedDragY.get(i));
      } 
      catch (Exception e) {
        println("The number of items in the List did not match the number of Touches");
      }
    }
  }
  //------------------ draw something on TouchDown 
  if (touchedDownX.size()>0) {
    //println (touchedX.size());
    for (int i = 0; i < touchedX.size(); i++) {
      try {
        drawOnTouchdown(touchedDownX.get(i), touchedDownY.get(i));
      } 
      catch (Exception e) {
        println("The number of items in the List did not match the number of Touches");
      }
    }
  }
}
//----------------------------------------------------------------------------------------------  DRAWING METHODS
void drawOnDrag(float mx, float my) { //------------------ used to map the coordinates and then draw
  mx = map(mx, rDeviceLeft, rDeviceW, 0, width);
  my = map(my, rDeviceTop, rDeviceH, 0, height);
  fill(255, 0, 255);
  circle(mx, my, 20);
}
void drawOnTouch(float mx, float my) 
{
  mx = map(mx, rDeviceLeft, rDeviceW, 0, width);
  my = map(my, rDeviceTop, rDeviceH, 0, height);
  fill(255, 255, 0);
  circle(mx, my, 30);
}
void drawOnTouchdown(float mx, float my)
{
  mx = map(mx, rDeviceLeft, rDeviceW, 0, width);
  my = map(my, rDeviceTop, rDeviceH, 0, height);
  fill(255, 0, 0);
  circle(mx, my, 20);
}

//----------------------------------------------------------------------------------------------  TRAMONTANA EVENTS
//--------------------------------------------------------aequivalent to mousePressed
void onMultiTouchDownEvent(String ipAddress, ArrayList touches, int numTouches) //touchdown is triggered ONLY when touching
{
  touchedDownX.clear();
  touchedDownY.clear();
  for (int i = 0; i < numTouches; i++) {
    touchedDownX.append(((TVector)touches.get(i)).x);
    touchedDownY.append(((TVector)touches.get(i)).y);
  }
}
//--------------------------------------------------------aequivalent to mouseReleased
void onMultiTouchEvent(String ipAddress, ArrayList touches, int numTouches) //touch is triggered when touching AND releasing 
{
  touchedX.clear();
  touchedY.clear();
  for (int i = 0; i < numTouches; i++) {
    touchedX.append(((TVector)touches.get(i)).x);
    touchedY.append(((TVector)touches.get(i)).y);
  }
  println("Touch!");
}
//--------------------------------------------------------aequivalent to mouseDrag
void onMultiTouchDragEvent(String ipAddress, ArrayList touches, int numTouches) //touchDrag is triggered when dragging
{
  touchedDragX.clear();
  touchedDragY.clear();
  for (int i = 0; i < numTouches; i++) {
    touchedDragX.append(((TVector)touches.get(i)).x);
    touchedDragY.append(((TVector)touches.get(i)).y);
  }
  println(touchedDragX);
  println("Drag!");
}

2 Likes

Thanks for sharing…