Permalink
Browse files

switched examples to javascript as they were confusing users.

  • Loading branch information...
1 parent bb02f2d commit c57190e229a3f9f142cd2c0221d6515bee84b11a @russellmcc committed Feb 20, 2013
@@ -0,0 +1,47 @@
+var float_to_int, inport, osc, outport, sock, udp;
+
+osc = require('osc-min');
+
+udp = require("dgram");
+
+if (process.argv[2] != null) {
+ inport = parseInt(process.argv[2]);
+} else {
+ inport = 41234;
+}
+
+if (process.argv[3] != null) {
+ outport = parseInt(process.argv[3]);
+} else {
+ outport = 41235;
+}
+
+float_to_int = function(message) {
+ var arg, _i, _len, _ref;
+ _ref = message.args;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ arg = _ref[_i];
+ if (arg.type === "float") {
+ arg.type = "integer";
+ }
+ }
+ return message;
+};
+
+sock = udp.createSocket("udp4", function(msg, rinfo) {
+ var edited;
+ try {
+ edited = osc.applyMessageTransform(msg, function(message) {
+ return float_to_int(message);
+ });
+ return sock.send(edited, 0, edited.length, outport, "localhost");
+ } catch (error) {
+ return console.log("error redirecting: " + error);
+ }
+});
+
+sock.bind(inport);
+
+console.log("OSC redirecter running at http://localhost:" + inport);
+
+console.log("translating messages to http://localhost:" + outport);
@@ -18,8 +18,6 @@ else
console.log "OSC redirecter running at http://localhost:" + inport
console.log "redirecting messages to http://localhost:" + outport
-#~verbatim:examples[2]~
-#### A simple OSC redirecter
sock = udp.createSocket "udp4", (msg, rinfo) ->
try
redirected = osc.applyAddressTransform msg, (address) -> "/redirect" + address
View
@@ -0,0 +1,37 @@
+var inport, osc, outport, sock, udp;
+
+osc = require('osc-min');
+
+udp = require("dgram");
+
+if (process.argv[2] != null) {
+ inport = parseInt(process.argv[2]);
+} else {
+ inport = 41234;
+}
+
+if (process.argv[3] != null) {
+ outport = parseInt(process.argv[3]);
+} else {
+ outport = 41235;
+}
+
+console.log("OSC redirecter running at http://localhost:" + inport);
+
+console.log("redirecting messages to http://localhost:" + outport);
+
+//~verbatim:examples[2]~
+//### A simple OSC redirecter
+sock = udp.createSocket("udp4", function(msg, rinfo) {
+ var redirected;
+ try {
+ redirected = osc.applyAddressTransform(msg, function(address) {
+ return "/redirect" + address;
+ });
+ return sock.send(redirected, 0, redirected.length, outport, "localhost");
+ } catch (error) {
+ return console.log("error redirecting: " + error);
+ }
+});
+
+sock.bind(inport);
@@ -0,0 +1,42 @@
+var dgram, osc, outport, sendHeartbeat, udp;
+
+osc = require('osc-min');
+
+dgram = require("dgram");
+
+udp = dgram.createSocket("udp4");
+
+if (process.argv[2] != null) {
+ outport = parseInt(process.argv[2]);
+} else {
+ outport = 41234;
+}
+
+sendHeartbeat = function() {
+ var buf;
+ buf = osc.toBuffer({
+ timetag: 12345,
+ elements: [
+ {
+ address: "/p1",
+ args: new Buffer("beat")
+ }, {
+ address: "/p2",
+ args: "string"
+ }, {
+ timetag: 34567,
+ elements: [
+ {
+ address: "/p3",
+ args: 12
+ }
+ ]
+ }
+ ]
+ });
+ return udp.send(buf, 0, buf.length, outport, "localhost");
+};
+
+setInterval(sendHeartbeat, 2000);
+
+console.log("sending heartbeat messages to http://localhost:" + outport);
@@ -12,8 +12,6 @@ else
outport = 41234
console.log "sending heartbeat messages to http://localhost:" + outport
-#~verbatim:examples[1]~
-#### Send a bunch of args every two seconds
sendHeartbeat = () ->
buf = osc.toBuffer(
address : "/heartbeat"
View
@@ -0,0 +1,33 @@
+var dgram, osc, outport, sendHeartbeat, udp;
+
+osc = require('osc-min');
+
+dgram = require("dgram");
+
+udp = dgram.createSocket("udp4");
+
+if (process.argv[2] != null) {
+ outport = parseInt(process.argv[2]);
+} else {
+ outport = 41234;
+}
+
+console.log("sending heartbeat messages to http://localhost:" + outport);
+
+//~verbatim:examples[1]~
+//### Send a bunch of args every two seconds
+sendHeartbeat = function() {
+ var buf;
+ buf = osc.toBuffer({
+ address: "/heartbeat",
+ args: [
+ 12, "sttttring", new Buffer("beat"), {
+ type: "integer",
+ value: 7
+ }
+ ]
+ });
+ return udp.send(buf, 0, buf.length, outport, "localhost");
+};
+
+setInterval(sendHeartbeat, 2000);
View
@@ -8,8 +8,6 @@ else
console.log "OSC listener running at http://localhost:" + inport
-#~verbatim:examples[0]~
-#### A simple OSC printer
sock = udp.createSocket "udp4", (msg, rinfo) ->
try
console.log osc.fromBuffer msg
View
@@ -0,0 +1,25 @@
+var inport, osc, sock, udp;
+
+osc = require('osc-min');
+
+udp = require("dgram");
+
+if (process.argv[2] != null) {
+ inport = parseInt(process.argv[2]);
+} else {
+ inport = 41234;
+}
+
+console.log("OSC listener running at http://localhost:" + inport);
+
+//~verbatim:examples[0]~
+//### A simple OSC printer
+sock = udp.createSocket("udp4", function(msg, rinfo) {
+ try {
+ return console.log(osc.fromBuffer(msg));
+ } catch (error) {
+ return console.log("invalid OSC packet");
+ }
+});
+
+sock.bind(inport);
View
@@ -1,6 +1,7 @@
(function() {
//~readme.out~
+//[![build status](https://secure.travis-ci.org/russellmcc/node-osc-min.png)](http://travis-ci.org/russellmcc/node-osc-min)
//# osc-min
//
// _simple utilities for open sound control in node.js_
View
@@ -1,6 +1,6 @@
{
"name": "osc-min",
- "version": "0.0.8",
+ "version": "0.0.9",
"main": "lib/index",
"author": {
"name": "Russell McClellan",
View
@@ -40,47 +40,53 @@ npm run-script coverage
----
## Examples
### A simple OSC printer
-```coffee-script
-sock = udp.createSocket "udp4", (msg, rinfo) ->
- try
- console.log osc.fromBuffer msg
- catch error
- console.log "invalid OSC packet"
-sock.bind inport
+```javascript
+sock = udp.createSocket("udp4", function(msg, rinfo) {
+ try {
+ return console.log(osc.fromBuffer(msg));
+ } catch (error) {
+ return console.log("invalid OSC packet");
+ }
+});
+
+sock.bind(inport);
```
### Send a bunch of args every two seconds
-```coffee-script
-sendHeartbeat = () ->
- buf = osc.toBuffer(
- address : "/heartbeat"
- args : [
- 12
- "sttttring"
- new Buffer "beat"
- {type : "integer", value : 7}
+```javascript
+sendHeartbeat = function() {
+ var buf;
+ buf = osc.toBuffer({
+ address: "/heartbeat",
+ args: [
+ 12, "sttttring", new Buffer("beat"), {
+ type: "integer",
+ value: 7
+ }
]
- )
+ });
+ return udp.send(buf, 0, buf.length, outport, "localhost");
+};
- udp.send buf, 0, buf.length, outport, "localhost"
+setInterval(sendHeartbeat, 2000);
-setInterval sendHeartbeat, 2000
```
### A simple OSC redirecter
-```coffee-script
-sock = udp.createSocket "udp4", (msg, rinfo) ->
- try
- redirected = osc.applyAddressTransform msg, (address) -> "/redirect" + address
- sock.send(
- redirected,
- 0,
- redirected.length,
- outport,
- "localhost"
- )
- catch error
- console.log "error redirecting: " + error
-sock.bind inport
+```javascript
+sock = udp.createSocket("udp4", function(msg, rinfo) {
+ var redirected;
+ try {
+ redirected = osc.applyAddressTransform(msg, function(address) {
+ return "/redirect" + address;
+ });
+ return sock.send(redirected, 0, redirected.length, outport, "localhost");
+ } catch (error) {
+ return console.log("error redirecting: " + error);
+ }
+});
+
+sock.bind(inport);
+
```

0 comments on commit c57190e

Please sign in to comment.