Permalink
Browse files

Updated examples and documentation for new coffee-script 1.3 complian…

…t API.
  • Loading branch information...
1 parent b86f5ca commit 65ac6ebf25e21b7044710a4b6facf1bd0be3c73e @russellmcc committed Apr 20, 2012
View
2 examples/osc-float-to-int.coffee
@@ -15,7 +15,7 @@ else
outport = 41235
float_to_int = (message) ->
- for arg in message.arguments
+ for arg in message.args
if arg.type is "float"
arg.type = "integer"
message
View
10 examples/oscbundle_heartbeat.coffee
@@ -16,26 +16,26 @@ sendHeartbeat = () ->
elements : [
{
address : "/p1"
- arguments : new Buffer "beat"
+ args : new Buffer "beat"
}
{
address : "/p2"
- arguments : "string"
+ args : "string"
}
{
timetag: 34567
elements : [
{
address : "/p3"
- arguments : 12
+ args : 12
}
]
}
]
)
-
+
udp.send buf, 0, buf.length, outport, "localhost"
-
+
setInterval sendHeartbeat, 2000
console.log "sending heartbeat messages to http://localhost:" + outport
View
10 examples/oscheartbeat.coffee
@@ -1,4 +1,4 @@
-# This example simply sends a message with several parameter types
+# This example simply sends a message with several parameter types
# every two seconds to port 41234
osc = require 'osc-min'
@@ -13,18 +13,18 @@ else
console.log "sending heartbeat messages to http://localhost:" + outport
#~verbatim:examples[1]~
-#### Send a bunch of arguments every two seconds
+#### Send a bunch of args every two seconds
sendHeartbeat = () ->
buf = osc.toBuffer(
address : "/heartbeat"
- arguments : [
+ args : [
12
"sttttring"
new Buffer "beat"
{type : "integer", value : 7}
]
)
-
+
udp.send buf, 0, buf.length, outport, "localhost"
-
+
setInterval sendHeartbeat, 2000
View
12 lib/index.js
@@ -39,11 +39,11 @@
// {
// oscType : "message"
// address : "/address/pattern/might/have/wildcards"
-// arguments : [arg1,arg2]
+// args : [arg1,arg2]
// }
//
-// Where arguments is an array of _OSC Arguments_. `oscType` is optional.
-// `arguments` can be a single element.
+// Where args is an array of _OSC Arguments_. `oscType` is optional.
+// `args` can be a single element.
//
// + An _OSC Argument_ is represented as a javascript object with the following layout:
//
@@ -110,12 +110,12 @@
// a node.js Buffer, or throws if the representation is ill-formed.
//
//----
-//### .toBuffer(address, arguments[], [strict])
+//### .toBuffer(address, args[], [strict])
// alternative syntax for above. Assumes this is an _OSC Message_ as defined below,
-// and `arguments` is an array of _OSC Arguments_ or single _OSC Argument_
+// and `args` is an array of _OSC Arguments_ or single _OSC Argument_
exports.toBuffer = function(object, strict, opt) {
if(typeof object === "string")
- return utils.toOscPacket({'address' : object, 'arguments' : strict}, opt);
+ return utils.toOscPacket({'address' : object, 'args' : strict}, opt);
return utils.toOscPacket(object, strict);
};
View
6 lib/osc-utilities.coffee
@@ -303,7 +303,7 @@ exports.fromOscMessage = (buffer, strict) ->
# implementations that send message without a type string are fixed.
# this will never happen, so we should accept this, even in
# strict mode.
- return {address : address, arguments : []} if not buffer.length
+ return {address : address, args : []} if not buffer.length
# if there's more data but no type string, we can't parse the arguments.
{string : types, rest : buffer} = exports.splitOscString buffer, strict
@@ -312,7 +312,7 @@ exports.fromOscMessage = (buffer, strict) ->
# parse the arguments.
if types[0] isnt ','
throw StrictError 'Argument lists must begin with ,' if strict
- return {address : address, arguments : []}
+ return {address : address, args : []}
# we don't need the comma anymore
types = types[1..(types.length)]
@@ -335,7 +335,7 @@ exports.fromOscMessage = (buffer, strict) ->
value : arg?.value
)
- {address : address, arguments : args, oscType : "message"}
+ {address : address, args : args, oscType : "message"}
#
# Try to parse an OSC bundle into a javascript object.
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "osc-min",
- "version": "0.0.5",
+ "version": "0.0.6",
"main": "lib/index",
"author": {
"name" : "Russell McClellan",
View
18 readme.md
@@ -48,21 +48,21 @@ sock = udp.createSocket "udp4", (msg, rinfo) ->
sock.bind inport
```
-### Send a bunch of arguments every two seconds
+### Send a bunch of args every two seconds
```coffee-script
sendHeartbeat = () ->
buf = osc.toBuffer(
address : "/heartbeat"
- arguments : [
+ args : [
12
"sttttring"
new Buffer "beat"
{type : "integer", value : 7}
]
)
-
+
udp.send buf, 0, buf.length, outport, "localhost"
-
+
setInterval sendHeartbeat, 2000
```
### A simple OSC redirecter
@@ -101,9 +101,9 @@ takes a _OSC packet_ javascript representation as defined below and returns
a node.js Buffer, or throws if the representation is ill-formed.
----
-### .toBuffer(address, arguments[], [strict])
+### .toBuffer(address, args[], [strict])
alternative syntax for above. Assumes this is an _OSC Message_ as defined below,
-and `arguments` is an array of _OSC Arguments_ or single _OSC Argument_
+and `args` is an array of _OSC Arguments_ or single _OSC Argument_
----
### .applyAddressTransform(buffer, transform)
@@ -148,11 +148,11 @@ See the [spec][spec] for more information on the OSC types.
{
oscType : "message"
address : "/address/pattern/might/have/wildcards"
- arguments : [arg1,arg2]
+ args : [arg1,arg2]
}
- Where arguments is an array of _OSC Arguments_. `oscType` is optional.
- `arguments` can be a single element.
+ Where args is an array of _OSC Arguments_. `oscType` is optional.
+ `args` can be a single element.
+ An _OSC Argument_ is represented as a javascript object with the following layout:
View
148 test/test-osc-utilities.coffee
@@ -126,67 +126,67 @@ exports["splitOscArgument fails when given a bogus type"] = ->
exports["fromOscMessage with no type string works"] = ->
translate = osc.fromOscMessage osc.toOscString "/stuff"
assert.strictEqual translate?.address, "/stuff"
- assert.deepEqual translate?.arguments, []
+ assert.deepEqual translate?.args, []
-exports["fromOscMessage with type string and no arguments works"] = ->
+exports["fromOscMessage with type string and no args works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ","
oscmessage = new Buffer(oscaddr.length + osctype.length)
oscaddr.copy oscmessage
osctype.copy oscmessage, oscaddr.length
translate = osc.fromOscMessage oscmessage
assert.strictEqual translate?.address, "/stuff"
- assert.deepEqual translate?.arguments, []
+ assert.deepEqual translate?.args, []
exports["fromOscMessage with string argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",s"
oscarg = osc.toOscString "argu"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype, oscarg]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "string"
- assert.strictEqual translate?.arguments?[0]?.value, "argu"
+ assert.strictEqual translate?.args?[0]?.type, "string"
+ assert.strictEqual translate?.args?[0]?.value, "argu"
exports["fromOscMessage with true argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",T"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "true"
- assert.strictEqual translate?.arguments?[0]?.value, true
+ assert.strictEqual translate?.args?[0]?.type, "true"
+ assert.strictEqual translate?.args?[0]?.value, true
exports["fromOscMessage with false argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",F"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "false"
- assert.strictEqual translate?.arguments?[0]?.value, false
+ assert.strictEqual translate?.args?[0]?.type, "false"
+ assert.strictEqual translate?.args?[0]?.value, false
exports["fromOscMessage with null argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",N"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "null"
- assert.strictEqual translate?.arguments?[0]?.value, null
+ assert.strictEqual translate?.args?[0]?.type, "null"
+ assert.strictEqual translate?.args?[0]?.value, null
exports["fromOscMessage with bang argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",I"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "bang"
- assert.strictEqual translate?.arguments?[0]?.value, "bang"
+ assert.strictEqual translate?.args?[0]?.type, "bang"
+ assert.strictEqual translate?.args?[0]?.value, "bang"
exports["fromOscMessage with blob argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",b"
oscarg = osc.concat [(osc.toIntegerBuffer 4), new Buffer "argu"]
translate = osc.fromOscMessage osc.concat [oscaddr, osctype, oscarg]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "blob"
- assert.strictEqual (translate?.arguments?[0]?.value?.toString "utf8"), "argu"
+ assert.strictEqual translate?.args?[0]?.type, "blob"
+ assert.strictEqual (translate?.args?[0]?.value?.toString "utf8"), "argu"
exports["fromOscMessage with integer argument works"] = ->
@@ -195,19 +195,19 @@ exports["fromOscMessage with integer argument works"] = ->
oscarg = osc.toIntegerBuffer 888
translate = osc.fromOscMessage osc.concat [oscaddr, osctype, oscarg]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "integer"
- assert.strictEqual (translate?.arguments?[0]?.value), 888
+ assert.strictEqual translate?.args?[0]?.type, "integer"
+ assert.strictEqual (translate?.args?[0]?.value), 888
exports["fromOscMessage with timetag argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",t"
oscarg = osc.toIntegerBuffer 8888, "UInt64"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype, oscarg]
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "timetag"
- assert.strictEqual (translate?.arguments?[0]?.value), 8888
+ assert.strictEqual translate?.args?[0]?.type, "timetag"
+ assert.strictEqual (translate?.args?[0]?.value), 8888
-exports["fromOscMessage with multiple arguments works."] = ->
+exports["fromOscMessage with multiple args works."] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",sbi"
oscargs = [
@@ -219,8 +219,8 @@ exports["fromOscMessage with multiple arguments works."] = ->
oscbuffer = osc.concat [oscaddr, osctype, (osc.concat oscargs)]
translate = osc.fromOscMessage oscbuffer
assert.strictEqual translate?.address, "/stuff"
- assert.strictEqual translate?.arguments?[0]?.type, "string"
- assert.strictEqual (translate?.arguments?[0]?.value), "argu"
+ assert.strictEqual translate?.args?[0]?.type, "string"
+ assert.strictEqual (translate?.args?[0]?.value), "argu"
exports["fromOscMessage strict fails if type string has no comma"] = ->
oscaddr = osc.toOscString "/stuff"
@@ -233,7 +233,7 @@ exports["fromOscMessage non-strict works if type string has no comma"] = ->
osctype = osc.toOscString "fake"
message = osc.fromOscMessage (osc.concat [oscaddr, osctype])
assert.strictEqual message.address, "/stuff"
- assert.strictEqual message.arguments.length, 0
+ assert.strictEqual message.args.length, 0
exports["fromOscMessage strict fails if type address doesn't begin with /"] = ->
oscaddr = osc.toOscString "stuff"
@@ -334,29 +334,29 @@ exports["fromOscBundle fails with ridiculous sizes"] = ->
roundTripMessage = (args) ->
oscMessage = {
address : "/addr"
- arguments : args
+ args : args
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage), true
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, args.length
+ assert.strictEqual roundTrip?.args?.length, args.length
for i in [0...args.length]
comp = if args[i]?.value? then args[i].value else args[i]
- assert.strictEqual roundTrip?.arguments?[i]?.type, args[i].type if args[i]?.type?
+ assert.strictEqual roundTrip?.args?[i]?.type, args[i].type if args[i]?.type?
if Buffer.isBuffer comp
for j in [0...comp.length]
- assert.strictEqual roundTrip?.arguments?[i]?.value?[j], comp[j]
+ assert.strictEqual roundTrip?.args?[i]?.value?[j], comp[j]
else
- assert.strictEqual roundTrip?.arguments?[i]?.value, comp
+ assert.strictEqual roundTrip?.args?[i]?.value, comp
exports["toOscArgument fails when given bogus type"] = ->
assert.throws -> osc.toOscArgument "bleh", "bogus"
# we tested fromOsc* manually, so just use roundtrip testing for toOsc*
-exports["toOscMessage with no arguments works"] = ->
+exports["toOscMessage with no args works"] = ->
roundTripMessage []
exports["toOscMessage strict with null argument throws"] = ->
- assert.throws -> osc.toOscMessage {address : "/addr", arguments : [null]}, true
+ assert.throws -> osc.toOscMessage {address : "/addr", args : [null]}, true
exports["toOscMessage with string argument works"] = ->
roundTripMessage ["strr"]
@@ -369,25 +369,25 @@ buffeq = (buff, exp_buff) ->
exports["toOscMessage with bad layout works"] = ->
oscMessage = {
address : "/addr"
- arguments : [
+ args : [
"strr"
]
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage), true
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, 1
- assert.strictEqual roundTrip?.arguments?[0]?.value, "strr"
+ assert.strictEqual roundTrip?.args?.length, 1
+ assert.strictEqual roundTrip?.args?[0]?.value, "strr"
exports["toOscMessage with single numeric argument works"] = ->
oscMessage = {
address : "/addr"
- arguments : 13
+ args : 13
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage)
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, 1
- assert.strictEqual roundTrip?.arguments?[0]?.value, 13
- assert.strictEqual roundTrip?.arguments?[0]?.type, "float"
+ assert.strictEqual roundTrip?.args?.length, 1
+ assert.strictEqual roundTrip?.args?[0]?.value, 13
+ assert.strictEqual roundTrip?.args?[0]?.type, "float"
exports["toOscMessage with args shortcut works"] = ->
oscMessage = {
@@ -396,32 +396,32 @@ exports["toOscMessage with args shortcut works"] = ->
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage)
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, 1
- assert.strictEqual roundTrip?.arguments?[0]?.value, 13
- assert.strictEqual roundTrip?.arguments?[0]?.type, "float"
+ assert.strictEqual roundTrip?.args?.length, 1
+ assert.strictEqual roundTrip?.args?[0]?.value, 13
+ assert.strictEqual roundTrip?.args?[0]?.type, "float"
exports["toOscMessage with single blob argument works"] = ->
buff = new Buffer 18
oscMessage = {
address : "/addr"
- arguments : buff
+ args : buff
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage)
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, 1
- buffeq roundTrip?.arguments?[0]?.value, buff
- assert.strictEqual roundTrip?.arguments?[0]?.type, "blob"
+ assert.strictEqual roundTrip?.args?.length, 1
+ buffeq roundTrip?.args?[0]?.value, buff
+ assert.strictEqual roundTrip?.args?[0]?.type, "blob"
exports["toOscMessage with single string argument works"] = ->
oscMessage = {
address : "/addr"
- arguments : "strr"
+ args : "strr"
}
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage)
assert.strictEqual roundTrip?.address, "/addr"
- assert.strictEqual roundTrip?.arguments?.length, 1
- assert.strictEqual roundTrip?.arguments?[0]?.value, "strr"
- assert.strictEqual roundTrip?.arguments?[0]?.type, "string"
+ assert.strictEqual roundTrip?.args?.length, 1
+ assert.strictEqual roundTrip?.args?[0]?.value, "strr"
+ assert.strictEqual roundTrip?.args?[0]?.type, "string"
exports["toOscMessage with integer argument works"] = ->
roundTripMessage [8]
@@ -431,28 +431,28 @@ exports["toOscMessage with buffer argument works"] = ->
roundTripMessage [new Buffer 16]
exports["toOscMessage strict with type true and value false throws"] = ->
- assert.throws -> osc.toOscMessage {address: "/addr/", arguments: {type : "true", value : false}}, true
+ assert.throws -> osc.toOscMessage {address: "/addr/", args: {type : "true", value : false}}, true
exports["toOscMessage strict with type false with value true throws"] = ->
- assert.throws -> osc.toOscMessage {address: "/addr/", arguments: {type : "false", value : true}}, true
+ assert.throws -> osc.toOscMessage {address: "/addr/", args: {type : "false", value : true}}, true
exports["toOscMessage with type true works"] = ->
- roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : true}
- assert.strictEqual roundTrip.arguments.length, 1
- assert.strictEqual roundTrip.arguments[0].value, true
- assert.strictEqual roundTrip.arguments[0].type, "true"
+ roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", args : true}
+ assert.strictEqual roundTrip.args.length, 1
+ assert.strictEqual roundTrip.args[0].value, true
+ assert.strictEqual roundTrip.args[0].type, "true"
exports["toOscMessage with type false works"] = ->
- roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : false}
- assert.strictEqual roundTrip.arguments.length, 1
- assert.strictEqual roundTrip.arguments[0].value, false
- assert.strictEqual roundTrip.arguments[0].type, "false"
+ roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", args : false}
+ assert.strictEqual roundTrip.args.length, 1
+ assert.strictEqual roundTrip.args[0].value, false
+ assert.strictEqual roundTrip.args[0].type, "false"
exports["toOscMessage with type bang argument works"] = ->
- roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : {type:"bang"}}
- assert.strictEqual roundTrip.arguments.length, 1
- assert.strictEqual roundTrip.arguments[0].value, "bang"
- assert.strictEqual roundTrip.arguments[0].type, "bang"
+ roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", args : {type:"bang"}}
+ assert.strictEqual roundTrip.args.length, 1
+ assert.strictEqual roundTrip.args[0].value, "bang"
+ assert.strictEqual roundTrip.args[0].type, "bang"
exports["toOscMessage with type timetag argument works"] = ->
roundTripMessage [{type: "timetag", value:8888}]
@@ -461,35 +461,35 @@ exports["toOscMessage with type double argument works"] = ->
roundTripMessage [{type: "double", value:8888}]
exports["toOscMessage strict with type null with value true throws"] = ->
- assert.throws -> osc.toOscMessage({address: "/addr/", arguments: {type : "null", value : true}}, true)
+ assert.throws -> osc.toOscMessage({address: "/addr/", args: {type : "null", value : true}}, true)
exports["toOscMessage with type null works"] = ->
- roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : null}
- assert.strictEqual roundTrip.arguments.length, 1
- assert.strictEqual roundTrip.arguments[0].value, null
- assert.strictEqual roundTrip.arguments[0].type, "null"
+ roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", args : null}
+ assert.strictEqual roundTrip.args.length, 1
+ assert.strictEqual roundTrip.args[0].value, null
+ assert.strictEqual roundTrip.args[0].type, "null"
exports["toOscMessage with float argument works"] = ->
roundTripMessage [{value : 6, type : "float"}]
exports["toOscMessage just a string works"] = ->
message = osc.fromOscMessage osc.toOscMessage "bleh"
assert.strictEqual message.address, "bleh"
- assert.strictEqual message.arguments.length, 0
+ assert.strictEqual message.args.length, 0
-exports["toOscMessage with multiple arguments works"] = ->
+exports["toOscMessage with multiple args works"] = ->
roundTripMessage ["str", 7, (new Buffer 30), 6]
exports["toOscMessage with integer argument works"] = ->
roundTripMessage [{value : 7, type: "integer"}]
exports["toOscMessage fails with no address"] = ->
- assert.throws -> osc.toOscMessage {arguments : []}
+ assert.throws -> osc.toOscMessage {args : []}
toOscMessageThrowsHelper = (arg) ->
assert.throws -> osc.toOscMessage(
address : "/addr"
- arguments : [arg]
+ args : [arg]
)
exports["toOscMessage fails when string type is specified but wrong"] = ->
@@ -589,8 +589,8 @@ exports["toOscPacket works when explicitly set to bundle"] = ->
assert.strictEqual roundTrip.elements.length, 0
exports["toOscPacket works when explicitly set to message"] = ->
- roundTrip = osc.fromOscPacket osc.toOscPacket {address: "/bleh", oscType:"message", arguments :[]}, true
- assert.strictEqual roundTrip.arguments.length, 0
+ roundTrip = osc.fromOscPacket osc.toOscPacket {address: "/bleh", oscType:"message", args :[]}, true
+ assert.strictEqual roundTrip.args.length, 0
assert.strictEqual roundTrip.address, "/bleh"
exports["identity applyTransform works with a simple bundle"] = ->
@@ -642,7 +642,7 @@ exports["addressTransform works with bundles"] = ->
exports["messageTransform works with identity function for single message"] = ->
message =
address: "/addr"
- arguments: []
+ args: []
buff = osc.toOscPacket message
buffeq (osc.applyTransform buff, osc.messageTransform (a) -> a), buff

0 comments on commit 65ac6eb

Please sign in to comment.