Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
19 js/gibber/environment.js
View
@@ -45,6 +45,8 @@ Gibber.Environment = {
},
master : function() {
+ $("#info").html("");
+
Gibber.Environment.masterSocket = io.connect('http://localhost:8080/');
Gibber.Environment.masterSocket.on('connect', function () {
Gibber.Environment.Editor.selectAll();
@@ -54,23 +56,20 @@ Gibber.Environment = {
Gibber.Environment.sessionHistory = [];
Gibber.Environment.Editor.clearSelection();
Gibber.Environment.masterSocket.on('code', function (msg) {
- //Gibber.Environment.Editor.insert("/************** from " + msg.userName + " at " + (new Date()).toTimeString() + " ************/\n\n");
Gibber.Environment.Editor.insert(msg.code + "\n");
Gibber.Environment.sessionHistory.push( { code: msg.code + "\n", time: new Date() - Gibber.Environment.sessionStart} );
G.log(Gibber.Environment.sessionHistory);
Gibber.Environment.Editor.scrollPageDown();
Gibber.callback.addCallback(msg.code, _1);
- //Gibber.runScript(msg.code + "\n\n");
});
- // Gibber.Environment.masterSocket.on('code_immediate', function (msg) {
- // Gibber.Environment.Editor.insert("/************** from " + msg.userName + " at " + (new Date()).toTimeString() + " ************/\n\n");
- // Gibber.Environment.Editor.insert(msg.code + "\n\n");
- // Gibber.Environment.Editor.scrollPageDown();
- //
- // Gibber.callback.runScript(msg.code);
- // //Gibber.runScript(msg.code + "\n\n");
- // });
+ Gibber.Environment.masterSocket.on('chat', function(msg) {
+ var p = $("<p>");
+ $(p).css("padding", "0px 10px");
+ $(p).html("<h2 style='display:inline'>"+msg.user+" :</h2>" + " " + msg.text);
+ $("#info").append(p);
+ $("#info").scrollTop( $("#info").height() );
+ });
Gibber.Environment.masterSocket.emit('master', null);
});
55 js/gibber/sequence.js
View
@@ -84,7 +84,6 @@ function Seq() {
this.mix = 1; // needed for modding because the value of the gen is multiplied by this, should never be changed
var that = this;
-
if(typeof arguments[0] === "object" && $.isArray(arguments[0]) === false) {
var obj = arguments[0];
for(key in obj) {
@@ -101,7 +100,6 @@ function Seq() {
}
this.sequence = _seq;
}
-
if(this.speed === null && this.durations === null) {
var arg1Type = typeof arguments[1];
if(arg1Type !== "undefined") {
@@ -119,11 +117,9 @@ function Seq() {
}
}
}
-
this.outputMessage = arguments[2] || "note";
Gibber.registerObserver( "bpm", this.bpmCallback(this) );
-
if(this.sequence != null && typeof this.sequence != "undefined") {
this.setSequence(this.sequence, this.speed);
}
@@ -144,7 +140,6 @@ function Seq() {
this.slavesInit = true;
}
}
-
this.setParam = function(param, _value){
this[param] = _value;
};
@@ -175,7 +170,6 @@ function Seq() {
}
return that;
};
-
Gibber.addModsAndFX.call(this);
}
@@ -187,9 +181,17 @@ Seq.prototype = {
// run the current event and schedule the next one. This is called automatically by the master clock if a sequencer is added to the Gibber.callback.slaves array.
advance : function() {
if(this.active) {
- var pos = this.counter % this.sequence.length;
- var val = this.sequence[pos];
-
+ var pos, val;
+ var usePick = (typeof this.sequence.pick !== "undefined");
+ if(!usePick) {
+ pos = this.counter % this.sequence.length;
+ }
+ if(!usePick) {
+ val = this.sequence[pos];
+ }else{
+ val = this.sequence.pick();
+ }
+
// only play if not setting an offset... if using offset simply set original offset position
var shouldReturn = false;
var nextPhase = 0;
@@ -200,10 +202,27 @@ Seq.prototype = {
shouldReturn = true;
// only use duration with negative offset
- if(this.offset < 0)
- nextPhase += (this.durations != null) ? this.durations[this.durationCounter % this.durations.length] : this.speed;
+ if(this.offset < 0) {
+ if(this.durations != null) {
+ if(this.durations.pick != null) {
+ nextPhase += this.durations.pick();
+ }else{
+ nextPhase +=this.durations[this.durationCounter % this.durations.length]
+ }
+ }else{
+ nextPhase += this.speed;
+ }
+ }
}else{
- nextPhase += (this.durations != null) ? this.durations[this.durationCounter % this.durations.length] : this.speed;
+ if(this.durations != null) {
+ if(this.durations.pick != null) {
+ nextPhase += this.durations.pick();
+ }else{
+ nextPhase += this.durations[this.durationCounter % this.durations.length]
+ }
+ }else{
+ nextPhase += this.speed;
+ }
}
// TODO: should this flip-flop between floor and ceiling instead of rounding?
nextPhase = Math.round(nextPhase);
@@ -256,7 +275,7 @@ Seq.prototype = {
this.counter++;
this.durationCounter++;
- if(this.counter % this.sequence.length === 0) {
+ if(!usePick && this.counter % this.sequence.length === 0) {
if(this.shouldDie) {
this.kill();
}
@@ -320,13 +339,16 @@ Seq.prototype = {
var _c = seq.charAt(c);
this.sequence.push(_c);
}
- }else{
+ }else if ($.isArray(seq) && typeof seq.pick === "undefined"){
for(var i = 0; i < seq.length; i++) {
var n = seq[i];
this.sequence[i] = n;
}
+ }else{
+ G.log("ASSIGNED CORRECTLY");
+ this.sequence = seq;
}
- if(this.init === false && !this.doNotAdvance) {
+ if(this.init === false && !this.doNotAdvance && typeof seq.pick === "undefined") {
this._sequence = this.sequence.slice(0);
//Gibber.callback.slaves.push(this);
if(typeof this.sequence[0] === "function"){
@@ -368,7 +390,8 @@ Seq.prototype = {
if(!this.slavesInit) {
this.advance();
this.slavesInit = true;
- this._sequence = this.sequence.slice(0);
+ if(typeof this.sequence.pick !== "undefined")
+ this._sequence = this.sequence.slice(0);
} // start sequence if it's not already running
}
return this;
26 js/gibber/utilities.js
View
@@ -216,6 +216,32 @@ window.rndf = window.randomf = function(min, max) {
return min + rr;
}
+/* returns function that randomly picks from an array using the provided weights. Example:
+a = [1,2,3,4]
+a.pick = weight([.5,.25,.1,.15])
+a.pick();
+
+TODO: Figure out an algorithm(s) to automatically create weights with different schemes
+*/
+window.weight = function(weights) {
+ var w = weights;
+ var returnValue = this[0];
+ function pick() {
+ var total = 0;
+ var r = rndf();
+ for(var i = 0; i < w.length; i++) {
+ total += w[i];
+ if(r < total) {
+ returnValue = this[i];
+ break;
+ }
+ }
+ return returnValue;
+ }
+
+ return pick;
+}
+
window.getSpeed = function(div) {
return window["_"+div];
};

No commit comments for this range

Something went wrong with that request. Please try again.