Skip to content

Commit

Permalink
add osc status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
respectTheCode committed Apr 16, 2016
1 parent fd5f741 commit f7908f6
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 7 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,42 @@ For now docs are in the source only.

var CasparCG = require("caspar-cg");

ccg = new CasparCG("localhost", 5250);
ccg.connect(function () {
ccg.info(function (err, serverInfo) {
ccg = new CasparCG({
host: "localhost",
port: 5250,
debug: true,
osc: true, // osc status updates are opt in
oscThrottle: 250 // throttles status updates in ms
});

ccg.connect(() => {
ccg.info((err, serverInfo) => {
console.log(serverInfo);
});

ccg.play("1-1", "AMB");
ccg.loadTemplate("1-20", "NTSC-TEST-60", true);

setTimeout(function () {
setTimeout(() => {
ccg.clear("1");
ccg.disconnect();
}, 10 * 1000);
}, 60 * 1000);
});

ccg.on("connected", function () {
ccg.on("connected", () => {
console.log("Connected");
});

## Changelog
// must opt in to osc
ccg.on("status", status => {
console.log(JSON.stringify(status));
});

## Change log

###v0.1.1

* Adds OSC Status updates

### v0.1.0

Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var ccg = module.exports = function (host, port) {
this.options.port = port;
}

// osc server
require("./lib/osc")(this);

this.index = count++;
};

Expand All @@ -29,6 +32,9 @@ ccg.prototype.options = {
reconnect: true,
host: "localhost",
port: 5250,
osc: false,
oscPort: 6250,
oscThrottle: 250,
debug: false
};

Expand Down
144 changes: 144 additions & 0 deletions lib/osc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"use strict";

const osc = require("node-osc");
const _ = require("underscore");

module.exports = function (ccg) {
if (!ccg.options.osc) return;

const oscServer = new osc.Server(ccg.options.oscPort, "0.0.0.0");

const channels = {};

let emit = ccg.emit.bind(ccg);

if (ccg.options.oscThrottle) {
emit = _.throttle(emit, ccg.options.oscThrottle);
}

oscServer.on("message", function (msg, rinfo) {
try {
msg.shift(); // bundle
msg.shift(); // number?

let message;
while (msg.length > 0) {
message = msg.shift();
parseMessage(message[0], message[1]);
}

emit("status", channels);
} catch (err) {
ccg.log("OSC Parsing Error", err);
}
});

function parseMessage(message, value) {
const parts = message.split("/");
parts.shift();

if (parts.length <= 0) return console.log("too short", parts);
if (parts[0] !== "channel") return console.log("not channel", parts);

const channel = channels[parts[1]] = channels[parts[1]] || {
layers: {},
audioChannels: {}
};

if (parts[2] === "stage") {
if (parts[3] === "layer") {
if (parts.length < 6) return console.log("too short", parts);
const layer = channel.layers[parts[4]] = channel.layers[parts[4]] || {};

switch (parts[5]) {
case "time":
layer.time = value;
return;
case "frame":
layer.frame = value;
return;
case "type":
layer.type = value;
return;
case "paused":
layer.paused = value;
return;
case "buffer":
layer.buffer = value;
return;
case "loop":
layer.loop = value;
return;
case "profiler":
switch (parts[6]) {
case "time":
layer.profiler = {time: value};
return;
}
return;
case "host":
const host = layer.host = layer.host || {};
switch (parts[6]) {
case "width":
host.width = value;
return;
case "height":
host.height = value;
return;
case "path":
if (value.indexOf("\\\\") >= 0) {
value = value.split("\\\\")[1];
}

host.path = value;
return;
case "fps":
host.fps = value;
return;
}
break;
case "file":
const file = layer.file = layer.file || {};
switch (parts[6]) {
case "time":
file.time = value;
return;
case "frame":
file.frame = value;
return;
case "fps":
file.fps = value;
return;
case "path":
file.path = value;
return;
case "loop":
file.loop = value;
return;
}
break;
}
}
}

if (parts[2] === "mixer") {
if (parts[3] === "audio") {
if (parts[4] === "nb_channels") {
channel.nbChannels = value;
return;
}

const audioChannel = channel.audioChannels[parts[4]] = channel.audioChannels[parts[4]] || {};

switch (parts[5]) {
case "pFS":
audioChannel.pFS = value;
return;
case "dBFS":
audioChannel.dBFS = value;
return;
}
}
}
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test": "grunt mochaTest"
},
"dependencies": {
"node-osc": "git+ssh://[email protected]/respectTheCode/node-osc.git",
"underscore": "~1.8.3",
"sax": "~1.1.1"
},
Expand Down

0 comments on commit f7908f6

Please sign in to comment.