Mercurial > hg > beaglert
annotate resources/osc/node_modules/osc-min/examples/osc-float-to-int.js @ 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 // Generated by CoffeeScript 1.10.0 |
l@271 | 2 var float_to_int, inport, osc, outport, sock, udp; |
l@271 | 3 |
l@271 | 4 osc = require('osc-min'); |
l@271 | 5 |
l@271 | 6 udp = require("dgram"); |
l@271 | 7 |
l@271 | 8 if (process.argv[2] != null) { |
l@271 | 9 inport = parseInt(process.argv[2]); |
l@271 | 10 } else { |
l@271 | 11 inport = 41234; |
l@271 | 12 } |
l@271 | 13 |
l@271 | 14 if (process.argv[3] != null) { |
l@271 | 15 outport = parseInt(process.argv[3]); |
l@271 | 16 } else { |
l@271 | 17 outport = 41235; |
l@271 | 18 } |
l@271 | 19 |
l@271 | 20 float_to_int = function(message) { |
l@271 | 21 var arg, i, len, ref; |
l@271 | 22 ref = message.args; |
l@271 | 23 for (i = 0, len = ref.length; i < len; i++) { |
l@271 | 24 arg = ref[i]; |
l@271 | 25 if (arg.type === "float") { |
l@271 | 26 arg.type = "integer"; |
l@271 | 27 } |
l@271 | 28 } |
l@271 | 29 return message; |
l@271 | 30 }; |
l@271 | 31 |
l@271 | 32 sock = udp.createSocket("udp4", function(msg, rinfo) { |
l@271 | 33 var edited, error, error1; |
l@271 | 34 try { |
l@271 | 35 edited = osc.applyMessageTransform(msg, function(message) { |
l@271 | 36 return float_to_int(message); |
l@271 | 37 }); |
l@271 | 38 return sock.send(edited, 0, edited.length, outport, "localhost"); |
l@271 | 39 } catch (error1) { |
l@271 | 40 error = error1; |
l@271 | 41 return console.log("error redirecting: " + error); |
l@271 | 42 } |
l@271 | 43 }); |
l@271 | 44 |
l@271 | 45 sock.bind(inport); |
l@271 | 46 |
l@271 | 47 console.log("OSC redirecter running at http://localhost:" + inport); |
l@271 | 48 |
l@271 | 49 console.log("translating messages to http://localhost:" + outport); |