Permalink
Browse files

Switched to auto-generating JS examples. adds ugly semicolons that ne…

…ed hand editing.
  • Loading branch information...
1 parent c57190e commit c5de68e3c85c1056a7bcab6557f22f5b93015801 @russellmcc committed Feb 20, 2013
View
@@ -19,5 +19,6 @@ task 'coverage', 'run tests with coverage check (requires development install)',
child.exec "rm -rf lib-cov " + output
task 'doc', 'create md and html doc files', (options) ->
- child.exec 'docket lib/* examples/* -m'
- child.exec 'docket lib/* examples/* -d doc_html'
+ child.exec 'coffee -b -c examples/*', ->
+ child.exec 'docket lib/* examples/* -m', ->
+ child.exec 'docket lib/* examples/* -d doc_html'
@@ -1,47 +0,0 @@
-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,6 +18,10 @@ 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
@@ -1,37 +0,0 @@
-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);
@@ -1,42 +0,0 @@
-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,6 +12,10 @@ 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
@@ -1,33 +0,0 @@
-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,6 +8,8 @@ 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
@@ -1,25 +0,0 @@
-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
@@ -39,50 +39,58 @@ npm run-script coverage
----
## Examples
-### A simple OSC printer
+### A simple OSC printer;
```javascript
+
+
sock = udp.createSocket("udp4", function(msg, rinfo) {
- try {
- return console.log(osc.fromBuffer(msg));
- } catch (error) {
- return console.log("invalid OSC packet");
- }
+ 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
```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");
+ 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);
```
### A simple OSC redirecter
```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);
- }
+ 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 c5de68e

Please sign in to comment.