From 362b9cb4fa4fbacd0660b1d5eb59213747de4984 Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Thu, 1 Apr 2021 10:24:50 -0700 Subject: [PATCH] Maschine Mikro MK2 support --- libs/surfaces/maschine2/m2_dev_mikro.h | 28 ++++++------ libs/surfaces/maschine2/m2_map_mikro.cc | 60 ++++++++++++++++++++++++- libs/surfaces/maschine2/m2_map_mikro.h | 16 +++++++ libs/surfaces/maschine2/m2controls.h | 9 +++- 4 files changed, 97 insertions(+), 16 deletions(-) diff --git a/libs/surfaces/maschine2/m2_dev_mikro.h b/libs/surfaces/maschine2/m2_dev_mikro.h index 5766a53706..adc1d653d8 100644 --- a/libs/surfaces/maschine2/m2_dev_mikro.h +++ b/libs/surfaces/maschine2/m2_dev_mikro.h @@ -45,14 +45,14 @@ class Maschine2Mikro : public M2Device #endif struct machine_mk2_input { - unsigned int trs_restart : 1; // 0 - unsigned int trs_left : 1; - unsigned int trs_right : 1; - unsigned int trs_grid : 1; - unsigned int trs_play : 1; - unsigned int trs_rec : 1; + unsigned int trs_shift : 1; // 0 unsigned int trs_erase : 1; - unsigned int trs_shift : 1; + unsigned int trs_rec : 1; + unsigned int trs_play : 1; + unsigned int trs_grid : 1; + unsigned int trs_right : 1; + unsigned int trs_left : 1; + unsigned int trs_restart : 1; unsigned int group : 1; // 8 unsigned int browse : 1; unsigned int sampling : 1; @@ -67,14 +67,14 @@ class Maschine2Mikro : public M2Device unsigned int nav_left : 1; unsigned int nav_right : 1; unsigned int main : 1; - unsigned int pads_scene : 1; // 24 - unsigned int pads_pattern : 1; - unsigned int pads_mode : 1; - unsigned int pads_navigate : 1; - unsigned int pads_duplicate : 1; - unsigned int pads_select : 1; + unsigned int pads_mute : 1; // 24 unsigned int pads_solo : 1; - unsigned int pads_mute : 1; // 31 + unsigned int pads_select : 1; + unsigned int pads_duplicate : 1; + unsigned int pads_navigate : 1; + unsigned int pads_mode : 1; + unsigned int pads_pattern : 1; + unsigned int pads_scene : 1; // 31 unsigned int mst_wheel_pos : 8; // 32..40 // range: 0..15 } ATTRIBUTE_PACKED ctrl_in; diff --git a/libs/surfaces/maschine2/m2_map_mikro.cc b/libs/surfaces/maschine2/m2_map_mikro.cc index 43a97d6b0b..c89ac268b9 100644 --- a/libs/surfaces/maschine2/m2_map_mikro.cc +++ b/libs/surfaces/maschine2/m2_map_mikro.cc @@ -19,21 +19,76 @@ #include "m2_map_mikro.h" using namespace ArdourSurface; +using namespace std; M2MapMikro::M2MapMikro () : M2Contols () , enc_master (16) -{} +{ +#define PSMAP(MOD, PHYS, SEM, BTN) \ + pmap[MOD].insert (make_pair (PHYS, BTN)); \ + smap.insert (make_pair (SEM, BTN)); + +#define PSMAPALL(PHYS, SEM, BTN) \ + pmap[ModNone].insert (make_pair (PHYS, BTN)); \ + pmap[ModShift].insert (make_pair (PHYS, BTN)); \ + smap.insert (make_pair (SEM, BTN)); \ + + PSMAP(ModNone, BtnPlay, Play, &tr[0]); + PSMAP(ModShift, BtnPlay, Metronom, &tr[1]); + PSMAP(ModNone, BtnRec, Rec, &tr[2]); + PSMAP(ModNone, BtnGrid, Grid, &tr[3]); + PSMAP(ModNone, BtnRestart, GotoStart, &ts[0]); + PSMAP(ModShift, BtnRestart, Loop, &tr[4]); + + PSMAP(ModNone, BtnStepLeft, FastRewind, &ts[1]); + PSMAP(ModNone, BtnStepRight, FastForward, &ts[2]); + PSMAP(ModShift, BtnStepLeft, JumpBackward, &ts[3]); + PSMAP(ModShift, BtnStepRight, JumpForward, &ts[4]); + + PSMAPALL(BtnWheel, EncoderWheel, &mst[0]); + PSMAPALL(BtnVolume, MasterVolume, &mst[1]); + //PSMAPALL(BtnSwing, Master?????, &mst[2]); + PSMAPALL(BtnTempo, MasterTempo, &mst[3]); + + PSMAP(ModShift, BtnAll, Save, &save); + + PSMAP(ModShift, BtnNavLeft, Undo, &undoredo[0]); + PSMAP(ModShift, BtnNavRight, Redo, &undoredo[1]); + + PSMAP(ModNone, BtnMute, Mute, &sm[7]); + PSMAP(ModShift, BtnMute, Panic, &panic); + + PSMAPALL(BtnScene, Scene, &sm[0]); + PSMAPALL(BtnPattern, Pattern, &sm[1]); + PSMAPALL(BtnPadMode, PadMode, &sm[2]); + PSMAPALL(BtnNavigate, Navigate, &sm[3]); + PSMAPALL(BtnDuplicate, Duplicate, &sm[4]); + PSMAPALL(BtnSelect, Select, &sm[5]); + PSMAPALL(BtnSolo, Solo, &sm[6]); + + // TODO: + pmap[ModNone].insert (make_pair (BtnErase, &ts[5])); + pmap[ModShift].insert (make_pair (BtnErase, &ts[5])); +} M2ButtonInterface* M2MapMikro::button (PhysicalButtonId id, Modifier m) { + PhysicalMap::const_iterator i = pmap[m].find (id); + if (i != pmap[m].end()) { + return i->second; + } return M2Contols::button (id, m); } M2ButtonInterface* M2MapMikro::button (SemanticButtonId id) { + SematicMap::const_iterator i = smap.find (id); + if (i != smap.end()) { + return i->second; + } return M2Contols::button (id); } @@ -43,6 +98,9 @@ M2MapMikro::encoder (unsigned int id) if (id == 0) { return &enc_master; } + else if (id < 9) { + return &enc_top[id - 1]; + } // TODO map "nav" (select) and Left/Right to encoder(s) delta. return M2Contols::encoder (id); } diff --git a/libs/surfaces/maschine2/m2_map_mikro.h b/libs/surfaces/maschine2/m2_map_mikro.h index e07e7fb4e6..2a11ce6044 100644 --- a/libs/surfaces/maschine2/m2_map_mikro.h +++ b/libs/surfaces/maschine2/m2_map_mikro.h @@ -34,7 +34,23 @@ class M2MapMikro : public M2Contols M2PadInterface* pad (unsigned int id); private: + PhysicalMap pmap[2]; // 2: Modifiers + SematicMap smap; + + M2Button tr[5]; // transport controlables + M2StatelessButton ts[6]; // transport pushbuttons + + M2Button mst[4]; // master "volume", "swing", "tempo", "encoder-push" + + M2Button save; + + M2Button undoredo[2]; + M2Button sm[8]; // scene, pattern, pad mode, navigate (AKA view), duplicate, select, solo, mute + M2StatelessButton panic; + M2Encoder enc_master; + M2Encoder enc_top[16]; + M2Pad pads[16]; }; diff --git a/libs/surfaces/maschine2/m2controls.h b/libs/surfaces/maschine2/m2controls.h index 38bce090a3..519a59ca51 100644 --- a/libs/surfaces/maschine2/m2controls.h +++ b/libs/surfaces/maschine2/m2controls.h @@ -131,7 +131,14 @@ class M2Contols EncoderWheel, // multi-purpose MasterVolume, MasterTempo, - Solo, Mute, + Scene, + Pattern, + PadMode, + Navigate, + Duplicate, + Select, + Solo, + Mute, Panic } SemanticButtonId;