l@271: // Generated by CoffeeScript 1.10.0 l@271: (function() { l@271: var IsArray, StrictError, TWO_POW_32, UNIX_EPOCH, binpack, getArrayArg, isOscBundleBuffer, makeTimetag, mapBundleList, oscTypeCodes, padding, toOscTypeAndArgs, l@271: hasProp = {}.hasOwnProperty; l@271: l@271: binpack = require("binpack"); l@271: l@271: exports.concat = function(buffers) { l@271: var buffer, copyTo, destBuffer, j, k, l, len, len1, len2, sumLength; l@271: if (!IsArray(buffers)) { l@271: throw new Error("concat must take an array of buffers"); l@271: } l@271: for (j = 0, len = buffers.length; j < len; j++) { l@271: buffer = buffers[j]; l@271: if (!Buffer.isBuffer(buffer)) { l@271: throw new Error("concat must take an array of buffers"); l@271: } l@271: } l@271: sumLength = 0; l@271: for (k = 0, len1 = buffers.length; k < len1; k++) { l@271: buffer = buffers[k]; l@271: sumLength += buffer.length; l@271: } l@271: destBuffer = new Buffer(sumLength); l@271: copyTo = 0; l@271: for (l = 0, len2 = buffers.length; l < len2; l++) { l@271: buffer = buffers[l]; l@271: buffer.copy(destBuffer, copyTo); l@271: copyTo += buffer.length; l@271: } l@271: return destBuffer; l@271: }; l@271: l@271: exports.toOscString = function(str, strict) { l@271: var i, j, nullIndex, ref; l@271: if (!(typeof str === "string")) { l@271: throw new Error("can't pack a non-string into an osc-string"); l@271: } l@271: nullIndex = str.indexOf("\u0000"); l@271: if (nullIndex !== -1 && strict) { l@271: throw StrictError("Can't pack an osc-string that contains NULL characters"); l@271: } l@271: if (nullIndex !== -1) { l@271: str = str.slice(0, nullIndex); l@271: } l@271: for (i = j = 0, ref = padding(str); 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { l@271: str += "\u0000"; l@271: } l@271: return new Buffer(str); l@271: }; l@271: l@271: exports.splitOscString = function(buffer, strict) { l@271: var i, j, nullIndex, rawStr, ref, ref1, rest, splitPoint, str; l@271: if (!Buffer.isBuffer(buffer)) { l@271: throw StrictError("Can't split something that isn't a buffer"); l@271: } l@271: rawStr = buffer.toString("utf8"); l@271: nullIndex = rawStr.indexOf("\u0000"); l@271: if (nullIndex === -1) { l@271: if (strict) { l@271: throw new Error("All osc-strings must contain a null character"); l@271: } l@271: return { l@271: string: rawStr, l@271: rest: new Buffer(0) l@271: }; l@271: } l@271: str = rawStr.slice(0, nullIndex); l@271: splitPoint = Buffer.byteLength(str) + padding(str); l@271: if (strict && splitPoint > buffer.length) { l@271: throw StrictError("Not enough padding for osc-string"); l@271: } l@271: if (strict) { l@271: for (i = j = ref = Buffer.byteLength(str), ref1 = splitPoint; ref <= ref1 ? j < ref1 : j > ref1; i = ref <= ref1 ? ++j : --j) { l@271: if (buffer[i] !== 0) { l@271: throw StrictError("Not enough or incorrect padding for osc-string"); l@271: } l@271: } l@271: } l@271: rest = buffer.slice(splitPoint, buffer.length); l@271: return { l@271: string: str, l@271: rest: rest l@271: }; l@271: }; l@271: l@271: exports.splitInteger = function(buffer, type) { l@271: var bytes, num, rest, value; l@271: if (type == null) { l@271: type = "Int32"; l@271: } l@271: bytes = (binpack["pack" + type](0)).length; l@271: if (buffer.length < bytes) { l@271: throw new Error("buffer is not big enough for integer type"); l@271: } l@271: num = 0; l@271: value = binpack["unpack" + type](buffer.slice(0, bytes), "big"); l@271: rest = buffer.slice(bytes, buffer.length); l@271: return { l@271: integer: value, l@271: rest: rest l@271: }; l@271: }; l@271: l@271: exports.splitTimetag = function(buffer) { l@271: var a, b, bytes, c, d, fractional, rest, seconds, type; l@271: type = "Int32"; l@271: bytes = (binpack["pack" + type](0)).length; l@271: if (buffer.length < (bytes * 2)) { l@271: throw new Error("buffer is not big enough to contain a timetag"); l@271: } l@271: a = 0; l@271: b = bytes; l@271: seconds = binpack["unpack" + type](buffer.slice(a, b), "big"); l@271: c = bytes; l@271: d = bytes + bytes; l@271: fractional = binpack["unpack" + type](buffer.slice(c, d), "big"); l@271: rest = buffer.slice(d, buffer.length); l@271: return { l@271: timetag: [seconds, fractional], l@271: rest: rest l@271: }; l@271: }; l@271: l@271: UNIX_EPOCH = 2208988800; l@271: l@271: TWO_POW_32 = 4294967296; l@271: l@271: exports.dateToTimetag = function(date) { l@271: return exports.timestampToTimetag(date.getTime() / 1000); l@271: }; l@271: l@271: exports.timestampToTimetag = function(secs) { l@271: var fracSeconds, wholeSecs; l@271: wholeSecs = Math.floor(secs); l@271: fracSeconds = secs - wholeSecs; l@271: return makeTimetag(wholeSecs, fracSeconds); l@271: }; l@271: l@271: exports.timetagToTimestamp = function(timetag) { l@271: var seconds; l@271: seconds = timetag[0] + exports.ntpToFractionalSeconds(timetag[1]); l@271: return seconds - UNIX_EPOCH; l@271: }; l@271: l@271: makeTimetag = function(unixseconds, fracSeconds) { l@271: var ntpFracs, ntpSecs; l@271: ntpSecs = unixseconds + UNIX_EPOCH; l@271: ntpFracs = Math.round(TWO_POW_32 * fracSeconds); l@271: return [ntpSecs, ntpFracs]; l@271: }; l@271: l@271: exports.timetagToDate = function(timetag) { l@271: var date, dd, fracs, fractional, seconds; l@271: seconds = timetag[0], fractional = timetag[1]; l@271: seconds = seconds - UNIX_EPOCH; l@271: fracs = exports.ntpToFractionalSeconds(fractional); l@271: date = new Date(); l@271: date.setTime((seconds * 1000) + (fracs * 1000)); l@271: dd = new Date(); l@271: dd.setUTCFullYear(date.getUTCFullYear()); l@271: dd.setUTCMonth(date.getUTCMonth()); l@271: dd.setUTCDate(date.getUTCDate()); l@271: dd.setUTCHours(date.getUTCHours()); l@271: dd.setUTCMinutes(date.getUTCMinutes()); l@271: dd.setUTCSeconds(date.getUTCSeconds()); l@271: dd.setUTCMilliseconds(fracs * 1000); l@271: return dd; l@271: }; l@271: l@271: exports.deltaTimetag = function(seconds, now) { l@271: var n; l@271: n = (now != null ? now : new Date()) / 1000; l@271: return exports.timestampToTimetag(n + seconds); l@271: }; l@271: l@271: exports.ntpToFractionalSeconds = function(fracSeconds) { l@271: return parseFloat(fracSeconds) / TWO_POW_32; l@271: }; l@271: l@271: exports.toTimetagBuffer = function(timetag) { l@271: var high, low, type; l@271: if (typeof timetag === "number") { l@271: timetag = exports.timestampToTimetag(timetag); l@271: } else if (typeof timetag === "object" && ("getTime" in timetag)) { l@271: timetag = exports.dateToTimetag(timetag); l@271: } else if (timetag.length !== 2) { l@271: throw new Error("Invalid timetag" + timetag); l@271: } l@271: type = "Int32"; l@271: high = binpack["pack" + type](timetag[0], "big"); l@271: low = binpack["pack" + type](timetag[1], "big"); l@271: return exports.concat([high, low]); l@271: }; l@271: l@271: exports.toIntegerBuffer = function(number, type) { l@271: if (type == null) { l@271: type = "Int32"; l@271: } l@271: if (typeof number !== "number") { l@271: throw new Error("cannot pack a non-number into an integer buffer"); l@271: } l@271: return binpack["pack" + type](number, "big"); l@271: }; l@271: l@271: oscTypeCodes = { l@271: s: { l@271: representation: "string", l@271: split: function(buffer, strict) { l@271: var split; l@271: split = exports.splitOscString(buffer, strict); l@271: return { l@271: value: split.string, l@271: rest: split.rest l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (typeof value !== "string") { l@271: throw new Error("expected string"); l@271: } l@271: return exports.toOscString(value, strict); l@271: } l@271: }, l@271: i: { l@271: representation: "integer", l@271: split: function(buffer, strict) { l@271: var split; l@271: split = exports.splitInteger(buffer); l@271: return { l@271: value: split.integer, l@271: rest: split.rest l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (typeof value !== "number") { l@271: throw new Error("expected number"); l@271: } l@271: return exports.toIntegerBuffer(value); l@271: } l@271: }, l@271: t: { l@271: representation: "timetag", l@271: split: function(buffer, strict) { l@271: var split; l@271: split = exports.splitTimetag(buffer); l@271: return { l@271: value: split.timetag, l@271: rest: split.rest l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: return exports.toTimetagBuffer(value); l@271: } l@271: }, l@271: f: { l@271: representation: "float", l@271: split: function(buffer, strict) { l@271: return { l@271: value: binpack.unpackFloat32(buffer.slice(0, 4), "big"), l@271: rest: buffer.slice(4, buffer.length) l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (typeof value !== "number") { l@271: throw new Error("expected number"); l@271: } l@271: return binpack.packFloat32(value, "big"); l@271: } l@271: }, l@271: d: { l@271: representation: "double", l@271: split: function(buffer, strict) { l@271: return { l@271: value: binpack.unpackFloat64(buffer.slice(0, 8), "big"), l@271: rest: buffer.slice(8, buffer.length) l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (typeof value !== "number") { l@271: throw new Error("expected number"); l@271: } l@271: return binpack.packFloat64(value, "big"); l@271: } l@271: }, l@271: b: { l@271: representation: "blob", l@271: split: function(buffer, strict) { l@271: var length, ref; l@271: ref = exports.splitInteger(buffer), length = ref.integer, buffer = ref.rest; l@271: return { l@271: value: buffer.slice(0, length), l@271: rest: buffer.slice(length, buffer.length) l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: var size; l@271: if (!Buffer.isBuffer(value)) { l@271: throw new Error("expected node.js Buffer"); l@271: } l@271: size = exports.toIntegerBuffer(value.length); l@271: return exports.concat([size, value]); l@271: } l@271: }, l@271: T: { l@271: representation: "true", l@271: split: function(buffer, strict) { l@271: return { l@271: rest: buffer, l@271: value: true l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (!value && strict) { l@271: throw new Error("true must be true"); l@271: } l@271: return new Buffer(0); l@271: } l@271: }, l@271: F: { l@271: representation: "false", l@271: split: function(buffer, strict) { l@271: return { l@271: rest: buffer, l@271: value: false l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (value && strict) { l@271: throw new Error("false must be false"); l@271: } l@271: return new Buffer(0); l@271: } l@271: }, l@271: N: { l@271: representation: "null", l@271: split: function(buffer, strict) { l@271: return { l@271: rest: buffer, l@271: value: null l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: if (value && strict) { l@271: throw new Error("null must be false"); l@271: } l@271: return new Buffer(0); l@271: } l@271: }, l@271: I: { l@271: representation: "bang", l@271: split: function(buffer, strict) { l@271: return { l@271: rest: buffer, l@271: value: "bang" l@271: }; l@271: }, l@271: toArg: function(value, strict) { l@271: return new Buffer(0); l@271: } l@271: } l@271: }; l@271: l@271: exports.oscTypeCodeToTypeString = function(code) { l@271: var ref; l@271: return (ref = oscTypeCodes[code]) != null ? ref.representation : void 0; l@271: }; l@271: l@271: exports.typeStringToOscTypeCode = function(rep) { l@271: var code, str; l@271: for (code in oscTypeCodes) { l@271: if (!hasProp.call(oscTypeCodes, code)) continue; l@271: str = oscTypeCodes[code].representation; l@271: if (str === rep) { l@271: return code; l@271: } l@271: } l@271: return null; l@271: }; l@271: l@271: exports.argToTypeCode = function(arg, strict) { l@271: var code, value; l@271: if (((arg != null ? arg.type : void 0) != null) && (typeof arg.type === 'string') && ((code = exports.typeStringToOscTypeCode(arg.type)) != null)) { l@271: return code; l@271: } l@271: value = (arg != null ? arg.value : void 0) != null ? arg.value : arg; l@271: if (strict && (value == null)) { l@271: throw new Error('Argument has no value'); l@271: } l@271: if (typeof value === 'string') { l@271: return 's'; l@271: } l@271: if (typeof value === 'number') { l@271: return 'f'; l@271: } l@271: if (Buffer.isBuffer(value)) { l@271: return 'b'; l@271: } l@271: if (typeof value === 'boolean') { l@271: if (value) { l@271: return 'T'; l@271: } else { l@271: return 'F'; l@271: } l@271: } l@271: if (value === null) { l@271: return 'N'; l@271: } l@271: throw new Error("I don't know what type this is supposed to be."); l@271: }; l@271: l@271: exports.splitOscArgument = function(buffer, type, strict) { l@271: var osctype; l@271: osctype = exports.typeStringToOscTypeCode(type); l@271: if (osctype != null) { l@271: return oscTypeCodes[osctype].split(buffer, strict); l@271: } else { l@271: throw new Error("I don't understand how I'm supposed to unpack " + type); l@271: } l@271: }; l@271: l@271: exports.toOscArgument = function(value, type, strict) { l@271: var osctype; l@271: osctype = exports.typeStringToOscTypeCode(type); l@271: if (osctype != null) { l@271: return oscTypeCodes[osctype].toArg(value, strict); l@271: } else { l@271: throw new Error("I don't know how to pack " + type); l@271: } l@271: }; l@271: l@271: exports.fromOscMessage = function(buffer, strict) { l@271: var address, arg, args, arrayStack, built, j, len, ref, ref1, type, typeString, types; l@271: ref = exports.splitOscString(buffer, strict), address = ref.string, buffer = ref.rest; l@271: if (strict && address[0] !== '/') { l@271: throw StrictError('addresses must start with /'); l@271: } l@271: if (!buffer.length) { l@271: return { l@271: address: address, l@271: args: [] l@271: }; l@271: } l@271: ref1 = exports.splitOscString(buffer, strict), types = ref1.string, buffer = ref1.rest; l@271: if (types[0] !== ',') { l@271: if (strict) { l@271: throw StrictError('Argument lists must begin with ,'); l@271: } l@271: return { l@271: address: address, l@271: args: [] l@271: }; l@271: } l@271: types = types.slice(1, +types.length + 1 || 9e9); l@271: args = []; l@271: arrayStack = [args]; l@271: for (j = 0, len = types.length; j < len; j++) { l@271: type = types[j]; l@271: if (type === '[') { l@271: arrayStack.push([]); l@271: continue; l@271: } l@271: if (type === ']') { l@271: if (arrayStack.length <= 1) { l@271: if (strict) { l@271: throw new StrictError("Mismatched ']' character."); l@271: } l@271: } else { l@271: built = arrayStack.pop(); l@271: arrayStack[arrayStack.length - 1].push({ l@271: type: 'array', l@271: value: built l@271: }); l@271: } l@271: continue; l@271: } l@271: typeString = exports.oscTypeCodeToTypeString(type); l@271: if (typeString == null) { l@271: throw new Error("I don't understand the argument code " + type); l@271: } l@271: arg = exports.splitOscArgument(buffer, typeString, strict); l@271: if (arg != null) { l@271: buffer = arg.rest; l@271: } l@271: arrayStack[arrayStack.length - 1].push({ l@271: type: typeString, l@271: value: arg != null ? arg.value : void 0 l@271: }); l@271: } l@271: if (arrayStack.length !== 1 && strict) { l@271: throw new StrictError("Mismatched '[' character"); l@271: } l@271: return { l@271: address: address, l@271: args: args, l@271: oscType: "message" l@271: }; l@271: }; l@271: l@271: exports.fromOscBundle = function(buffer, strict) { l@271: var bundleTag, convertedElems, ref, ref1, timetag; l@271: ref = exports.splitOscString(buffer, strict), bundleTag = ref.string, buffer = ref.rest; l@271: if (bundleTag !== "\#bundle") { l@271: throw new Error("osc-bundles must begin with \#bundle"); l@271: } l@271: ref1 = exports.splitTimetag(buffer), timetag = ref1.timetag, buffer = ref1.rest; l@271: convertedElems = mapBundleList(buffer, function(buffer) { l@271: return exports.fromOscPacket(buffer, strict); l@271: }); l@271: return { l@271: timetag: timetag, l@271: elements: convertedElems, l@271: oscType: "bundle" l@271: }; l@271: }; l@271: l@271: exports.fromOscPacket = function(buffer, strict) { l@271: if (isOscBundleBuffer(buffer, strict)) { l@271: return exports.fromOscBundle(buffer, strict); l@271: } else { l@271: return exports.fromOscMessage(buffer, strict); l@271: } l@271: }; l@271: l@271: getArrayArg = function(arg) { l@271: if (IsArray(arg)) { l@271: return arg; l@271: } else if (((arg != null ? arg.type : void 0) === "array") && (IsArray(arg != null ? arg.value : void 0))) { l@271: return arg.value; l@271: } else if ((arg != null) && (arg.type == null) && (IsArray(arg.value))) { l@271: return arg.value; l@271: } else { l@271: return null; l@271: } l@271: }; l@271: l@271: toOscTypeAndArgs = function(argList, strict) { l@271: var arg, buff, j, len, oscargs, osctype, ref, thisArgs, thisType, typeCode, value; l@271: osctype = ""; l@271: oscargs = []; l@271: for (j = 0, len = argList.length; j < len; j++) { l@271: arg = argList[j]; l@271: if ((getArrayArg(arg)) != null) { l@271: ref = toOscTypeAndArgs(getArrayArg(arg), strict), thisType = ref[0], thisArgs = ref[1]; l@271: osctype += "[" + thisType + "]"; l@271: oscargs = oscargs.concat(thisArgs); l@271: continue; l@271: } l@271: typeCode = exports.argToTypeCode(arg, strict); l@271: if (typeCode != null) { l@271: value = arg != null ? arg.value : void 0; l@271: if (value === void 0) { l@271: value = arg; l@271: } l@271: buff = exports.toOscArgument(value, exports.oscTypeCodeToTypeString(typeCode), strict); l@271: if (buff != null) { l@271: oscargs.push(buff); l@271: osctype += typeCode; l@271: } l@271: } l@271: } l@271: return [osctype, oscargs]; l@271: }; l@271: l@271: exports.toOscMessage = function(message, strict) { l@271: var address, allArgs, args, old_arg, oscaddr, oscargs, osctype, ref; l@271: address = (message != null ? message.address : void 0) != null ? message.address : message; l@271: if (typeof address !== "string") { l@271: throw new Error("message must contain an address"); l@271: } l@271: args = message != null ? message.args : void 0; l@271: if (args === void 0) { l@271: args = []; l@271: } l@271: if (!IsArray(args)) { l@271: old_arg = args; l@271: args = []; l@271: args[0] = old_arg; l@271: } l@271: oscaddr = exports.toOscString(address, strict); l@271: ref = toOscTypeAndArgs(args, strict), osctype = ref[0], oscargs = ref[1]; l@271: osctype = "," + osctype; l@271: allArgs = exports.concat(oscargs); l@271: osctype = exports.toOscString(osctype); l@271: return exports.concat([oscaddr, osctype, allArgs]); l@271: }; l@271: l@271: exports.toOscBundle = function(bundle, strict) { l@271: var allElems, buff, e, elem, elements, elemstr, error, j, len, oscBundleTag, oscElems, oscTimeTag, ref, ref1, size, timetag; l@271: if (strict && ((bundle != null ? bundle.timetag : void 0) == null)) { l@271: throw StrictError("bundles must have timetags."); l@271: } l@271: timetag = (ref = bundle != null ? bundle.timetag : void 0) != null ? ref : new Date(); l@271: elements = (ref1 = bundle != null ? bundle.elements : void 0) != null ? ref1 : []; l@271: if (!IsArray(elements)) { l@271: elemstr = elements; l@271: elements = []; l@271: elements.push(elemstr); l@271: } l@271: oscBundleTag = exports.toOscString("\#bundle"); l@271: oscTimeTag = exports.toTimetagBuffer(timetag); l@271: oscElems = []; l@271: for (j = 0, len = elements.length; j < len; j++) { l@271: elem = elements[j]; l@271: try { l@271: buff = exports.toOscPacket(elem, strict); l@271: size = exports.toIntegerBuffer(buff.length); l@271: oscElems.push(exports.concat([size, buff])); l@271: } catch (error) { l@271: e = error; l@271: null; l@271: } l@271: } l@271: allElems = exports.concat(oscElems); l@271: return exports.concat([oscBundleTag, oscTimeTag, allElems]); l@271: }; l@271: l@271: exports.toOscPacket = function(bundleOrMessage, strict) { l@271: if ((bundleOrMessage != null ? bundleOrMessage.oscType : void 0) != null) { l@271: if (bundleOrMessage.oscType === "bundle") { l@271: return exports.toOscBundle(bundleOrMessage, strict); l@271: } l@271: return exports.toOscMessage(bundleOrMessage, strict); l@271: } l@271: if (((bundleOrMessage != null ? bundleOrMessage.timetag : void 0) != null) || ((bundleOrMessage != null ? bundleOrMessage.elements : void 0) != null)) { l@271: return exports.toOscBundle(bundleOrMessage, strict); l@271: } l@271: return exports.toOscMessage(bundleOrMessage, strict); l@271: }; l@271: l@271: exports.applyMessageTranformerToBundle = function(transform) { l@271: return function(buffer) { l@271: var bundleTagBuffer, copyIndex, elem, elems, j, k, len, len1, lengthBuff, outBuffer, ref, string, timetagBuffer, totalLength; l@271: ref = exports.splitOscString(buffer), string = ref.string, buffer = ref.rest; l@271: if (string !== "\#bundle") { l@271: throw new Error("osc-bundles must begin with \#bundle"); l@271: } l@271: bundleTagBuffer = exports.toOscString(string); l@271: timetagBuffer = buffer.slice(0, 8); l@271: buffer = buffer.slice(8, buffer.length); l@271: elems = mapBundleList(buffer, function(buffer) { l@271: return exports.applyTransform(buffer, transform, exports.applyMessageTranformerToBundle(transform)); l@271: }); l@271: totalLength = bundleTagBuffer.length + timetagBuffer.length; l@271: for (j = 0, len = elems.length; j < len; j++) { l@271: elem = elems[j]; l@271: totalLength += 4 + elem.length; l@271: } l@271: outBuffer = new Buffer(totalLength); l@271: bundleTagBuffer.copy(outBuffer, 0); l@271: timetagBuffer.copy(outBuffer, bundleTagBuffer.length); l@271: copyIndex = bundleTagBuffer.length + timetagBuffer.length; l@271: for (k = 0, len1 = elems.length; k < len1; k++) { l@271: elem = elems[k]; l@271: lengthBuff = exports.toIntegerBuffer(elem.length); l@271: lengthBuff.copy(outBuffer, copyIndex); l@271: copyIndex += 4; l@271: elem.copy(outBuffer, copyIndex); l@271: copyIndex += elem.length; l@271: } l@271: return outBuffer; l@271: }; l@271: }; l@271: l@271: exports.applyTransform = function(buffer, mTransform, bundleTransform) { l@271: if (bundleTransform == null) { l@271: bundleTransform = exports.applyMessageTranformerToBundle(mTransform); l@271: } l@271: if (isOscBundleBuffer(buffer)) { l@271: return bundleTransform(buffer); l@271: } else { l@271: return mTransform(buffer); l@271: } l@271: }; l@271: l@271: exports.addressTransform = function(transform) { l@271: return function(buffer) { l@271: var ref, rest, string; l@271: ref = exports.splitOscString(buffer), string = ref.string, rest = ref.rest; l@271: string = transform(string); l@271: return exports.concat([exports.toOscString(string), rest]); l@271: }; l@271: }; l@271: l@271: exports.messageTransform = function(transform) { l@271: return function(buffer) { l@271: var message; l@271: message = exports.fromOscMessage(buffer); l@271: return exports.toOscMessage(transform(message)); l@271: }; l@271: }; l@271: l@271: IsArray = Array.isArray; l@271: l@271: StrictError = function(str) { l@271: return new Error("Strict Error: " + str); l@271: }; l@271: l@271: padding = function(str) { l@271: var bufflength; l@271: bufflength = Buffer.byteLength(str); l@271: return 4 - (bufflength % 4); l@271: }; l@271: l@271: isOscBundleBuffer = function(buffer, strict) { l@271: var string; l@271: string = exports.splitOscString(buffer, strict).string; l@271: return string === "\#bundle"; l@271: }; l@271: l@271: mapBundleList = function(buffer, func) { l@271: var e, elem, elems, j, len, nonNullElems, size, thisElemBuffer; l@271: elems = (function() { l@271: var error, ref, results; l@271: results = []; l@271: while (buffer.length) { l@271: ref = exports.splitInteger(buffer), size = ref.integer, buffer = ref.rest; l@271: if (size > buffer.length) { l@271: throw new Error("Invalid bundle list: size of element is bigger than buffer"); l@271: } l@271: thisElemBuffer = buffer.slice(0, size); l@271: buffer = buffer.slice(size, buffer.length); l@271: try { l@271: results.push(func(thisElemBuffer)); l@271: } catch (error) { l@271: e = error; l@271: results.push(null); l@271: } l@271: } l@271: return results; l@271: })(); l@271: nonNullElems = []; l@271: for (j = 0, len = elems.length; j < len; j++) { l@271: elem = elems[j]; l@271: if (elem != null) { l@271: nonNullElems.push(elem); l@271: } l@271: } l@271: return nonNullElems; l@271: }; l@271: l@271: }).call(this);