Mercurial > hg > beaglert
comparison resources/osc/node_modules/osc-min/examples/osc-float-to-int.coffee @ 271:fb9c28a4676b prerelease
Added osc example project and node script for testing
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 16:01:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
270:de37582ce6f3 | 271:fb9c28a4676b |
---|---|
1 # This listens for osc messages and rebroadcasts them | |
2 # with all the floats converted to ints. | |
3 | |
4 osc = require 'osc-min' | |
5 udp = require "dgram" | |
6 | |
7 if process.argv[2]? | |
8 inport = parseInt process.argv[2] | |
9 else | |
10 inport = 41234 | |
11 | |
12 if process.argv[3]? | |
13 outport = parseInt process.argv[3] | |
14 else | |
15 outport = 41235 | |
16 | |
17 float_to_int = (message) -> | |
18 for arg in message.args | |
19 if arg.type is "float" | |
20 arg.type = "integer" | |
21 message | |
22 | |
23 sock = udp.createSocket "udp4", (msg, rinfo) -> | |
24 try | |
25 edited = osc.applyMessageTransform msg, (message) -> float_to_int message | |
26 sock.send( | |
27 edited, | |
28 0, | |
29 edited.length, | |
30 outport, | |
31 "localhost" | |
32 ) | |
33 catch error | |
34 console.log "error redirecting: " + error | |
35 sock.bind inport | |
36 | |
37 console.log "OSC redirecter running at http://localhost:" + inport | |
38 console.log "translating messages to http://localhost:" + outport |