Skip to content

Commit

Permalink
Got up to a point where the node server serves up a config page and a…
Browse files Browse the repository at this point in the history
…cts as mediator between LiveOSC and Web.
  • Loading branch information
Andrew Hao committed Sep 22, 2011
1 parent 5a1a9f0 commit 300a4c7
Show file tree
Hide file tree
Showing 7 changed files with 610 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
-mmtss is a loop station built for live performances.
- mmtss is a loop station built for live performances.

It wraps Ableton around a Web wrapper using a Webkit view, backed by nodejs and
socket.io. Communication is done via LiveOSC
Expand Down
84 changes: 72 additions & 12 deletions app.js
@@ -1,26 +1,86 @@
// import module
// also req: jade
var osc = require('osc4node');
var express = require('express');
var sys = require('sys');

SERVER_PORT = 9000
CLIENT_PORT = 9001

SERVER_PORT = 9001
CLIENT_PORT = 9000

// create osc server and client
var oscServer = new osc.Server(SERVER_PORT, 'localhost')
, oscClient = new osc.Client('localhost', CLIENT_PORT);

debugger;
console.log('OSC Server set up, listening on port ' + SERVER_PORT);
console.log('OSC Client set up, listening on port ' + CLIENT_PORT);

// create osc message
var message = new osc.Message('/live/tempo', '123.00');
sys.puts("here");

// send
var message = new osc.Message('/live/time');
sys.puts("sending message" + sys.inspect(message));
oscServer.send(message, oscClient);
sys.puts("heree");

// oscServer dispatches 'oscmessage' event when receives the message.
// so we attach handler on the event for global message handling.
oscServer.on('oscmessage', function(msg, rinfo) {
console.log(msg);
var web = express.createServer();

web.configure(function(){
web.set('views', __dirname + '/views');
web.set('view engine', 'jade');
web.use(express.bodyParser());
web.use(express.methodOverride());
web.use(web.router);
web.use(express.static(__dirname + '/public'));
});

web.get('/', function(req, res) {
res.render('index', {
title: 'mmtss'
});
});

var io = require('socket.io').listen(web);
web.listen(3000, 'localhost');
console.log('Web server listening on %s:%d', 'localhost', 3000);

/**
* We define our own message syntax:
* {address {str}
* type {str: i|f|s|a
* args: [] tuples: [<val, type>]
*/
sendMessage = function(msg) {
var args = msg.args;
var address = msg.address;
var typ = msg.type;

var param = null;

if (typ == 'i') {
param = parseInt(args);
} else if (typ == 'f') {
param = parseFloat(args);
} else if (typ == 's') {
param = msg.args
}

var oscMsg = new osc.Message(address, param)
oscServer.send(oscMsg, oscClient);
};


io.sockets.on('connection', function(socket) {
sys.puts('Web browser connected');
socket.send('hey, you connected to me the server.');
socket.on('message', function(msg) {
sys.puts("receiving from browser: " + msg);
msg = JSON.parse(msg);
console.log('msg rcv from client was: ' + sys.inspect(msg));
sendMessage(msg);
});

oscServer.on('oscmessage', function(msg, rinfo) {
sys.puts(sys.inspect(msg));
//debugger;
socket.send('OSCMSG' + sys.inspect(msg));
});

});
18 changes: 18 additions & 0 deletions public/javascripts/jquery-1.6.1.min.js

Large diffs are not rendered by default.

0 comments on commit 300a4c7

Please sign in to comment.