Created
March 3, 2012 20:43
-
-
Save nulltask/1968092 to your computer and use it in GitHub Desktop.
OSC over HTTP example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
.DS_Store | |
._* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var express = require('express') | |
, routes = require('./routes'); | |
var app = module.exports = express.createServer() | |
, io = require('./io')(app); | |
// Configuration | |
app.configure(function() { | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
}); | |
app.get('/', routes.index); | |
app.listen(process.env.PORT || 3000); | |
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Connect to Socket.IO. | |
*/ | |
var socket = io.connect(); | |
document.addEventListener('DOMContentLoaded', function(e) { | |
document.addEventListener('mousemove', function(e) { | |
var percentage = Math.round((e.x / window.outerWidth) * 100); | |
socket.emit('/wtf', percentage); | |
}); | |
document.addEventListener('touchmove', function(e) { | |
var percentage = Math.round((e.touches[0].pageX / window.outerWidth) * 100); | |
socket.emit('/wtf', percentage); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'deploy' | |
# Uncomment if you are using Rails' asset pipeline | |
# load 'deploy/assets' | |
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OSC over HTTP example | |
// https://gist.github.com/1968092 | |
( | |
n = NetAddr("vps.null.ly", 11000); | |
n.sendMsg('/hello'); | |
( | |
o = OSCresponder(n, '/wtf', { |t, r, msg| | |
var s = { SinOsc.ar(20 * msg[1], 0, 0.1 * EnvGen.ar(Env.perc(0, 1), doneAction:2)) }; | |
msg[1].postln; | |
Out.ar(1, s.play); | |
}).add; | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :ident, "osc-over-http-example" | |
set :user, "nulltask" | |
set :application, "#{ident}" | |
set :repository, "git://gist.github.com/1968092.git" | |
set :scm, :git | |
set :branch, "master" | |
set :scm_verbose, true | |
set :deploy_to, "/home/#{user}/app/#{application}" | |
set :deploy_via, :copy | |
set :git_shallow_clone, 1 | |
set :node_env, 'production' | |
set :node_port, 4126 | |
set :default_environment, { | |
'PATH' => "~/.nave/installed/0.6.12/bin:$PATH" | |
} | |
role :web, "vps.null.ly" | |
role :app, "vps.null.ly" | |
namespace :deploy do | |
task :start, :roles => :app do | |
run "NODE_ENV=#{node_env} PORT=#{node_port} forever start #{current_path}/app.js" | |
end | |
task :stop, :roles => :app do | |
run "forever stop #{current_path}/app.js" | |
end | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "NODE_ENV=#{node_env} PORT=#{node_port} forever restart #{current_path}/app.js" | |
end | |
end | |
after "deploy:create_symlink", :roles => :app do | |
run "ln -svf #{shared_path}/node_modules #{current_path}/node_modules" | |
run "cd #{current_path} && npm install" | |
end | |
after "deploy:setup", :roles => :app do | |
run "mkdir -p #{shared_path}/node_modules" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1= title | |
p Move your mouse or swipe your iPhone! | |
p | |
a(href='/client.scd') Download SuperCollider client code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GET home page. | |
*/ | |
exports.index = function(req, res){ | |
res.render('index', { title: 'OSC Over HTTP Example' }); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var socket = require('socket.io') | |
, osc = require('osc4node') | |
, server = new osc.Server(11000, '0.0.0.0') | |
, clients = []; | |
module.exports = function(app) { | |
/** | |
* Listen websocket. | |
*/ | |
var io = socket.listen(app); | |
/** | |
* Handle web clients connection. | |
*/ | |
io.sockets.on('connection', function(client) { | |
client.on('/wtf', function() { | |
var args = Array.prototype.slice.call(arguments) | |
, message = new osc.Message('/wtf', args); | |
clients.forEach(function(client) { | |
server.send(message, client); | |
}); | |
}); | |
}); | |
/** | |
* Handle OSC receivers connection. | |
*/ | |
server.on('oscmessage', function(msg, rinfo) { | |
if (msg.address === '/hello') { | |
clients.push(new osc.Client(rinfo.address, rinfo.port)); | |
} | |
}); | |
return io; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! | |
html | |
head | |
title= title | |
link(rel='stylesheet', href='/stylesheets/style.css') | |
script(src='/socket.io/socket.io.js') | |
script(src='/javascripts/app.js') | |
body!= body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "osc-over-http-example" | |
, "version": "0.0.1" | |
, "private": true | |
, "dependencies": { | |
"express": "2.5.8" | |
, "jade": ">= 0.0.1" | |
, "stylus": ">= 0.0.1" | |
, "socket.io": "*" | |
, "osc4node": "https://github.com/nulltask/osc4node/tarball/bug/encode" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
padding: 50px; | |
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | |
} | |
a { | |
color: #00B7FF; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Online demo:
http://vps.null.ly:4126/
Related forum post:
http://supercollider.jp/modules/xhnewbb/viewtopic.php?topic_id=280&viewmode=thread
Network layout:
https://cacoo.com/diagrams/9pMGjkYT9EhlljvC-2B232.png