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