From f49c5866bf8deb5214fa05b281f05c6f76578613 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 26 Oct 2009 01:43:24 +0000 Subject: made API super simple, added [info( message, made proper help patch, and made it build from iPhoneOS svn path=/trunk/externals/apple/; revision=12676 --- Makefile | 3 +- multitouch-help.pd | 90 ++++++++++++++++++++++++++++++++++++++++++++++-------- multitouch.c | 52 +++++++++++++++---------------- 3 files changed, 103 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index a58276d..be33ef8 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ SOURCES = # For objects that only build on certain platforms, add those to the SOURCES # line for the right platforms. SOURCES_Darwin = ambient_light_sensor.c iodisplay.c keyboard_light.c sudden_motion_sensor.c smc.c multitouch.c +SOURCES_iphoneos = multitouch.c SOURCES_Linux = SOURCES_Windows = @@ -33,7 +34,7 @@ ifeq ($(UNAME),Darwin) ifeq ($(CPU),arm) # iPhone/iPod Touch # install Headers first: # http://iphonesdkdev.blogspot.com/2008/08/how-to-copy-sdk-headers-to-iphone-and.html - SOURCES += $(SOURCES_Darwin) + SOURCES += $(SOURCES_iphoneos) EXTENSION = pd_darwin OS = iphoneos IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin diff --git a/multitouch-help.pd b/multitouch-help.pd index 0745a85..1732f2f 100644 --- a/multitouch-help.pd +++ b/multitouch-help.pd @@ -1,13 +1,77 @@ -#N canvas 236 102 450 300 10; -#X obj 153 120 multitouch; -#X msg 162 52 bang; -#X obj 170 98 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 -1; -#X obj 142 153 print DATA; -#X obj 216 153 print STATUS; -#X msg 199 83 info; -#X connect 0 0 3 0; -#X connect 0 1 4 0; -#X connect 1 0 0 0; -#X connect 2 0 0 0; -#X connect 5 0 0 0; +#N canvas 147 22 562 447 10; +#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header multitouch 3 12 +0 18 -241536 -1 0; +#X obj 3 220 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlet 15 12 0 13 +-245500 -191407 0; +#N canvas 779 22 494 344 META 0; +#X text 12 25 KEYWORDS control number float store; +#X text 12 45 LICENSE GPL; +#X text 12 65 TEMPLATE template-help.pd v0.1; +#X text 12 85 PLATFORM windows macosx gnulinux; +#X text 12 105 DATATYPE float list; +#X text 12 125 LIBRARY internal; +#X text 12 145 WEBSITE http://crca.ucsd.edu/~msp/; +#X text 12 165 RELEASE_DATE 2007-08-24; +#X text 12 185 RELEASE_VERSION 0.40-test05; +#X text 12 5 GENRE storage; +#X restore 500 404 pd META; +#X obj 3 289 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 15 12 0 +13 -245500 -191407 0; +#X obj 3 369 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15 +12 0 13 -245500 -191407 0; +#X obj 434 6 pddp/pddplink http://wiki.puredata.info/en/apple/multitouch +-text pdpedia: multitouch; +#X obj 449 -14 apple/multitouch; +#X obj 146 101 multitouch; +#X msg 146 48 bang; +#X msg 179 73 info; +#X obj 203 120 pddp/print; +#X text 216 73 output info on right outlet; +#X obj 73 73 metro 250; +#X obj 73 54 tgl 15 0 empty empty empty 0 -6 0 10 -204786 -1 -1 0 1 +; +#X text 183 46 output sensor values; +#X text 102 258 "info" - outputs info about the sensor on the right +outlet; +#X obj 72 336 cnv 17 3 20 empty \$0-pddp.cnv.let.1 1 5 9 0 16 -228856 +-162280 0; +#X obj 72 310 cnv 17 3 20 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +-162280 0; +#X text 15 6 description: get multitouches from trackpads and iPhones +; +#X text 102 239 bang - output current multitouch data; +#X text 103 337 a message with info about the sensor status; +#X text 103 311 a list of values for each touch that is being tracked +; +#X obj 104 395 pddp/pddplink http://steike.com/code/multitouch/; +#X floatatom 6 179 5 0 0 3 finger - -; +#X floatatom 45 179 5 0 0 3 frame - -; +#X floatatom 81 179 5 0 0 3 angle - -; +#X floatatom 120 179 5 0 0 3 majorAxis - -; +#X floatatom 178 179 5 0 0 3 minorAxis - -; +#X obj 146 145 unpack 0 0 0 0 0 0 0 0 0 0 0 0; +#X floatatom 236 179 5 0 0 3 x - -; +#X floatatom 274 179 5 0 0 3 y - -; +#X floatatom 307 179 5 0 0 3 x-velocity - -; +#X floatatom 368 179 5 0 0 3 Y-velocity - -; +#X floatatom 431 179 5 0 0 3 ID - -; +#X floatatom 469 179 5 0 0 3 state - -; +#X floatatom 509 179 5 0 0 3 size - -; +#X connect 7 0 28 0; +#X connect 7 1 10 0; +#X connect 8 0 7 0; +#X connect 9 0 7 0; +#X connect 12 0 7 0; +#X connect 13 0 12 0; +#X connect 28 0 23 0; +#X connect 28 1 24 0; +#X connect 28 2 25 0; +#X connect 28 3 26 0; +#X connect 28 4 27 0; +#X connect 28 5 29 0; +#X connect 28 6 30 0; +#X connect 28 7 31 0; +#X connect 28 8 32 0; +#X connect 28 9 33 0; +#X connect 28 10 34 0; +#X connect 28 11 35 0; diff --git a/multitouch.c b/multitouch.c index 0b9b0a7..0d2f3bf 100644 --- a/multitouch.c +++ b/multitouch.c @@ -33,8 +33,8 @@ #include "MultitouchSupport.h" #include -//#define DEBUG(x) -#define DEBUG(x) x +#define DEBUG(x) +//#define DEBUG(x) x /*------------------------------------------------------------------------------ * CLASS DEF @@ -51,7 +51,7 @@ typedef struct _multitouch { static MTDeviceRef dev; /* reference to the trackpad */ static int fingerc; /* current count of Fingers */ static Finger fingerv[32]; /* current list of Fingers */ -static int polling = 0; /* set when one instance is polling so others don't */ +static int multitouch_instances = 0; /* set when one instance is polling so others don't */ /*------------------------------------------------------------------------------ * CALLBACK TO GET DATA @@ -92,36 +92,24 @@ static void multitouch_output(t_multitouch* x) } } - -static void multitouch_float(t_multitouch* x, t_float f) +static void multitouch_info(t_multitouch* x) { - DEBUG(post("multitouch_float");); - if (f > 0) { - polling++; - /* if I am the first instance to poll, then set the callback up */ - if (polling == 1) { - dev = MTDeviceCreateDefault(); - MTRegisterContactFrameCallback(dev, callback); - MTDeviceStart(dev, 0); - } - } else { - polling--; - /* if I am the last instance, clean up the callback stuff */ - if (polling == 0) { - MTDeviceStop(dev); - MTUnregisterContactFrameCallback(dev, callback); - MTDeviceRelease(dev); - dev = NULL; - } - } + t_atom output_atom; + SETFLOAT(&output_atom, fingerc); + outlet_anything(x->status_outlet, gensym("fingers"), 1, &output_atom); } - static void multitouch_free(t_multitouch* x) { DEBUG(post("multitouch_free");); - /* make sure callback is released before deleting the object */ - multitouch_float(x, 0); + multitouch_instances--; + /* if I am the last instance, clean up the callback stuff */ + if (multitouch_instances == 0) { + MTDeviceStop(dev); + MTUnregisterContactFrameCallback(dev, callback); + MTDeviceRelease(dev); + dev = NULL; + } } static void *multitouch_new(void) @@ -129,6 +117,14 @@ static void *multitouch_new(void) DEBUG(post("multitouch_new");); t_multitouch *x = (t_multitouch *)pd_new(multitouch_class); + multitouch_instances++; + /* if I am the first instance to poll, then set the callback up */ + if (multitouch_instances == 1) { + dev = MTDeviceCreateDefault(); + MTRegisterContactFrameCallback(dev, callback); + MTDeviceStart(dev, 0); + } + x->data_outlet = outlet_new(&x->x_obj, &s_list); x->status_outlet = outlet_new(&x->x_obj, &s_anything); @@ -145,5 +141,5 @@ void multitouch_setup(void) 0); /* add inlet datatype methods */ class_addbang(multitouch_class,(t_method) multitouch_output); - class_addfloat(multitouch_class,(t_method) multitouch_float); + class_addmethod(multitouch_class,(t_method) multitouch_info, gensym("info"), 0); } -- cgit v1.2.1