FP8/16: include makeup gain control
[ardour.git] / libs / surfaces / faderport8 / fp8_base.h
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) 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
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef _ardour_surfaces_fp8base_h_
20 #define _ardour_surfaces_fp8base_h_
21
22 #include <stdint.h>
23 #include <vector>
24
25 #include "pbd/signals.h"
26
27 #ifdef FADERPORT16
28 # define FP_NAMESPACE FP16
29 #elif defined FADERPORT2
30 # define FP_NAMESPACE FP2
31 #else
32 # define FP_NAMESPACE FP8
33 #endif
34
35 namespace ArdourSurface { namespace FP_NAMESPACE {
36
37 /* conveniece wrappers depending on "FP8Base& _base" */
38 #define fp8_loop dynamic_cast<BaseUI*>(&_base)->main_loop
39 #define fp8_context() dynamic_cast<BaseUI*>(&_base)
40 #define fp8_protocol() dynamic_cast<ControlProtocol*>(&_base)
41
42 /** Virtual abstract base of the FaderPort8 control surface
43  *
44  * This is passed as handle to all elements (buttons, lights,..)
45  * to inteface common functionality for the current instance:
46  *  - sending MIDI
47  *  - global events (signals)
48  *  - thread context
49  *
50  * It is implemented by FaderPort8
51  */
52 class FP8Base
53 {
54 public:
55         virtual ~FP8Base() {}
56
57         virtual size_t tx_midi (std::vector<uint8_t> const&) const = 0;
58         virtual std::string const& timecode () const = 0;
59         virtual std::string const& musical_time () const = 0;
60         virtual bool shift_mod () const = 0;
61         virtual bool show_meters () const = 0;
62         virtual bool show_panner () const = 0;
63         virtual bool twolinetext () const = 0;
64         virtual uint32_t clock_mode () const = 0;
65
66         size_t tx_midi2 (uint8_t sb, uint8_t d1) const
67         {
68                  std::vector<uint8_t> d;
69                  d.push_back (sb);
70                  d.push_back (d1);
71                  return tx_midi (d);
72         }
73
74         size_t tx_midi3 (uint8_t sb, uint8_t d1, uint8_t d2) const
75         {
76                  std::vector<uint8_t> d;
77                  d.push_back (sb);
78                  d.push_back (d1);
79                  d.push_back (d2);
80                  return tx_midi (d);
81         }
82
83         size_t tx_sysex (size_t count, ...)
84         {
85                  std::vector<uint8_t> d;
86                  sysexhdr (d);
87
88                  va_list var_args;
89                  va_start (var_args, count);
90                  for  (size_t i = 0; i < count; ++i)
91                  {
92                          // uint8_t {aka unsigned char} is promoted to β€˜int’ when passed through β€˜...’
93                          uint8_t b = va_arg (var_args, int);
94                          d.push_back (b);
95                  }
96                  va_end (var_args);
97
98                  d.push_back (0xf7);
99                  return tx_midi (d);
100         }
101
102         size_t tx_text (uint8_t id, uint8_t line, uint8_t align, std::string const& txt)
103         {
104                  std::vector<uint8_t> d;
105                  sysexhdr (d);
106                  d.push_back (0x12);
107                  d.push_back (id & 0x0f);
108                  d.push_back (line & 0x03);
109                  d.push_back (align & 0x07);
110
111                  for  (size_t i = 0; i < txt.size(); ++i)
112                  {
113                          d.push_back (txt[i]);
114                          if (i >= 8) {
115                                  break;
116                          }
117                  }
118                  d.push_back (0xf7);
119                  return tx_midi (d);
120         }
121
122         /* modifier keys */
123         PBD::Signal1<void, bool> ShiftButtonChange;
124         PBD::Signal1<void, bool> ARMButtonChange;
125
126         /* timer events */
127         PBD::Signal1<void, bool> BlinkIt;
128         PBD::Signal0<void> Periodic;
129
130 private:
131         void sysexhdr (std::vector<uint8_t>& d)
132         {
133                 /* faderport8 <SysExHdr> */
134                 d.push_back (0xf0);
135                 d.push_back (0x00);
136                 d.push_back (0x01);
137                 d.push_back (0x06);
138 #ifdef FADERPORT16
139                 d.push_back (0x16);
140 #else
141                 d.push_back (0x02);
142 #endif
143         }
144 };
145
146 namespace FP8Types {
147
148         enum FaderMode {
149                 ModeTrack,
150                 ModePlugins,
151                 ModeSend,
152                 ModePan
153         };
154
155         enum NavigationMode {
156                 NavChannel,
157                 NavZoom,
158                 NavScroll,
159                 NavBank,
160                 NavMaster,
161                 NavSection,
162                 NavMarker,
163                 NavPan /* FP2 only */
164         };
165
166         enum MixMode {
167                 MixAudio,
168                 MixInstrument,
169                 MixBus,
170                 MixVCA,
171                 MixAll,
172                 MixInputs,
173                 MixMIDI,
174                 MixOutputs,
175                 MixFX,
176                 MixUser,
177                 MixModeMax = MixUser
178         };
179
180 };
181
182 } } /* namespace */
183 #endif /* _ardour_surfaces_fp8base_h_ */