fe9lix / Tuio.js

TUIO Reference Implementation for JavaScript
GNU General Public License v2.0
95 stars 26 forks source link

Question: how to transform OSC message into TUIO message? #9

Closed hoosierEE closed 7 years ago

hoosierEE commented 8 years ago

My program is happily sending OSC messages over UDP. In JSON, my messages look like this:

{ address: "/p0", args: [0.2, 0.4, 0.5] }

What do I need to do to send this to a TUIO client?

By the way I know this isn't strictly related to Tuio.js but if I had the answer to this question then I might be able to use Tuio.js. At this point I am unable to use it or any other TUIO client implementation. :disappointed: Any help appreciated!

s-light commented 7 years ago

@hoosierEE have a look at http://www.tuio.org/?specification there the package format is explained.

hoosierEE commented 7 years ago

I ended up not being able to work around the type conversions built into TUIO.js so I used plain OSC messages instead.

For what it's worth, my issues seemed to be related to TUIO.js always outputting float values to clients which were expecting int values, or maybe it was the other way around (it's been a while).

Here's an excerpt from what I ended up using. It receives an OSC bundle, modifies it slightly, and sends it to a TUIO client:

let fseq_id=0;
let onbun=(bun)=>{

    let intify=(d)=>({type:'i',value:d}); /* force type to be 'integer' */

    /* receive from device */
    let results=bun.packets.map(message=>{
        return ({
            id: parseInt(message.address[2],10),
            values: normalize(message.args,true).slice(0,-1),
        });
    });

    /* send to client */
    osc.send({
        timeTag: osc.timeTag(0),
        packets: [
            {address:'/tuio/2Dcur',args:['alive',intify(0),intify(1)]},
            {address:'/tuio/2Dcur',args:['set',intify(0)].concat(results[0].values,1,1,1)},
            {address:'/tuio/2Dcur',args:['set',intify(1)].concat(results[1].values,1,1,1)},
            {address:'/tuio/2Dcur',args:['fseq',intify(++fseq_id)]},
        ]
    });
};
s-light commented 7 years ago

just for documentation: if you look at the Attributes Section - Table 1: semantic types of set messages in the specification - it seems only the ids are int32 type. all others are defined as float32. i have experimented with osc.js and that is exactly what i get as message content... ( sender was reactTIVision internal WebSockSender) and if i understand your example that is what you have achieved. ;-) (i only experimented with received things - so don't know how the sending and type specification is done....)