Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NI Traktor Kontrol Z1: Synchronize control positions on startup #12426

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions res/controllers/Traktor-Kontrol-Z1-scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Native Instruments Traktor Kontrol Z1 HID controller script for Mixxx 2.4
// -------------------------------------------------------------------------
// Based on: Kontrol S2 MK3 script by mi01 and Kontrol Z1 script by xeruf
// Based on: NI Traktor Kontrol series scripts by leifhelm, mi01 & xeruf
// Author: djantti
//

Expand All @@ -12,16 +12,20 @@ class TraktorZ1Class {
// Modifier state
this.modePressed = false;

// VuMeter
// VU meters
this.vuLeftConnection = {};
this.vuRightConnection = {};
this.vuMeterThresholds = {"vu-30": (1 / 7), "vu-15": (2 / 7), "vu-6": (3 / 7), "vu-3": (4 / 7), "vu0": (5 / 7), "vu3": (6 / 7), "vu6": (7 / 7)};
}

init(_id) {
this.id = _id;

this.registerInputPackets();
this.registerOutputPackets();
this.readCurrentPosition();
this.enableSoftTakeover();

console.log(this.id + " initialized");
}

Expand Down Expand Up @@ -66,38 +70,6 @@ class TraktorZ1Class {
this.registerInputScaler(InputReport0x01, "[Master]", "crossfader", 0x1B, 0xFFFF, this.parameterHandler.bind(this));

this.controller.registerInputPacket(InputReport0x01);

// Soft takeover for all knobs and faders
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter3", true);
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter2", true);
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter1", true);

engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter3", true);
engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter2", true);
engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter1", true);

engine.softTakeover("[QuickEffectRack1_[Channel1]]", "super1", true);
engine.softTakeover("[QuickEffectRack1_[Channel2]]", "super1", true);

engine.softTakeover("[Channel1]", "pregain", true);
engine.softTakeover("[Channel2]", "pregain", true);

engine.softTakeover("[Master]", "headMix", true);

engine.softTakeover("[Channel1]", "volume", true);
engine.softTakeover("[Channel2]", "volume", true);

engine.softTakeover("[Master]", "crossfader", true);
}

registerInputButton(inputReport, group, name, offset, bitmask, callback) {
inputReport.addControl(group, name, offset, "B", bitmask);
inputReport.setCallback(group, name, callback);
}

registerInputScaler(inputReport, group, name, offset, bitmask, callback) {
inputReport.addControl(group, name, offset, "H", bitmask);
inputReport.setCallback(group, name, callback);
}

registerOutputPackets() {
Expand Down Expand Up @@ -144,6 +116,48 @@ class TraktorZ1Class {
this.lightDeck(false);
}

readCurrentPosition() {
// Sync on-screen controls with controller knob positions
const report0x01 = new Uint8Array(controller.getInputReport(0x01));
// The first packet is ignored by HIDController
this.controller.parsePacket([0x01, ...Array.from(report0x01.map(x => x ^ 0xFF))]);
this.controller.parsePacket([0x01, ...Array.from(report0x01)]);
}

enableSoftTakeover() {
// Soft takeover for all knobs and faders
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter3", true);
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter2", true);
engine.softTakeover("[EqualizerRack1_[Channel1]_Effect1]", "parameter1", true);

engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter3", true);
engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter2", true);
engine.softTakeover("[EqualizerRack1_[Channel2]_Effect1]", "parameter1", true);

engine.softTakeover("[QuickEffectRack1_[Channel1]]", "super1", true);
engine.softTakeover("[QuickEffectRack1_[Channel2]]", "super1", true);

engine.softTakeover("[Channel1]", "pregain", true);
engine.softTakeover("[Channel2]", "pregain", true);

engine.softTakeover("[Master]", "headMix", true);

engine.softTakeover("[Channel1]", "volume", true);
engine.softTakeover("[Channel2]", "volume", true);

engine.softTakeover("[Master]", "crossfader", true);
}

registerInputButton(inputReport, group, name, offset, bitmask, callback) {
inputReport.addControl(group, name, offset, "B", bitmask);
inputReport.setCallback(group, name, callback);
}

registerInputScaler(inputReport, group, name, offset, bitmask, callback) {
inputReport.addControl(group, name, offset, "H", bitmask);
inputReport.setCallback(group, name, callback);
}

modeHandler(field) {
this.modePressed = field.value;
this.outputHandler(field.value, field.group, "mode");
Expand Down Expand Up @@ -186,7 +200,7 @@ class TraktorZ1Class {
if (this.vuMeterThresholds[vuKeys[i]] > value) {
this.controller.setOutput(group, vuKeys[i], 0x00, last);
} else {
this.controller.setOutput(group, vuKeys[i], 0x7E, last);
this.controller.setOutput(group, vuKeys[i], 0x7F, last);
}
}
}
Expand Down
Loading