Ardour  9.0-pre0-384-ga76afae0e9
fp8_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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 of the License, or
7  * (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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 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 
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  if (txt[i] < 0) {
114  continue;
115  }
116  d.push_back (txt[i]);
117  if (i >= 8) {
118  break;
119  }
120  }
121  d.push_back (0xf7);
122  return tx_midi (d);
123  }
124 
125  /* modifier keys */
128 
129  /* timer events */
130  PBD::Signal<void(bool)> BlinkIt;
132 
133 private:
134  void sysexhdr (std::vector<uint8_t>& d)
135  {
136  /* faderport8 <SysExHdr> */
137  d.push_back (0xf0);
138  d.push_back (0x00);
139  d.push_back (0x01);
140  d.push_back (0x06);
141 #ifdef FADERPORT16
142  d.push_back (0x16);
143 #else
144  d.push_back (0x02);
145 #endif
146  }
147 };
148 
149 namespace FP8Types {
150 
151  enum FaderMode {
155  ModePan
156  };
157 
166  NavPan /* FP2 only */
167  };
168 
169  enum MixMode {
181  };
182 
183 };
184 
185 } } /* namespace */
186 #endif /* _ardour_surfaces_fp8base_h_ */
size_t tx_sysex(size_t count,...)
Definition: fp8_base.h:83
virtual bool twolinetext() const =0
virtual size_t tx_midi(std::vector< uint8_t > const &) const =0
virtual bool show_panner() const =0
virtual uint32_t clock_mode() const =0
virtual bool show_meters() const =0
size_t tx_midi2(uint8_t sb, uint8_t d1) const
Definition: fp8_base.h:66
PBD::Signal< void()> Periodic
Definition: fp8_base.h:131
void sysexhdr(std::vector< uint8_t > &d)
Definition: fp8_base.h:134
virtual std::string const & musical_time() const =0
size_t tx_midi3(uint8_t sb, uint8_t d1, uint8_t d2) const
Definition: fp8_base.h:74
virtual std::string const & timecode() const =0
virtual bool shift_mod() const =0
PBD::Signal< void(bool)> BlinkIt
Definition: fp8_base.h:130
PBD::Signal< void(bool)> ShiftButtonChange
Definition: fp8_base.h:126
PBD::Signal< void(bool)> ARMButtonChange
Definition: fp8_base.h:127
size_t tx_text(uint8_t id, uint8_t line, uint8_t align, std::string const &txt)
Definition: fp8_base.h:102
#define FP_NAMESPACE
Definition: fp8_base.h:32