Skip to content

Instantly share code, notes, and snippets.

@pwhelan
Created May 30, 2012 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwhelan/2834120 to your computer and use it in GitHub Desktop.
Save pwhelan/2834120 to your computer and use it in GitHub Desktop.
DJTTMFPCUEMASTER-SLIPMODE
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// Remove a vlue from an array
Array.prototype.removeValue = function(value)
{
var idx = this.indexOf(value);
if (idx == -1)
return -1;
this.remove(idx, idx);
return idx;
}
DJTTCueMaster = {};
DJTTCueMaster.eq2control = function(eq)
{
switch(eq) {
case 'hi':
return 'filterHigh';
case 'mid':
return 'filterMid';
case 'low':
return 'filterLow';
case 'all':
default:
return 'pregain';
}
}
DJTTCueMasterStutter = function(deck, eq)
{
this.group = "[Channel" + deck + "]";
this.control = DJTTCueMaster.eq2control(eq);
this.ceiling = -1;
this.floor = 0.2;
this.timer = -1;
this.state = false;
this.deck = deck;
this.eq = eq;
this.process = function()
{
print("GROUP=" + this.group + " CONTROL=" + this.control);
var value = this.state ? this.ceiling : this.floor;
this.state = !this.state;
engine.setValue(this.group, this.control, value);
}
this.activate = function(step)
{
if (this.timer != -1)
return;
print("GROUP=" + this.group + " CONTROL=" + this.control);
this.ceiling = engine.getValue(this.group, this.control);
this.state = 0;
var bpm = engine.getValue(this.group, 'bpm');
var step = 4 * (Math.floor((step / 32))+1);
if ( step <= 0)
step = 0;
var interval = (((bpm/4) / 60) * 1000 / step);
this.timer = engine.beginTimer(interval, this.process);
}
this.deactivate = function()
{
if (this.timer==-1)
return;
engine.setValue(this.group, this.control, this.ceiling);
engine.stopTimer(this.timer);
this.timer = -1;
}
}
DJTTCueMaster.stutterActivate = function(deck, eq)
{
DJTTCueMaster.stutter[(deck-1)][eq].activate(DJTTCueMaster.slider[0]);
}
DJTTCueMaster.stutterDeactivate = function(deck, eq)
{
DJTTCueMaster.stutter[(deck-1)][eq].deactivate();
}
DJTTCueMaster.stutterHi = function(channel, control, value, status, group)
{
var deck = group == '[Channel1]' ? 1 : 2;
if (status == 0x90) {
DJTTCueMaster.stutterActivate(deck, 'hi');
}
else {
DJTTCueMaster.stutterDeactivate(deck, 'hi');
}
}
DJTTCueMaster.stutterMid = function (channel, control, value, status, group)
{
var deck = group == '[Channel1]' ? 1 : 2;
if (status == 0x90) {
DJTTCueMaster.stutterActivate(deck, 'mid');
}
else {
DJTTCueMaster.stutterDeactivate(deck, 'mid');
}
}
DJTTCueMaster.stutterLow = function (channel, control, value, status, group)
{
var deck = group == '[Channel1]' ? 1 : 2;
if (status == 0x90) {
DJTTCueMaster.stutterActivate(deck, 'low');
}
else {
DJTTCueMaster.stutterDeactivate(deck, 'low');
}
}
DJTTCueMaster.stutterAll = function (channel, control, value, status, group)
{
var deck = group == '[Channel1]' ? 1 : 2;
if (status == 0x90) {
DJTTCueMaster.stutterActivate(deck, 'all');
}
else {
DJTTCueMaster.stutterDeactivate(deck, 'all');
}
}
DJTTCueMaster.init = function()
{
DJTTCueMaster.bstk = new Array();
DJTTCueMaster.beatloop = 0;
DJTTCueMaster.stutter = [
{
hi: new DJTTCueMasterStutter(1, 'hi'),
mid: new DJTTCueMasterStutter(1, 'mid'),
low: new DJTTCueMasterStutter(1, 'low'),
all: new DJTTCueMasterStutter(1, 'all')
},
{
hi: new DJTTCueMasterStutter(2, 'hi'),
mid: new DJTTCueMasterStutter(2, 'mid'),
low: new DJTTCueMasterStutter(2, 'low'),
all: new DJTTCueMasterStutter(2, 'all')
}
];
DJTTCueMaster.slider = [ 0, 0 ];
DJTTCueMaster.slipmodetime = {};
DJTTCueMaster.slipmodeconnect = {};
print("DJ Techtools MIDI Fighter PRO CueMaster initialized");
}
DJTTCueMaster.beatloop1 = function (channel, control, value, status, group)
{
DJTTCueMaster.beatloopInt(group, (status&0x90)==0x90, 1);
}
DJTTCueMaster.beatloop05 = function (channel, control, value, status, group)
{
DJTTCueMaster.beatloopInt(group, (status&0x90)==0x90, 0.5);
}
DJTTCueMaster.beatloop025 = function (channel, control, value, status, group)
{
DJTTCueMaster.beatloopInt(group, (status&0x90)==0x90, 0.25);
}
DJTTCueMaster.beatloop0125 = function (channel, control, value, status, group)
{
DJTTCueMaster.beatloopInt(group, (status&0x90)==0x90, 0.125);
}
DJTTCueMaster.beatcheck = function(first, second, third, fourth)
{
if (this.bstk[0] == first && this.bstk[1] == second && this.bstk[2] == third && this.bstk[3] == fourth)
return true;
return false;
}
DJTTCueMaster.beatloopInt = function(group, on, beats)
{
if (on) {
if (this.bstk.length == 0) {
var slipmodestatus = {
rate: engine.getValue(group, 'rate'),
startplaypos: engine.getValue(group, 'playposition'),
curplaypos: engine.getValue(group, 'playposition')
};
var slipmodegroup = group;
DJTTCueMaster.slipmodetime[group] = engine.getValue(group, 'playposition');
DJTTCueMaster.slipmodeconnect[group] = engine.connectControl(group, 'playposition',
function(value) {
try {
if (value > slipmodestatus.curplaypos) {
DJTTCueMaster.slipmodetime[slipmodegroup] += value - slipmodestatus.curplaypos;
}
else {
DJTTCueMaster.slipmodetime[slipmodegroup] += value - slipmodestatus.startplaypos;
DJTTCueMaster.slipmodetime[slipmodegroup] += (engine.getValue(slipmodegroup, 'loop_end_position') / engine.getValue(group, 'track_samples')) - slipmodestatus.curplaypos;
}
slipmodestatus.curplaypos = value;
}
catch(e) {
print("ERROR = " + e.message);
}
}
);
}
this.bstk.push(beats);
if (this.bstk.length == 4) {
if (this.beatcheck(1, 0.5, 0.25, 0.125)) {
engine.setValue(group, 'beatloop', 0.0625);
}
else {
engine.setValue(group, 'beatloop', beats);
}
}
else {
engine.setValue(group, 'beatloop', beats);
}
}
else {
this.bstk.removeValue(beats);
if (this.bstk.length > 0) {
this.beatloop = this.bstk[(this.bstk.length - 1)];
engine.setValue(group, 'beatloop', this.beatloop);
}
else {
var oldout = engine.getValue(group, 'loop_end_position') / engine.getValue(group, 'track_samples');
engine.setValue(group, 'reloop_exit', 1);
var cb = this.slipmodeconnect[group];
// CO commands are evaluated as simple bit flips on a list of objects
// they are always processed in the same order, regardless of when the actual
// change occurs. We use a timer to make sure we are executed well after the
// reloop_exit is set.
engine.beginTimer(20, function() {
cb.disconnect();
engine.setValue(group, 'playposition', DJTTCueMaster.slipmodetime[group]);
}, true);
}
}
}
DJTTCueMaster.sliderControl1 = function(channel, control, value, status, group)
{
DJTTCueMaster.slider[0] = value;
}
DJTTCueMaster.sliderControl2 = function(channel, control, value, status, group)
{
DJTTCueMaster.slider[1] = value;
}
DJTTCueMaster.reverse1 = function(channel, control, value, status, group)
{
engine.setValue(group, 'reverse', (status==0x90));
}
DJTTCueMaster.reverse125 = function(channel, control, value, status, group)
{
engine.setValue(group, 'reverse', (status==0x90));
}
DJTTCueMaster.reverse15 = function(channel, control, value, status, group)
{
engine.setValue(group, 'reverse', (status==0x90));
}
DJTTCueMaster.reverse2 = function(channel, control, value, status, group)
{
engine.setValue(group, 'reverse', (status==0x90));
}
DJTTCueMaster.flanger = function(channel, control, value, status, group)
{
engine.setValue(group, 'flanger', (status==0x90));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment