asked Sep 20 at 19:25 by nojoe (46)

edited Sep 20 at 19:26

1
1

Hi,

i polished the script from Nettsu but i'm really not a java script coder and do the most with copy/paste and trail & error. Maybe someone here can help a little bit to minimize my ToDo list? ^^

loadAPI(6);

// Extended version from Nettsu v1.0 - https://github.com/Nettsu/minilab-mkII-bitwig
// by nojoe v1.2, at the moment the controller settings are my test defaults!
// .. Pad 1&2 scroll now between tracks; Pad 5 Overdub toggle; Knob 9 hold for Metronome
//
//
// ToDo:
//
// 1. [Shift + Pad 1/2] scroll between devices ( deviceCursor.selectPrevious & deviceCursor.selectNext )
// 2. Knob1click - Resets macro values. Possible to resets to macro preset defaults then to 0?
// 3. Knob9click - Metronome on/off. Needs a fix: At the moment holding the Knob activates the Click,
//    release the Knob deactivates the Click!
// 4. Knob7 - Song pointer position
//    In Controller Setting: Independent Knob speed for adjusting to fit personal preference
// 5. Knob8 - Panning of the selected track
// 5. Knob15 - Global data up/down like arrow up/down on keyboard?
//    In Controller Setting: Independent Knob speed for adjusting to fit personal preference
// 6. Knob16 - Volume of the selected track
// 7. Pad 9-16 - Delete Note/Control toggle in controller setting and use Pad buttons to switch between Control and Note playing!

host.defineController("Arturia", "MiniLab MKII", "1.2 beta", "9c891939-9cb5-488d-a447-266f543516f3", "Netsu (TEST by nojoe)");
host.defineMidiPorts(1, 1);
host.addDeviceNameBasedDiscoveryPair(["Arturia MINILAB MKII"], ["Arturia MINILAB MKII"]);

STATUS_PAD_ON = 153;
STATUS_PAD_OFF = 137;
STATUS_KNOB = 176;
FIRST_PAD_MIDI = 36;

var MACRO_NAMES = [
    "Macro 1",
    "Macro 2",
    "Macro 3",
    "Macro 4",
    "Macro 5",
    "Macro 6",
    "Macro 7",
    "Macro 8"
];

var MACRO_MAP =
{
    "Macro 1":0,
    "Macro 2":1,
    "Macro 3":2,
    "Macro 4":3,
    "Macro 5":4,
    "Macro 6":5,
    "Macro 7":6,
    "Macro 8":7
};

var COLOR =
{
    BLACK   :"00",
    RED     :"01",
    BLUE    :"10",
    GREEN   :"04",
    CYAN    :"14",
    PURPLE  :"11",
    YELLOW  :"05",
    WHITE   :"7F"
};

var PAD_COLORS =
[
    COLOR.YELLOW,
    COLOR.YELLOW,
    COLOR.PURPLE,
    COLOR.PURPLE,
    COLOR.CYAN,
    COLOR.GREEN,
    COLOR.BLUE,
    COLOR.RED,
    COLOR.YELLOW,
    COLOR.YELLOW,
    COLOR.PURPLE,
    COLOR.PURPLE,
    COLOR.CYAN,
    COLOR.GREEN,
    COLOR.BLUE,
    COLOR.RED
];

var BOTTOM_FUNC =
{
    CURRENT:0,
    MASTER:1
};

var PAD_FUNCTION =
{
    NOTES:0,
    CONTROL:1
};


var KnobsLeft = [112, 74, 71, 76, 114, 18, 19, 16];
var KnobsRight = [77, 93, 17, 91];


// RESET MACRO VALUES TO 0 (read ToDo!)
var Knob1click = 113;

// METRONOME (read ToDo!)
var Knob9click = 115;

// SONG POINTER POSITION (read ToDo!)
var Knob7 = 73;

// PAN (read ToDo!)
var Knob8 = 75;

// SONG POINTER POSITION (read ToDo!)
var Knob15 = 79;

// VOLUME (read ToDo!)
var Knob16 = 72;


var modWheel        = 1;
var modWheelMacro   = 7;
var macroKnobSpeed  = 1.0;
var rainbowColors   = true;
var padFunction     = PAD_FUNCTION.NOTES;

var identityMap     = makeArray(128, -1);
var emptyMap        = makeArray(128, -1);

function makeArray(x, init)
{
    var table = new Array(x);
    for (var i = 0; i < x; i++)
    {
        table[i] = init;
    }
    return table;
}

