Pressure / Force

Howdy everyone,

Hope everyone had a great Christmas and New Years. I was reading the latest update documentation (man, I love how the latest version is looking) and then got very interested in force/pressure.

Can someone explain to me how this works? I mean, if using an iPad and an Apple Pencil, the pressure is measured through the Pencil. So, to use Pressure, is this only applicable for screens that support force? I'm just curious about how this works with OSC.

I'm incredibly interested in this because imagine having a pressure sensitive keyboard so you can suddenly implement Aftertouch. Or 5D Touch meaning we can suddenly have "lift" as a way of inputting data to create performance based instruments.

Very excited. I apologise for ignorance on such matters. Never in my life did I think this could even be a possibility!


Pressure will indeed work only on devices/screens that supports it (I guess most smartphones and tablets do, not sure about desktop touchscreens). The pressure information can only be used with a canvas widget, there's no predefined usage for it in o-s-c, it's up to you to be creative with it :).

Here is a simple example to test it: create a canvas widget with the following touch script and draw script:

// touch
locals.pressure = event.force

if (event.type == 'start') {
  locals.touched = true
} else if (event.type == 'stop') {
  locals.touched = false
  locals.pressure = 0
// draw
var radius = 10 + (width / 2 - 10) * locals.pressure

ctx.arc(width / 2, height / 2, radius, 0, Math.PI * 2)
ctx.fillStyle = cssVars.colorFill

If pressure is supported, you'll get a circle which size depends on how much pressure you put you the widget when touching it.

Ok man, its as I thought. Hmmm, I wish all desktop touch screens supported this. It would be massive.

By the way, loving the Canvas widget. It really is a game changer especially for performance. Thanks so much for implementing that!

Wow, this is amazing !
(I've been waiting and requesting for such a thing in Lemur / touchOSC / Max Mira, ...)
Finally I can use the Apple Pencil pressure to send OSC :grinning: :smiley: :hugs:
Once again, thank you very much Jean-Emmanuel !!

Would you mind adding azimuth angle / tilt , please ?

or PointerEvent.tiltX
(+ tiltY / twist / ...)

PointerEvent.pointerType may be useful as well... to know if the pointer us a touch, a stylus, etc... ?

So many exiting things to explore with this new input :slight_smile:

On iPad, look like when Apple Pencil is used, the touch events are ignored...
is it a setting we could change ? or an iOS limitation ?
I'm pretty sure that there are apps that can use simultaneously pencil + touch...

One more thing :
on iOS devices, touch radius ( radiusX ?) should also be accessible.
I remmener a couple of years ago, developers had to use a forbidden private api to access these data (some apps had some hidden parameters to enable it..) ; then it became officially supported, but with a very low resolution. (Orphion app uses this feature)
Anyway, I guess it would worth giving it a try :wink:



I'm adding these properties in next version, except those tied to the PointerEvent API that would require a partial rewrite of o-s-c touch event implementation.

great !
looking forward exploring these exiting new features :smiley:

touch script seem to be triggered only when cursors is added/removed or moves (X/Y)
So force/pressure is only sent / drawn when x or y value change.
(if the stylus stays at same position, pressure is not updated.)

Can't find a way to trigger a script when any value changes (force, azimuthAngle, altitudeAngle, ...)

is it possible ?
canvas_x_y_force.json (6.0 KB)

I think we already had that conversation : About new canvas touch events (force, radiusX, …) - #3 by jean-emmanuel (not that I'm againt it,I just didn't make any progress on it).

oups sorry, I just forgot I already reported this :flushed:

I'm only starting to use iPad stylus in a 'real' project right now ..
It's really really fun, adds another level of expressiveness. I love it.
But for now, as soon as I map pressure or tilt to some real-time synth parameters (gain, pitch, ..), this limitation is a showstopper :-s

Could you try v1.17.1-beta0 ? It's kind of a shot in the dark here but it might work.

Edit: I just realized there's a mistake in my code, wait for beta1 please...

Edit2: beta2 should be available soon here

Sorry for late reply !
just seen the changeling for v1.18.0

  • canvas: iOS: trigger onTouch when event.force, event.altitudeAngle or event.azimuthAngle updates

great news !
but it doesn't seem to work here..
is there something I missed in order to enable this ?
I added updateCanvas() in my onTouch script, but it doesn't work.
Only x | y update the script.

I have this error message in O-S-C console when opening canvas_x_y_force.json

(ERROR, CLIENT) TypeError: undefined is not an object (evaluating 'this.iosTouchCache[e.pointerId][t]')
at setInterval( (src/client/widgets/pads/canvas.js:136:73)

updateCanvas() is not related to this, it just forces a new draw.

As I said I can't test this myself so it might take some time before I get it right, i'll see what I can do based on this error.

Thanks for trying !
in case it can help, I also get this one :

(ERROR, CLIENT) TypeError: undefined is not an object (evaluating 'this.iosTouchCache[e.pointerId]')
at setInterval( (src/client/widgets/pads/canvas.js:136:60)
As these error messages are returned on each frame.. my sessions that contains this kind of script run veeeeery sloowwwly with 1.18.0 :frowning:

v1.18.1 is uploading, let me know how it behaves

thanks for your reactivity !

error messages are gone.. but still no script trigger on event.force , event.altitudeAngle or event.azimuthAngle updates :frowning:

(I noticed that I have to close / reopen | refresh the page on iOS / safari when I change O-S-C server version ; I guess the client needs to reload the new version)


Just to be sure : it's the onTouch script that's supposed to be called when these property update.

From the onTouch script I can update the value, send an osc message, or redraw the canvas ;
so yes, I think so.