a77b4a67f0a270bdc6eae3fdbbb9d888134d631c
[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 #else
30 #define FP_NAMESPACE FP8
31 #endif
32
33 namespace ArdourSurface { namespace FP_NAMESPACE {
34
35 /* conveniece wrappers depending on "FP8Base& _base" */
36 #define fp8_loop dynamic_cast<BaseUI*>(&_base)->main_loop
37 #define fp8_context() dynamic_cast<BaseUI*>(&_base)
38 #define fp8_protocol() dynamic_cast<ControlProtocol*>(&_base)
39
40 /** Virtual abstract base of the FaderPort8 control surface
41  *
42  * This is passed as handle to all elements (buttons, lights,..)
43  * to inteface common functionality for the current instance:
44  *  - sending MIDI
45  *  - global events (signals)
46  *  - thread context
47  *
48  * It is implemented by FaderPort8
49  */
50 class FP8Base
51 {
52 public:
53         virtual ~FP8Base() {}
54
55         virtual size_t tx_midi (std::vector<uint8_t> const&) const = 0;
56         virtual std::string const& timecode () const = 0;
57         virtual std::string const& musical_time () const = 0;
58         virtual bool shift_mod () const = 0;
59         virtual bool show_meters () const = 0;
60         virtual bool show_panner () const = 0;
61         virtual bool twolinetext () const = 0;
62         virtual uint32_t clock_mode () const = 0;
63
64         size_t tx_midi2 (uint8_t sb, uint8_t d1) const
65         {
66                  std::vector<uint8_t> d;
67                  d.push_back (sb);
68                  d.push_back (d1);
69                  return tx_midi (d);
70         }
71
72         size_t tx_midi3 (uint8_t sb, uint8_t d1, uint8_t d2) const
73         {
74                  std::vector<uint8_t> d;
75                  d.push_back (sb);
76                  d.push_back (d1);
77                  d.push_back (d2);
78                  return tx_midi (d);
79         }
80
81         size_t tx_sysex (size_t count, ...)
82         {
83                  std::vector<uint8_t> d;
84                  sysexhdr (d);
85
86                  va_list var_args;
87                  va_start (var_args, count);
88                  for  (size_t i = 0; i < count; ++i)
89                  {
90                          // uint8_t {aka unsigned char} is promoted to β€˜int’ when passed through β€˜...’
91                          uint8_t b = va_arg (var_args, int);
92                          d.push_back (b);
93                  }
94                  va_end (var_args);
95
96                  d.push_back (0xf7);
97                  return tx_midi (d);
98         }
99
100         size_t tx_text (uint8_t id, uint8_t line, uint8_t align, std::string const& txt)
101         {
102                  std::vector<uint8_t> d;
103                  sysexhdr (d);
104                  d.push_back (0x12);
105                  d.push_back (id & 0x0f);
106                  d.push_back (line & 0x03);
107                  d.push_back (align & 0x07);
108
109                  for  (size_t i = 0; i < txt.size(); ++i)
110                  {
111                          d.push_back (txt[i]);
112                          if (i >= 8) {
113                                  break;
114                          }
115                  }
116                  d.push_back (0xf7);
117                  return tx_midi (d);
118         }
119
120         /* modifier keys */
121         PBD::Signal1<void, bool> ShiftButtonChange;
122         PBD::Signal1<void, bool> ARMButtonChange;
123
124         /* timer events */
125         PBD::Signal1<void, bool> BlinkIt;
126         PBD::Signal0<void> Periodic;
127
128 private:
129         void sysexhdr (std::vector<uint8_t>& d)
130         {
131                 /* faderport8 <SysExHdr> */
132                 d.push_back (0xf0);
133                 d.push_back (0x00);
134                 d.push_back (0x01);
135                 d.push_back (0x06);
136 #ifdef FADERPORT16
137                 d.push_back (0x16);
138 #else
139                 d.push_back (0x02);
140 #endif
141         }
142 };
143
144 namespace FP8Types {
145
146         enum FaderMode {
147                 ModeTrack,
148                 ModePlugins,
149                 ModeSend,
150                 ModePan
151         };
152
153         enum NavigationMode {
154                 NavChannel,
155                 NavZoom,
156                 NavScroll,
157                 NavBank,
158                 NavMaster,
159                 NavSection,
160                 NavMarker
161         };
162
163         enum MixMode {
164                 MixAudio,
165                 MixInstrument,
166                 MixBus,
167                 MixVCA,
168                 MixAll,
169                 MixInputs,
170                 MixMIDI,
171                 MixOutputs,
172                 MixFX,
173                 MixUser,
174                 MixModeMax = MixUser
175         };
176
177 };
178
179 } } /* namespace */
180 #endif /* _ardour_surfaces_fp8base_h_ */