Skeleton for NI Maschine2 Surface
[ardour.git] / libs / surfaces / maschine2 / m2_map_mk2.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #include "m2_map_mk2.h"
20
21 using namespace ArdourSurface;
22 using namespace std;
23
24 M2MapMk2::M2MapMk2 ()
25         : M2Contols ()
26         , enc_master (16)
27 {
28 #define PSMAP(MOD, PHYS, SEM, BTN) \
29         pmap[MOD].insert (make_pair (PHYS, BTN)); \
30         smap.insert (make_pair (SEM, BTN));
31
32 #define PSMAPALL(PHYS, SEM, BTN) \
33         pmap[ModNone].insert (make_pair (PHYS, BTN)); \
34         pmap[ModShift].insert (make_pair (PHYS, BTN)); \
35         smap.insert (make_pair (SEM, BTN)); \
36
37         PSMAP(ModNone,  BtnPlay, Play,         &tr[0]);
38         PSMAP(ModShift, BtnPlay, Metronom,     &tr[1]);
39         PSMAP(ModNone,  BtnRec, Rec,           &tr[2]);
40         PSMAP(ModNone,  BtnGrid, Grid,         &tr[3]);
41         PSMAP(ModNone,  BtnRestart, GotoStart, &ts[0]);
42         PSMAP(ModShift, BtnRestart, Loop,      &tr[4]);
43
44         PSMAP(ModNone,  BtnStepLeft,  FastRewind,   &ts[1]);
45         PSMAP(ModNone,  BtnStepRight, FastForward,  &ts[2]);
46         PSMAP(ModShift, BtnStepLeft,  JumpBackward, &ts[3]);
47         PSMAP(ModShift, BtnStepRight, JumpForward,  &ts[4]);
48
49         PSMAPALL(BtnWheel,  EncoderWheel, &mst[0]);
50         PSMAPALL(BtnVolume, MasterVolume, &mst[1]);
51         //PSMAPALL(BtnSwing, Master?????, &mst[2]);
52         PSMAPALL(BtnTempo,  MasterTempo,  &mst[3]);
53
54         PSMAP(ModShift,  BtnAll, Save, &save);
55
56         PSMAP(ModShift,  BtnNavLeft,  Undo, &undoredo[0]);
57         PSMAP(ModShift,  BtnNavRight, Redo, &undoredo[1]);
58
59         PSMAP(ModNone,  BtnMute, Mute,  &sm[0]);
60         PSMAP(ModShift, BtnMute, Panic, &panic);
61         PSMAPALL(BtnSolo, Solo,         &sm[1]);
62
63         // TODO:
64         pmap[ModNone].insert  (make_pair (BtnErase, &ts[5]));
65         pmap[ModShift].insert (make_pair (BtnErase, &ts[5]));
66
67 }
68
69 M2ButtonInterface*
70 M2MapMk2::button (PhysicalButtonId id, Modifier m)
71 {
72         PhysicalMap::const_iterator i = pmap[m].find (id);
73         if (i != pmap[m].end()) {
74                 return i->second;
75         }
76         return M2Contols::button (id, m);
77 }
78
79 M2ButtonInterface*
80 M2MapMk2::button (SemanticButtonId id)
81 {
82         SematicMap::const_iterator i = smap.find (id);
83         if (i != smap.end()) {
84                 return i->second;
85         }
86         return M2Contols::button (id);
87 }
88
89 M2EncoderInterface*
90 M2MapMk2::encoder (unsigned int id)
91 {
92         if (id == 0) {
93                 return &enc_master;
94         }
95         else if (id < 9) {
96                 return &enc_top[id - 1];
97         }
98         return M2Contols::encoder (id);
99 }
100
101 M2PadInterface*
102 M2MapMk2::pad (unsigned int id)
103 {
104         if (id < 16) {
105                 return &pads[id];
106         }
107         return M2Contols::pad (id);
108 }