Skip to content

Commit

Permalink
merged OSC branch into master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dktr0 committed Jul 12, 2015
2 parents 70e09b0 + ab3f5fa commit d181195
Show file tree
Hide file tree
Showing 17 changed files with 814 additions and 163 deletions.
92 changes: 82 additions & 10 deletions .ghci
Original file line number Diff line number Diff line change
@@ -1,13 +1,85 @@
import Sound.Tidal.Context
d1 <- dirtStream
d2 <- dirtStream
d3 <- dirtStream
d4 <- dirtStream
d5 <- dirtStream
d6 <- dirtStream
d7 <- dirtStream
d8 <- dirtStream
d9 <- dirtStream
d10 <- dirtStream

(cps, getNow) <- bpsUtils

let vis = dirt {timestamp = NoStamp, latency = 0.04}

vs1 <- stream "127.0.0.1" 8000 vis
ds1 <- dirtStream
let d1 p = vs1 p >> ds1 p

vs2 <- stream "127.0.0.1" 8000 vis
ds2 <- dirtStream
let d2 p = vs2 p >> ds2 p

vs3 <- stream "127.0.0.1" 8000 vis
ds3 <- dirtStream
let d3 p = vs3 p >> ds3 p

vs4 <- stream "127.0.0.1" 8000 vis
ds4 <- dirtStream
let d4 p = vs4 p >> ds4 p

vs5 <- stream "127.0.0.1" 8000 vis
ds5 <- dirtStream
let d5 p = vs5 p >> ds5 p

vs6 <- stream "127.0.0.1" 8000 vis
ds6 <- dirtStream
let d6 p = vs6 p >> ds6 p

vs7 <- stream "127.0.0.1" 8000 vis
ds7 <- dirtStream
let d7 p = vs7 p >> ds7 p

vs8 <- stream "127.0.0.1" 8000 vis
ds8 <- dirtStream
let d8 p = vs8 p >> ds8 p

vs9 <- stream "127.0.0.1" 8000 vis
ds9 <- dirtStream
let d9 p = vs9 p >> ds9 p

vs10 <- stream "127.0.0.1" 8000 vis
ds10 <- dirtStream
let d10 p = vs10 p >> ds10 p

vs11 <- stream "127.0.0.1" 8000 vis
ds11 <- dirtStream
let d11 p = vs11 p >> ds11 p

vs12 <- stream "127.0.0.1" 8000 vis
ds12 <- dirtStream
let d12 p = vs12 p >> ds12 p

vs13 <- stream "127.0.0.1" 8000 vis
ds13 <- dirtStream
let d13 p = vs13 p >> ds13 p

vs14 <- stream "127.0.0.1" 8000 vis
ds14 <- dirtStream
let d14 p = vs14 p >> ds14 p

vs15 <- stream "127.0.0.1" 8000 vis
ds15 <- dirtStream
let d15 p = vs15 p >> ds15 p

vs16 <- stream "127.0.0.1" 8000 vis
ds16 <- dirtStream
let d16 p = vs16 p >> ds16 p

vs17 <- stream "127.0.0.1" 8000 vis
ds17 <- dirtStream
let d17 p = vs17 p >> ds17 p

vs18 <- stream "127.0.0.1" 8000 vis
ds18 <- dirtStream
let d18 p = vs18 p >> ds18 p

vs19 <- stream "127.0.0.1" 8000 vis
ds19 <- dirtStream
let d19 p = vs19 p >> ds19 p

