Skip to content

Commit

Permalink
Track which deck is active on each side of the MC7000
Browse files Browse the repository at this point in the history
This is needed to handle the deck switching correctly (since we only
want to transfer shift state if the deck was actually switched, not if
the same deck's button has been pressed, since the latter would yield us
the same shift inversion bug again).
  • Loading branch information
fwcd committed May 12, 2022
1 parent 5c5caaa commit 08c0641
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions res/controllers/Denon-MC7000-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ MC7000.factor = [];
//Set Shift button state to false as default
MC7000.shift = [false, false, false, false];

// For each side whether the top or bottom deck is active.
MC7000.topDeckActive = [true, true];

// initialize the PAD Mode to Hot Cue and all others off when starting
MC7000.PADModeCue = [true, true, true, true];
MC7000.PADModeCueLoop = [false, false, false, false];
Expand Down Expand Up @@ -181,6 +184,10 @@ MC7000.init = function() {
engine.makeConnection("[Channel3]", "VuMeter", MC7000.VuMeter);
engine.makeConnection("[Channel4]", "VuMeter", MC7000.VuMeter);

// Switch to active decks
midi.sendShortMsg(MC7000.topDeckActive[0] ? 0x90 : 0x92, 0x08, 0x7F);
midi.sendShortMsg(MC7000.topDeckActive[1] ? 0x91 : 0x93, 0x08, 0x7F);

// Platter Ring LED mode
midi.sendShortMsg(0x90, 0x64, MC7000.modeSingleLED);
midi.sendShortMsg(0x91, 0x64, MC7000.modeSingleLED);
Expand Down Expand Up @@ -889,31 +896,34 @@ MC7000.crossFaderCurve = function(control, value) {

// Update state on deck changes
MC7000.switchDeck = function(channel, control, value, status, group) {
var deckOffset = script.deckFromGroup(group) - 1;
var isTopDeck = deckOffset < 2;
var side = deckOffset % 2;

var previousDeckOffset;
switch (deckOffset) {
case 0:
previousDeckOffset = 2;
break;
case 1:
previousDeckOffset = 3;
break;
case 2:
previousDeckOffset = 0;
break;
case 3:
previousDeckOffset = 1;
break;
}

// We need to 'transfer' the shift state when switching decks,
// otherwise it will get stuck and result in an 'inverted'
// shift after switching back to the deck.
// Since the controller switches immediately upon pressing down,
// we only do this when value is high.

if (value === 0x7F) {
var deckOffset = script.deckFromGroup(group) - 1;

var previousDeckOffset;
switch (deckOffset) {
case 0:
previousDeckOffset = 2;
break;
case 1:
previousDeckOffset = 3;
break;
case 2:
previousDeckOffset = 0;
break;
case 3:
previousDeckOffset = 1;
break;
}

if (value === 0x7F && MC7000.topDeckActive[side] !== isTopDeck) {
MC7000.topDeckActive[side] = isTopDeck;
MC7000.shift[deckOffset] = MC7000.shift[previousDeckOffset];
MC7000.shift[previousDeckOffset] = false;
}
Expand Down

0 comments on commit 08c0641

Please sign in to comment.