I don't know JS-Akai MPK 2xx

Post Reply New Topic
RELATED
PRODUCTS

Post

I'm using a modified version, by one josephlarson, of the script found here: https://www.bitwig.com/en/community/con ... 1_249.html

The modified version is here: https://github.com/joelarson/mpk261-bitwig

Basically I want to know if it's possible implement a follow MIDI input function so when I hit a pad on the hardware the Drum Machine in Bitwig updates to the last pad I hit like an Ableton's Drum Racks. In other words, it selects it as if I were selecting it with the mouse thus displaying the chain following that particular pad.

Also, there's something funky in the script. I'll try and explain. When using the Drum Machine and adding samples the hardware will show where the samples are by lighting up that pad. That's cool and useful, but if I leave the Drum Machine track and come back to it all the pads light up to the color of the track (give or take due to the limited amount of colors), I realize this is part of the script when selecting a track in general. If I add another sample to Drum Machine, it will light up that pad alone leaving the rest dark, even if other pads have samples on them already. Ideally, if I return to a track with a Drum Machine on it, only the pads with samples should light up. Adding another sample would simply update the pads to reflect Drum Machine. Is this possible?

If for whatever reason no one can help, where can I look into this without learning JS over the next year? :wink:

The js files are:

MPK2_common.js
MPK2_PadClipLaunch.js
MPK2_PadInstrument.js
MPK2_PadSceneLaunch.js
MPK261.control.js

If it helps, this is what is on the "MPK2_PadInstrument.js". I'm assuming this where I'd be looking to add or fix things but I actually don't know. Script linked above.

Code: Select all

PadInstrument = new PadMode();

PadInstrument.handleMIDI = function(data1,data2) {
    
}

PadInstrument.handleNavKeys = function (data1) {
    if (data1 == NAVKeys.LEFT) {
        shifted ? cursorTrack.selectPrevious() : cursorDevice.selectPrevious();
    }
    
    else if (data1 == NAVKeys.RIGHT) {
        shifted ? cursorTrack.selectNext() : cursorDevice.selectNext();
    }
    else if (data1 == NAVKeys.UP) {
        shifted ? cursorDevice.switchToNextPreset() : cursorDevice.nextParameterPage();
        
    }
    else if (data1 == NAVKeys.DOWN) {
        shifted ? cursorDevice.switchToPreviousPreset() : cursorDevice.previousParameterPage() ;
    }
}

PadInstrument.init = function() {
    if (displayHelpText) {
        host.showPopupNotification("Pads: Instrument/Drum Rack Mode");
    }

    usingDrumMachine ? PadInstrument.lightPadsForDrumRack(CursorTrackColor) : lightAllPads(CursorTrackColor,"Off");
    PadNotes.setKeyTranslationTable(PadMIDITable.ON);    
}

PadInstrument.cursorTrackColorObs = function(red,green,blue) {
    PadMode.prototype.cursorTrackColorObs(red,green,blue);

    if (usingDrumMachine) {
        PadInstrument.lightPadsForDrumRack (CursorTrackColor);
    }
    
    else {
        lightAllPads(CursorTrackColor,"Off");
    }
}


PadInstrument.cursorTrackInstrumentNameObs = function(track,text) {
    PadMode.prototype.cursorTrackInstrumentNameObs(track,text);
    usingDrumMachine ? PadInstrument.lightPadsForDrumRack(CursorTrackColor) : lightAllPads(CursorTrackColor,"Off");
}

PadInstrument.lightPadsForDrumRack = function(color) {
    padIdent = minimumPadOff;
    var MidiOut = "F0 47 00 " + uint7ToHex(PRODUCT_ID) + " 31 00 43 40 " + uint7ToHex(getMSB(padIdent)) + " " + uint7ToHex(getLSB(padIdent));
    for (var x = 36; x < 100; x++ ) {
        if (drumKeys[x] == false) {
            MidiOut+= " " + uint7ToHex(padColors['Off']);
        }
        else {
            MidiOut+= " " + uint7ToHex(color);
        }
    }
    MidiOut+= " F7";
    host.getMidiOutPort(1).sendSysex(MidiOut);
}

PadInstrument.cursorTrackpitchObs = function(key,name) {
    PadMode.prototype.cursorTrackpitchObs(key,name);
    PadInstrument.lightPadsForDrumRack(CursorTrackColor)
}
Last edited by JHernandez on Sat Feb 10, 2018 8:21 pm, edited 1 time in total.
-JH

Post

Bigwig allows you to choose from a color palette to set your track to.


var bitwigColor = { Dark_Grey : [0.3294.toFixed(4),0.3294.toFixed(4),0.3294.toFixed(4)],

is followed by a unique line for every color in the script like:

Light_Grey : [0.4784.toFixed(4),0.4784.toFixed(4),0.4784.toFixed(4)],

. . and so on. Where do these numbers come from? Surely there is a way to look these up, right? I'm looking through the Scripting Guide and Control Surface API documentation and it just confuses me further. They're not listed in there as far as I can tell. They don't look like any color codes I've ever seen before, that's for sure, so they must be unique ID’s specific to Bigwigs color palette, no?

Then this:

function bitwigColorToPadColor(rgbInput) {

follow by a bunch of these for each color again:

if (areArraysEqual(rgbInput,bitwigColor['Dark_Grey']) == true) { return padColors['Grey']; }
else if (areArraysEqual(rgbInput,bitwigColor['Light_Grey']) == true) { return padColors['Grey']; }


. . . and so on

Seems to me that the first set of lines define a set of “labels” with unique ID’s (?) and the next set are instructions what to do if the track color is set to, say Dark Grey, in this case telling my controller to turn the pads Grey as per the { return padColors['Grey']; } instruction, and that's what they do. Am I right? Somewhat?


There's also a section like so:

/* MPK2 Pad Color Identifiers */ <---- (I'm assuming this is a note)
const padColors = {
Off:0x00,
Red:0x01,

. . . and so on for each color the hardware is capable of. Again, where do these numbers come from? There’s no list I can find.

From what I gather these lines of code are part function, definition, ID and action. Am I close?

Say I want to add Yellow (I actually do) to the first set of code because it's not in there, well I would need to know where to get the 0.XXXX for Yellow to start with, right? How do people know where to get all these unique identifiers? How do I get them?

I thought maybe messing with the Controller Script Console might clue me in, but it does nothing to illuminate anything for me, it just stares at me black or screams at me red. I think this may be a step in understanding what’s going on. A rather important one it seems.

Thanks
-JH

Post Reply

Return to “Controller Scripting”