Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

osc-min

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osc-min - npm Package Compare versions

Comparing version
0.0.8
to
0.0.9
+4
.travis.yml
language: node_js
node_js:
- 0.6
- 0.8
/*--------------------- Layout and Typography ----------------------------*/
body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 15px;
line-height: 22px;
color: #252519;
margin: 0; padding: 0;
}
a {
color: #261a3b;
}
a:visited {
color: #261a3b;
}
p {
margin: 0 0 15px 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0px 0 15px 0;
}
h1 {
margin-top: 40px;
}
#container {
position: relative;
}
#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
font: 10px Arial;
text-transform: uppercase;
cursor: pointer;
text-align: right;
}
#jump_to, #jump_wrapper {
position: fixed;
right: 0; top: 0;
padding: 5px 10px;
}
#jump_wrapper {
padding: 0;
display: none;
}
#jump_to:hover #jump_wrapper {
display: block;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
}
#jump_page .source {
display: block;
padding: 5px 10px;
text-decoration: none;
border-top: 1px solid #eee;
}
#jump_page .source:hover {
background: #f5f5ff;
}
#jump_page .source:first-child {
}
table td {
border: 0;
outline: 0;
}
td.docs, th.docs {
max-width: 600px;
min-width: 600px;
min-height: 5px;
padding: 10px 25px 1px 150px;
overflow-x: hidden;
vertical-align: top;
text-align: left;
}
.docs pre {
margin: 15px 0 15px;
padding-left: 15px;
}
.docs p tt, .docs p code {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 12px;
padding: 0 0.2em;
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
/*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc }
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
body .cs { color: #408080; font-style: italic } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #808080 } /* Generic.Output */
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0040D0 } /* Generic.Traceback */
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #954121 } /* Keyword.Pseudo */
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #B00040 } /* Keyword.Type */
body .m { color: #666666 } /* Literal.Number */
body .s { color: #219161 } /* Literal.String */
body .na { color: #7D9029 } /* Name.Attribute */
body .nb { color: #954121 } /* Name.Builtin */
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
body .no { color: #880000 } /* Name.Constant */
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
body .nf { color: #0000FF } /* Name.Function */
body .nl { color: #A0A000 } /* Name.Label */
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
body .nv { color: #19469D } /* Name.Variable */
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #666666 } /* Literal.Number.Float */
body .mh { color: #666666 } /* Literal.Number.Hex */
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */
body .sb { color: #219161 } /* Literal.String.Backtick */
body .sc { color: #219161 } /* Literal.String.Char */
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #219161 } /* Literal.String.Double */
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #219161 } /* Literal.String.Heredoc */
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */
body .sr { color: #BB6688 } /* Literal.String.Regex */
body .s1 { color: #219161 } /* Literal.String.Single */
body .ss { color: #19469D } /* Literal.String.Symbol */
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */
body .vi { color: #19469D } /* Name.Variable.Instance */
body .il { color: #666666 } /* Literal.Number.Integer.Long */
<head>
<title>readme.out</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="docket.css" />
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tbody><tr><td class="docs"><p><a href="http://travis-ci.org/russellmcc/node-osc-min"><img src="https://secure.travis-ci.org/russellmcc/node-osc-min.png" alt="build status" title="" /></a></p>
<h1>osc-min</h1>
<p><em>simple utilities for open sound control in node.js</em></p>
<p>This package provides some node.js utilities for working with
<a href="http://opensoundcontrol.org/">OSC</a>, a format for sound and systems control. <br />
Here we implement the <a href="http://opensoundcontrol.org/spec-1_1">OSC 1.1</a> specification. OSC is a transport-independent
protocol, so we don't provide any server objects, as you should be able to
use OSC over any transport you like. The most common is probably udp, but tcp
is not unheard of.</p>
<hr />
<h2>Installation</h2>
<p>The easiest way to get osc-min is through <a href="http://npmjs.org">NPM</a>.
After install npm, you can install osc-min in the current directory with</p>
<p><code>
npm install osc-min
</code></p>
<p>If you'd rather get osc-min through github (for example, if you're forking
it), you still need npm to install dependencies, which you can do with</p>
<p><code>
npm install --dev
</code></p>
<p>Once you've got all the dependencies you should be able to run the unit
tests with </p>
<p><code>
npm test
npm run-script coverage
</code></p>
<hr />
<h2>Examples</h2>
<h3>A simple OSC printer;</h3>
<pre><code> 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);
</code></pre>
<h3>Send a bunch of args every two seconds;</h3>
<pre><code> 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);
</code></pre>
<h3>A simple OSC redirecter;</h3>
<pre><code> 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);
</code></pre>
<p>more examples are available in the <code>examples/</code> directory.</p>
<hr />
<h2>Exported functions</h2>
<hr />
<h3>.fromBuffer(buffer, [strict])</h3>
<p>takes a node.js Buffer of a complete <em>OSC Packet</em> and
outputs the javascript representation, or throws if the buffer is ill-formed.</p>
<p><code>strict</code> is an optional parameter that makes the function fail more often.</p>
<hr />
<h3>.toBuffer(object, [strict])</h3>
<p>takes a <em>OSC packet</em> javascript representation as defined below and returns
a node.js Buffer, or throws if the representation is ill-formed.</p>
<hr />
<h3>.toBuffer(address, args[], [strict])</h3>
<p>alternative syntax for above. Assumes this is an <em>OSC Message</em> as defined below,
and <code>args</code> is an array of <em>OSC Arguments</em> or single <em>OSC Argument</em></p>
<hr />
<h3>.applyAddressTransform(buffer, transform)</h3>
<p>takes a callback that takes a string and outputs a string,
and applies that to the address of the message encoded in the buffer,
and outputs an encoded buffer.</p>
<p>If the buffer encodes an <em>OSC Bundle</em>, this applies the function to each address
in the bundle.</p>
<p>There's two subtle reasons you'd want to use this function rather than
composing <code>fromBuffer</code> and <code>toBuffer</code>:
- Future-proofing - if the OSC message uses an argument typecode that
we don't understand, calling <code>fromBuffer</code> will throw. The only time
when <code>applyAddressTranform</code> might fail is if the address is malformed.
- Accuracy - javascript represents numbers as 64-bit floats, so some
OSC types will not be able to be represented accurately. If accuracy
is important to you, then, you should never convert the OSC message to a
javascript representation.</p>
<hr />
<h3>.applyMessageTransform(buffer, transform)</h3>
<p>takes a function that takes and returns a javascript <em>OSC Message</em> representation,
and applies that to each message encoded in the buffer,
and outputs a new buffer with the new address.</p>
<p>If the buffer encodes an osc-bundle, this applies the function to each message
in the bundle.</p>
<p>See notes above for applyAddressTransform for why you might want to use this.
While this does parse and re-pack the messages, the bundle timetags are left
in their accurate and prestine state.</p>
<hr />
<h2>Javascript representations of the OSC types.</h2>
<p>See the <a href="http://opensoundcontrol.org/spec-1_0">spec</a> for more information on the OSC types.</p>
<ul>
<li><p>An <em>OSC Packet</em> is an <em>OSC Message</em> or an <em>OSC Bundle</em>.</p></li>
<li><p>An <em>OSC Message</em>:</p>
<pre><code> {
oscType : "message"
address : "/address/pattern/might/have/wildcards"
args : [arg1,arg2]
}
</code></pre>
<p>Where args is an array of <em>OSC Arguments</em>. <code>oscType</code> is optional.
<code>args</code> can be a single element.</p></li>
<li><p>An <em>OSC Argument</em> is represented as a javascript object with the following layout:</p>
<pre><code> {
type : "string"
value : "value"
}
</code></pre>
<p>Where the <code>type</code> is one of the following:</p>
<ul><li><code>string</code> - string value</li>
<li><code>float</code> - numeric value</li>
<li><code>integer</code> - numeric value</li>
<li><code>blob</code> - node.js Buffer value</li>
<li><code>true</code> - value is boolean true</li>
<li><code>false</code> - value is boolean false</li>
<li><code>null</code> - no value</li>
<li><code>bang</code> - no value (this is the <code>I</code> type tag)</li>
<li><code>timetag</code> - numeric value</li></ul>
<p>Note that <code>type</code> is always a string - i.e. <code>"true"</code> rather than <code>true</code>.</p>
<p>The following non-standard types are also supported:</p>
<ul><li><code>double</code> - numeric value (encodes to a float64 value)</li></ul>
<p>For messages sent to the <code>toBuffer</code> function, <code>type</code> is optional.
If the argument is not an object, it will be interpreted as either
<code>string</code>, <code>float</code>, or <code>blob</code>, depending on its javascript type.</p></li>
<li><p>An <em>OSC Bundle</em> is represented as a javascript object with the following layout</p>
<pre><code> {
oscType : "bundle"
timetag : 7
elements : [element1, element]
}
</code></pre>
<p>Where the timetag is a javascript-native numeric value of the timetag,
and elements is an array of either an <em>OSC Bundle</em> or an <em>OSC Message</em>
The <code>oscType</code> field is optional, but is always returned by api functions.</p></li>
</ul></td></tr></tbody>
</table>
</body>
// Generated by CoffeeScript 1.3.3
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);
// Generated by CoffeeScript 1.3.3
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);
// Generated by CoffeeScript 1.3.3
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);
// Generated by CoffeeScript 1.3.3
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);
// Generated by CoffeeScript 1.3.3
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);
+2
-2

@@ -21,4 +21,4 @@ # This listens for osc messages and outputs them

#~verbatim:examples[2]~
#### A simple OSC redirecter
`//~verbatim:examples[2]~
//### A simple OSC redirecter`
sock = udp.createSocket "udp4", (msg, rinfo) ->

@@ -25,0 +25,0 @@ try

@@ -15,4 +15,4 @@ # This example simply sends a message with several parameter types

#~verbatim:examples[1]~
#### Send a bunch of args every two seconds
`//~verbatim:examples[1]~
//### Send a bunch of args every two seconds`
sendHeartbeat = () ->

@@ -19,0 +19,0 @@ buf = osc.toBuffer(

@@ -11,4 +11,4 @@ osc = require 'osc-min'

#~verbatim:examples[0]~
#### A simple OSC printer
`//~verbatim:examples[0]~
//### A simple OSC printer`
sock = udp.createSocket "udp4", (msg, rinfo) ->

@@ -15,0 +15,0 @@ try

(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

@@ -5,0 +6,0 @@ //

{
"name": "osc-min",
"version": "0.0.8",
"version": "0.0.9",
"main": "lib/index",

@@ -5,0 +5,0 @@ "author": {

+50
-37

@@ -0,1 +1,2 @@

[![build status](https://secure.travis-ci.org/russellmcc/node-osc-min.png)](http://travis-ci.org/russellmcc/node-osc-min)
# osc-min

@@ -41,44 +42,56 @@

## 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
### 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");
}
});
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}
]
)
### Send a bunch of args every two seconds;
```javascript
udp.send buf, 0, buf.length, outport, "localhost"
setInterval sendHeartbeat, 2000
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);
```
### 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
### 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);
}
});
sock.bind(inport);
```

@@ -85,0 +98,0 @@

Sorry, the diff of this file is not supported yet