40af712c1d8ab699ea2d95c3f4873894f9dbf651
[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 std::string const& musical_time () const = 0;
52         virtual bool shift_mod () const = 0;
53         virtual bool show_meters () const = 0;
54         virtual bool show_panner () const = 0;
55         virtual bool twolinetext () const = 0;
56         virtual uint32_t clock_mode () const = 0;
57
58         size_t tx_midi2 (uint8_t sb, uint8_t d1) const
59         {
60                  std::vector<uint8_t> d;
61                  d.push_back (sb);
62                  d.push_back (d1);
63                  return tx_midi (d);
64         }
65
66         size_t tx_midi3 (uint8_t sb, uint8_t d1, uint8_t d2) const
67         {
68                  std::vector<uint8_t> d;
69                  d.push_back (sb);
70                  d.push_back (d1);
71                  d.push_back (d2);
72                  return tx_midi (d);
73         }
74
75         size_t tx_sysex (size_t count, ...)
76         {
77                  std::vector<uint8_t> d;
78                  sysexhdr (d);
79
80                  va_list var_args;
81                  va_start (var_args, count);
82                  for  (size_t i = 0; i < count; ++i)
83                  {
84                          // uint8_t {aka unsigned char} is promoted to β€˜int’ when passed through β€˜...’
85                          uint8_t b = va_arg (var_args, int);
86                          d.push_back (b);
87                  }
88                  va_end (var_args);
89
90                  d.push_back (0xf7);
91                  return tx_midi (d);
92         }
93
94         size_t tx_text (uint8_t id, uint8_t line, uint8_t align, std::string const& txt)
95         {
96                  std::vector<uint8_t> d;
97                  sysexhdr (d);
98                  d.push_back (0x12);
99                  d.push_back (id & 0x07);
100                  d.push_back (line & 0x03);
101                  d.push_back (align & 0x07);
102
103                  for  (size_t i = 0; i < txt.size(); ++i)
104                  {
105                          d.push_back (txt[i]);
106                          if (i >= 8) {
107                                  break;
108                          }
109                  }
110                  d.push_back (0xf7);
111                  return tx_midi (d);
112         }
113
114         /* modifier keys */
115         PBD::Signal1<void, bool> ShiftButtonChange;
116         PBD::Signal1<void, bool> ARMButtonChange;
117
118         /* timer events */
119         PBD::Signal1<void, bool> BlinkIt;
120         PBD::Signal0<void> Periodic;
121
122 private:
123         void sysexhdr (std::vector<uint8_t>& d)
124         {
125                 /* faderport8 <SysExHdr> */
126                 d.push_back (0xf0);
127                 d.push_back (0x00);
128                 d.push_back (0x01);
129                 d.push_back (0x06);
130                 d.push_back (0x02);
131         }
132 };
133
134 namespace FP8Types {
135
136         enum FaderMode {
137                 ModeTrack,
138                 ModePlugins,
139                 ModeSend,
140                 ModePan
141         };
142
143         enum NavigationMode {
144                 NavChannel,
145                 NavZoom,
146                 NavScroll,
147                 NavBank,
148                 NavMaster,
149                 NavSection,
150                 NavMarker
151         };
152
153         enum MixMode {
154                 MixAudio,
155                 MixInstrument,
156                 MixBus,
157                 MixVCA,
158                 MixAll,
159                 MixInputs,
160                 MixMIDI,
161                 MixOutputs,
162                 MixFX,
163                 MixUser,
164                 MixModeMax = MixUser
165         };
166
167 };
168
169 } /* namespace */
170 #endif /* _ardour_surfaces_fp8base_h_ */