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