vs20 <- stream "127.0.0.1" 8000 vis
ds20 <- dirtStream
let d20 p = vs20 p >> ds20 p
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
jquery*
#*
*~
149 changes: 122 additions & 27 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,130 @@
function postSignal(name) {
var password = document.getElementById('password').value;
if(password == null || password == "") {
alert("You must enter a password to evaluate code.");
}
else {
$.post(name + "-" + password, function(x) {});
}
var ws;

function Osc() {}
jQuery.extend(Osc.prototype,jQuery.eventEmitter);
var osc = new Osc();

function setup() {
window.WebSocket = window.WebSocket || window.MozWebSocket;
var url = 'ws://' + location.hostname + ':8002';
console.log("attempting websocket connection to " + url);
ws = new WebSocket(url);
ws.onopen = function () {
console.log("extramuros websocket connection opened");
};
ws.onerror = function () {
console.log("ERROR opening extramuros websocket connection");
};
ws.onmessage = function (m) {
var data = JSON.parse(m.data);
if(data.type == 'osc') {
var address = data.address.substring(1);
// Tidal-specific double-mappings for incoming /play messages
if(address == "play") {
data.args.name = data.args[1];
data.args.begin = data.args[3];
data.args.end = data.args[4];
data.args.speed = data.args[5];
data.args.pan = data.args[6];
data.args.gain = data.args[14];
}
$(osc).trigger(address);
eval( address + "(data.args)");
// ummm... we should check to make sure the function exists first!...
}
if(data.type == 'js') {
eval(data.code);
}
if(data.type == 'feedback') {
var fb = $('#feedback');
var oldText = fb.val();
if(oldText.length > 10000) oldText = ""; // short-term solution...
fb.val(oldText+data.text);
fb.scrollTop(fb[0].scrollHeight);
}
};
for(var x=1;x<=20;x++) openEditor('edit' + x.toString());
setupKeyboardHandlers();
setupVisuals();
}

function openEditor(name) {
sharejs.open(name,'text',function(error,doc) {
if(error) console.log(error);
else {
var elem = document.getElementById(name);
elem.disabled = false;
doc.attach_textarea(elem);

function getPassword() {
var x = document.getElementById('password').value;
if(x == null || x == "") {
alert("You must enter a password to evaluate code.");
return null;
}
});
return x;
}

function setup() {
openEditor('edit1');
openEditor('edit2');
openEditor('edit3');
openEditor('edit4');
openEditor('edit5');
openEditor('edit6');
openEditor('edit7');
openEditor('edit8');
openEditor('edit9');
openEditor('chat');
function evaluateBuffer(name) {
var password = getPassword();
if(password) {
var msg = { request: "eval", bufferName: name, password: password };
ws.send(JSON.stringify(msg));
}
}

function evaluateJavaScriptGlobally(code) {
var password = getPassword();
if(password) {
var msg = { request: "evalJS", code: code, password: password };
ws.send(JSON.stringify(msg));
}
}

function openEditor(name) {
var elem = document.getElementById(name);
if( elem != null) {
sharejs.open(name,'text',function(error,doc) {
if(error) console.log(error);
else {
elem.disabled = false;
doc.attach_textarea(elem);
}
});
}
}

function setupKeyboardHandlers() {
$('textarea').keydown(function (event) {
if(event.which == 13 && event.shiftKey && event.ctrlKey) {
// ctrl+shift+enter: evaluate buffer as Javascript through server
event.preventDefault();
var code = $(this).val();
evaluateJavaScriptGlobally(code);
}
else if(event.which == 13 && event.ctrlKey) {
// ctrl+Enter: evaluate text as JavaScript in local browser
event.preventDefault();
var code = $(this).val();
eval(code);
}
else if(event.which == 13 && event.shiftKey) {
// shift+Enter: evaluate buffer globally through the server
event.preventDefault();
evaluateBuffer(event.target.id);
}
else if(event.which == 67 && event.ctrlKey && event.shiftKey) {
// ctrl+shift+c: global clear() on visuals
event.preventDefault();
evaluateJavaScriptGlobally("clear();");
}
else if(event.which == 82 && event.ctrlKey && event.shiftKey) {
// ctrl+shift+r: global retick() on visuals
event.preventDefault();
evaluateJavaScriptGlobally("retick();");
}
else if(event.which == 67 && event.altKey) {
// alt+c: global clear() on visuals
event.preventDefault();
evaluateJavaScriptGlobally("clear();");
}
else if(event.which == 82 && event.altKey) {
// alt+r: global retick() on visuals
event.preventDefault();
evaluateJavaScriptGlobally("retick();");
}
});
}
Loading

0 comments on commit d181195

Please sign in to comment.