///////////////////////////////////////////////////////////////////////////////////
// JSHint configuration //
///////////////////////////////////////////////////////////////////////////////////
/* global engine */
/* global script */
/* global HIDDebug */
/* global HIDPacket */
/* global HIDController */
/* jshint -W016 */
///////////////////////////////////////////////////////////////////////////////////
/* */
/* Traktor Kontrol S2 MK3 HID controller script v1.01 */
/* Last modification: February 2021 */
/* Author: Michael Schmidt */
/* https://github.com/mixxxdj/mixxx/wiki/Native%20Instruments%20Traktor%20Kontrol%20S2%20MK3 */
/* */
///////////////////////////////////////////////////////////////////////////////////
var TraktorS2MK3 = new function () {
this.controller = new HIDController();
this.shiftPressed = { "[Channel1]": false, "[Channel2]": false };
this.fxButtonState = { 1: false, 2: false, 3: false, 4: false };
this.padModeState = { "[Channel1]": 0, "[Channel2]": 0 }; // 0 = Hotcues Mode, 1 = Samples Mode
// Knob encoder states (hold values between 0x0 and 0xF)
// Rotate to the right is +1 and to the left is means -1
this.browseKnobEncoderState = { "[Channel1]": 0, "[Channel2]": 0 };
this.loopKnobEncoderState = { "[Channel1]": 0, "[Channel2]": 0 };
this.moveKnobEncoderState = { "[Channel1]": 0, "[Channel2]": 0 };
// Microphone button
this.microphonePressedTimer = 0; // Timer to distinguish between short and long press
// Sync buttons
this.syncPressedTimer = { "[Channel1]": 0, "[Channel2]": 0 }; // Timer to distinguish between short and long press
// Jog wheels
this.pitchBendMultiplier = 1.1;
this.lastTickVal = [0, 0];
this.lastTickTime = [0.0, 0.0];
// VuMeter
this.vuLeftConnection = {};
this.vuRightConnection = {};
this.clipLeftConnection = {};
this.clipRightConnection = {};
this.vuMeterThresholds = { "vu-18": (1 / 6), "vu-12": (2 / 6), "vu-6": (3 / 6), "vu0": (4 / 6), "vu6": (5 / 6) };
// Sampler callbacks
this.samplerCallbacks = [];
this.samplerHotcuesRelation = {
"[Channel1]": {
1: 1, 2: 2, 3: 3, 4: 4, 5: 9, 6: 10, 7: 11, 8: 12
}, "[Channel2]": {
1: 5, 2: 6, 3: 7, 4: 8, 5: 13, 6: 14, 7: 15, 8: 16
}
};
};
TraktorS2MK3.init = function (id) {
TraktorS2MK3.registerInputPackets();
TraktorS2MK3.registerOutputPackets();
HIDDebug("TraktorS2MK3: Init done!");
};
TraktorS2MK3.registerInputPackets = function () {
var messageShort = new HIDPacket("shortmessage", 0x01, this.messageCallback);
var messageLong = new HIDPacket("longmessage", 0x02, this.messageCallback);
this.registerInputButton(messageShort, "[Channel1]", "!play", 0x02, 0x08, this.playHandler);
this.registerInputButton(messageShort, "[Channel2]", "!play", 0x05, 0x20, this.playHandler);
this.registerInputButton(messageShort, "[Channel1]", "!cue_default", 0x02, 0x04, this.cueHandler);
this.registerInputButton(messageShort, "[Channel2]", "!cue_default", 0x05, 0x10, this.cueHandler);
this.registerInputButton(messageShort, "[Channel1]", "!shift", 0x01, 0x20, this.shiftHandler);
this.registerInputButton(messageShort, "[Channel2]", "!shift", 0x04, 0x80, this.shiftHandler);
this.registerInputButton(messageShort, "[Channel1]", "!sync", 0x02, 0x01, this.syncHandler);
this.registerInputButton(messageShort, "[Channel2]", "!sync", 0x05, 0x04, this.syncHandler);
this.registerInputButton(messageShort, "[Channel1]", "!keylock", 0x02, 0x02, this.keylockHandler);
this.registerInputButton(messageShort, "