Skip to content

Instantly share code, notes, and snippets.

@tancredi
Created December 25, 2021 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tancredi/ebd74a70467010b18bfc6f14b101e1db to your computer and use it in GitHub Desktop.
Save tancredi/ebd74a70467010b18bfc6f14b101e1db to your computer and use it in GitHub Desktop.
Griffin PowerMater as library wheel & preview button - Mixxx HID controller mappings
const THROTTLE = 50;
const GPM = { lastMove: null, previewToMiddleOnLoad: false };
const GROUPS = { PREVIEW: "[PreviewDeck1]" };
const MAX_POSITION = 1.14;
GPM.init = function (id) {
GPM.controller = new HIDController();
GPM.id = id;
GPM.registerInputPackets();
GPM.registerOutputPackets();
GPM.registerCallbacks();
engine.makeConnection(
GROUPS.PREVIEW,
"track_loaded",
GPM.handlePreviewLoaded
);
GPM.toggleLED(false);
};
GPM.shutdown = function () {
GPM.controller.close();
};
GPM.registerOutputPackets = function () {
const packet = new HIDPacket("out");
packet.addControl("hid", "led", 0, "B");
GPM.controller.registerOutputPacket(packet);
};
GPM.handlePreviewLoaded = function () {
if (GPM.previewToMiddleOnLoad) {
GPM.previewToMiddleOnLoad = false;
engine.setValue(GROUPS.PREVIEW, "playposition", MAX_POSITION / 2);
}
};
GPM.startPreview = function () {
const playing = engine.getValue(GROUPS.PREVIEW, "play");
GPM.previewToMiddleOnLoad = true;
GPM.toggleLED(true);
script.triggerControl(GROUPS.PREVIEW, "LoadSelectedTrackAndPlay", true);
};
GPM.stopPreview = function () {
GPM.toggleLED(false);
return engine.setValue(GROUPS.PREVIEW, "play", false);
};
GPM.registerInputPackets = function () {
const packet = new HIDPacket("control");
packet.addControl("hid", "button", 0, "B", 0x01);
packet.addControl("hid", "wheel", 1, "b");
packet.setMinDelta("hid", "wheel", undefined);
this.controller.registerInputPacket(packet);
};
GPM.incomingData = function (data, length) {
GPM.controller.parsePacket(data, length);
};
GPM.registerCallbacks = function (id) {
const controller = GPM.controller;
controller.setCallback("control", "hid", "button", GPM.button);
controller.setCallback("control", "hid", "wheel", GPM.wheel);
};
GPM.toggleLED = function (on) {
const packet = GPM.controller.getOutputPacket("out");
const field = packet.getField("hid", "led");
field.value = on ? 255 : 0;
packet.send();
};
GPM.button = function (field) {
field.value ? GPM.startPreview() : GPM.stopPreview();
};
GPM.wheel = function (field) {
if (field.value === 0) {
return;
}
if (GPM.lastMove && Date.now() - GPM.lastMove < THROTTLE) {
return;
}
GPM.lastMove = Date.now();
script.triggerControl(
"[Playlist]",
field.value > 0 ? "SelectNextTrack" : "SelectPrevTrack",
true
);
};
<?xml version='1.0' encoding='utf-8'?>
<MixxxControllerPreset schemaVersion="1" mixxxVersion="1.11+">
<info>
<name>Griffin Powermate - Library control</name>
<author>Tancredi Trugenberger</author>
<description>Griffin Powermate HID mapping to library control (press to preview track)</description>
</info>
<controller id="Griffin">
<scriptfiles>
<file filename="common-hid-packet-parser.js" functionprefix=""/>
<file filename="griffin-powermate-library-control.hid.js" functionprefix="GPM"/>
</scriptfiles>
</controller>
</MixxxControllerPreset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment