Ardour  9.2-654-gd2ed0bd940
contourdesign.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Johannes Mueller <github@johannes-mueller.org>
3  * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef ardour_contourdesign_control_protocol_h
21 #define ardour_contourdesign_control_protocol_h
22 
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <glibmm/main.h>
28 
29 #if defined COMPILER_MSVC && defined WAF_BUILD
30 #define NOMINMAX
31 #endif
32 
33 #define ABSTRACT_UI_EXPORTS
34 #include "pbd/abstract_ui.h"
35 #include "ardour/types.h"
37 
38 struct libusb_device_handle;
39 struct libusb_transfer;
40 
41 class ContourDesignGUI;
42 
43 namespace ArdourSurface {
44 
45 struct ContourDesignControlUIRequest : public BaseUI::BaseRequestObject {
46 public:
49 };
50 
51 enum JumpUnit {
52  SECONDS = 0,
53  BEATS = 1,
54  BARS = 2
55 };
56 
57 struct JumpDistance {
58  JumpDistance () : value (1.0), unit (BEATS) {}
59  JumpDistance (double v, JumpUnit u) : value (v), unit (u) {}
60  JumpDistance (const JumpDistance& o) : value (o.value), unit (o.unit) {}
62  value = o.value;
63  unit = o.unit;
64  return *this;
65  }
66 
67  double value;
69 };
70 
71 class ButtonBase;
72 
73 
76  , public AbstractUI<ContourDesignControlUIRequest>
77 {
78 public:
81 
82  enum DeviceType {
83  None = 0,
87  };
88 
89  DeviceType device_type() const { return _device_type; }
90 
91  static bool available ();
92  static bool match_usb (uint16_t, uint16_t);
93 
94  int set_active (bool yn);
95 
96  XMLNode& get_state () const;
97  int set_state (const XMLNode&, int version);
98 
100 
101  void handle_event ();
102 
103  static const int num_shuttle_speeds = 7;
104 
107 
110 
111  std::shared_ptr<ButtonBase> make_button_action (std::string action_string);
112 
113  int usb_errorcode () const { return _error; }
114 
115  bool keep_rolling () const { return _keep_rolling; }
116  void set_keep_rolling (bool kr) { _keep_rolling = kr; }
117 
118  bool test_mode () const { return _test_mode; }
119  void set_test_mode (bool tm) { _test_mode = tm; }
120 
121  int get_button_count() const { return _button_actions.size(); }
122  const std::shared_ptr<ButtonBase> get_button_action (unsigned int index) const;
123  void set_button_action (unsigned int index, const std::shared_ptr<ButtonBase> btn_act);
124 
127 
128  void set_shuttle_speed (unsigned int index, double speed);
129  double shuttle_speed (unsigned int index) const {
130  return _shuttle_speeds[index];
131  }
132 
133  PBD::Signal<void(unsigned short)> ButtonPress;
134  PBD::Signal<void(unsigned short)> ButtonRelease;
135 
137 
138 private:
140  void start ();
141  void stop ();
142 
143  bool has_editor () const { return true; }
144  void* get_gui () const;
145  void tear_down_gui ();
146 
147  void thread_init ();
148 
150  void release_device ();
151 
153  void handle_button_press (unsigned short btn);
154  void handle_button_release (unsigned short btn);
155 
158 
160 
161  bool wait_for_event ();
162  GSource* _io_source;
163  libusb_device_handle* _dev_handle;
164  libusb_transfer* _usb_transfer;
166 
167  unsigned char _buf[5];
168 
170 
172 
173  struct State {
174  int8_t shuttle;
175  uint8_t jog;
176  uint16_t buttons;
177  };
179 
181 
182  // Config stuff
183 
185  std::vector<double> _shuttle_speeds;
187 
188  std::vector<std::shared_ptr<ButtonBase> > _button_actions;
189 
190  mutable ContourDesignGUI* _gui;
191  void build_gui ();
192 
193  int _error;
195 };
196 
197 
198 
200 {
201 public:
203  virtual ~ButtonBase () {}
204  virtual void execute () = 0;
205 
206  virtual XMLNode& get_state (XMLNode& node) const = 0;
207 
208 protected:
210 };
211 
212 
213 class ButtonJump : public ButtonBase
214 {
215 public:
217  : ButtonBase (ccp)
218  , _dist (dist) {}
220 
221  void execute ();
222  JumpDistance get_jump_distance () const { return _dist; };
223 
224  XMLNode& get_state (XMLNode& node) const;
225 
226 private:
228 };
229 
230 class ButtonAction : public ButtonBase
231 {
232 public:
233  ButtonAction (const std::string as, ContourDesignControlProtocol& ccp)
234  : ButtonBase (ccp)
235  , _action_string (as) {}
237 
238  void execute ();
239  std::string get_path () const { return _action_string; }
240 
241  XMLNode& get_state (XMLNode& node) const;
242 
243 private:
244  const std::string _action_string;
245 };
246 
247 
248 
249 } // namespace
250 
251 #endif /* ardour_contourdesign_control_protocol_h */
void None
Definition: TypeList.h:49
ButtonAction(const std::string as, ContourDesignControlProtocol &ccp)
std::string get_path() const
XMLNode & get_state(XMLNode &node) const
const std::string _action_string
ContourDesignControlProtocol & _spc
ButtonBase(ContourDesignControlProtocol &spc)
virtual void execute()=0
virtual XMLNode & get_state(XMLNode &node) const =0
ButtonJump(JumpDistance dist, ContourDesignControlProtocol &ccp)
JumpDistance get_jump_distance() const
XMLNode & get_state(XMLNode &node) const
void do_request(ContourDesignControlUIRequest *)
static bool match_usb(uint16_t, uint16_t)
void handle_button_press(unsigned short btn)
const std::shared_ptr< ButtonBase > get_button_action(unsigned int index) const
std::shared_ptr< ButtonBase > make_button_action(std::string action_string)
double shuttle_speed(unsigned int index) const
PBD::Signal< void(unsigned short)> ButtonPress
std::vector< std::shared_ptr< ButtonBase > > _button_actions
void handle_button_release(unsigned short btn)
void set_button_action(unsigned int index, const std::shared_ptr< ButtonBase > btn_act)
PBD::Signal< void(unsigned short)> ButtonRelease
void set_shuttle_speed(unsigned int index, double speed)
int set_state(const XMLNode &, int version)
Definition: xml++.h:114
JumpDistance(double v, JumpUnit u)
Definition: contourdesign.h:59
JumpDistance(const JumpDistance &o)
Definition: contourdesign.h:60
JumpDistance & operator=(const JumpDistance &o)
Definition: contourdesign.h:61