function init()
{
    for (var i = 0; i < 128; i++)
        identityMap[i] = i;

    // Create the Note Inputs and their Settings
    MiniLabKeys = host.getMidiInPort(0).createNoteInput("MiniLab Keys", "80????", "90????", "B001??", "B002??", "B007??", "B00B??", "B040??", "C0????", "D0????", "E0????");
    MiniLabKeys.setShouldConsumeEvents(false);
    MiniLabPads = host.getMidiInPort(0).createNoteInput("MiniLab Pads", "?9????");
    MiniLabPads.setShouldConsumeEvents(false);
    MiniLabPads.assignPolyphonicAftertouchToExpression(0, NoteExpression.TIMBRE_UP, 2);

    host.getMidiInPort(0).setMidiCallback(onMidi);

    transport = host.createTransport();
    cTrack = host.createCursorTrack(3, 0);
    uControl = host.createUserControls(8);
    prefs = host.getPreferences();    

    primaryDevice = cTrack.getPrimaryDevice();

    deviceCursor = cTrack.createCursorDevice();
    controlPageCursor = deviceCursor.createCursorRemoteControlsPage(8);

    for (var i = 0; i < 8; i++)
    {
        uControl.getControl(i).setLabel("CC " + KnobsRight[i])
    }

    var modWheelSetting = prefs.getEnumSetting("Modwheel macro", "Modwheel", MACRO_NAMES, "Macro 1");
    modWheelSetting.addValueObserver(function (value)
    {
        modWheelMacro = MACRO_MAP[value];
    });

    var macroSpeedSetting = prefs.getNumberSetting("Macro knob speed", "Knobs", -10, 10, 0.1, "", 2.0);
    macroSpeedSetting.addRawValueObserver(function(value)
    {
        macroKnobSpeed = value;
    });

    var rainbowSetting = prefs.getEnumSetting("Rainbow colors", "Pads", ["ON", "OFF"], "ON");
    rainbowSetting.addValueObserver(function (value)
    {
        rainbowColors = (value == "ON");
        if (rainbowColors == true)
        {
            makeRainbow();
        }
    });

    var padSetting = prefs.getEnumSetting("Pad function", "Pads", ["Notes", "Control"], "Control");
    padSetting.addValueObserver(function (value)
    {
        if (value == "Notes")
        {
            padFunction = PAD_FUNCTION.NOTES;
            MiniLabPads.setKeyTranslationTable(identityMap);
        }
        else
        {
            padFunction = PAD_FUNCTION.CONTROL;
            MiniLabPads.setKeyTranslationTable(emptyMap);
        }
    });

    setIndications();
}

function makeRainbow()
{
    for (var i = 0; i < 16; i++)
    {
        setPadColor(i, PAD_COLORS[i]);
    }
}

function MidiData(status, data1, data2)
{
   this.status = status;
   this.data1 = data1;
   this.data2 = data2;
}

function onPad(midi)
{
    if (midi.status == STATUS_PAD_ON)
    {
        var padNum = midi.data1 - FIRST_PAD_MIDI;

        if (padFunction == PAD_FUNCTION.CONTROL)
        {
            if (padNum == 0)
            {
                cTrack.selectNext();
            }
            else if (padNum == 1)
            {
                cTrack.selectPrevious();
            }
            else if (padNum == 2)
            {
                controlPageCursor.selectPreviousPage(true);
            }
            else if (padNum == 3)
            {
                controlPageCursor.selectNextPage(true);
            }
            else if (padNum == 4)
            {
                transport.toggleOverdub();
            }
            else if (padNum == 5)
            {
                transport.togglePlay();
            }
            else if (padNum == 6)
            {
                transport.stop();
            }
            else if (padNum == 7)
            {
                transport.record();
            }
        }

        if (rainbowColors == true)
        {
            setPadColor(padNum, COLOR.WHITE);
        }
    }
    else if (midi.status == STATUS_PAD_OFF)
    {
        var padNum = midi.data1 - FIRST_PAD_MIDI;

        if (rainbowColors == true)
        {
            setPadColor(padNum, PAD_COLORS[padNum]);
        }
    }
}

function onMidi(status, data1, data2)
{
    // Instantiate the MidiData Object for convenience:
    var midi = new MidiData(status, data1, data2);

    println(midi.status + ":" + midi.data1 + ":" + midi.data2);
    if (midi.status == STATUS_PAD_ON || midi.status == STATUS_PAD_OFF)
    {
        onPad(midi);
    }

    if (midi.status == STATUS_KNOB)
    {
        var inc = (midi.data2 - 64) * macroKnobSpeed;

        for (var i = 0; i < 8; i++)
        {
            if (midi.data1 === KnobsLeft[i])
            {
                controlPageCursor.getParameter(i).inc(inc, 128);
            }
            else if (midi.data1 === KnobsRight[i])
            {
                uControl.getControl(i).inc(inc, 128);
            }
        }

        if (midi.data1 == Knob1click)
        {
            resetMacros();
        }
        else if (midi.data1 == Knob9click)
        {
            transport.toggleClick();
        }
        else if (midi.data1 == modWheel)
        {
            modWheelFunc(midi);
        }
    }
}

function resetMacros()
{
    for (var i = 0; i < 8; i++)
    {
        controlPageCursor.getParameter(i).reset();
    }
}

function modWheelFunc(midi)
{
    controlPageCursor.getParameter(modWheelMacro).set(midi.data2, 128);
}

function setPadColor(pad, color)
{
    var padHex = (112 + pad).toString(16);
    sendSysex("F0 00 20 6B 7F 42 02 00 10 " + padHex + " " + color + " F7");
}

function setIndications()
{
    for (var i = 0; i < 8; i++)
    {
        controlPageCursor.getParameter(i).setIndication(true);
        uControl.getControl(i).setIndication(true);
    }
}

function getSign(x)
{
    return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
}

function exit()
{
}

`

just got a minilab mk2 and am very much a JS coder. I'm in to help. If you're still interested I'd love to collab, hit me up via email or something. Otherwise I will totally be using this starting point!

link

answered Dec 01 at 22:33 by turbohappy (11)

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×27
×20
×4

Asked: Sep 20 at 19:25

Seen: 165 times

Last updated: Dec 01 at 22:33