annotate 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
rev   line source
l@271 1 # This listens for osc messages and rebroadcasts them
l@271 2 # with all the floats converted to ints.
l@271 3
l@271 4 osc = require 'osc-min'
l@271 5 udp = require "dgram"
l@271 6
l@271 7 if process.argv[2]?
l@271 8 inport = parseInt process.argv[2]
l@271 9 else
l@271 10 inport = 41234
l@271 11
l@271 12 if process.argv[3]?
l@271 13 outport = parseInt process.argv[3]
l@271 14 else
l@271 15 outport = 41235
l@271 16
l@271 17 float_to_int = (message) ->
l@271 18 for arg in message.args
l@271 19 if arg.type is "float"
l@271 20 arg.type = "integer"
l@271 21 message
l@271 22
l@271 23 sock = udp.createSocket "udp4", (msg, rinfo) ->
l@271 24 try
l@271 25 edited = osc.applyMessageTransform msg, (message) -> float_to_int message
l@271 26 sock.send(
l@271 27 edited,
l@271 28 0,
l@271 29 edited.length,
l@271 30 outport,
l@271 31 "localhost"
l@271 32 )
l@271 33 catch error
l@271 34 console.log "error redirecting: " + error
l@271 35 sock.bind inport
l@271 36
l@271 37 console.log "OSC redirecter running at http://localhost:" + inport
l@271 38 console.log "translating messages to http://localhost:" + outport