comparison resources/osc/node_modules/osc-min/examples/osc-float-to-int.coffee @ 284:7bfb25a2e158 Doxy prerelease

Merge
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 15:53:24 +0100
parents fb9c28a4676b
children
comparison
equal deleted inserted replaced
269:ac8eb07afcf5 284:7bfb25a2e158
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