Ardour  9.0-pre0-582-g084a23a80d
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 #define ABSTRACT_UI_EXPORTS
30 #include "pbd/abstract_ui.h"
31 #include "ardour/types.h"
33 
34 struct libusb_device_handle;
35 struct libusb_transfer;
36 
37 class ContourDesignGUI;
38 
39 namespace ArdourSurface {
40 
41 struct ContourDesignControlUIRequest : public BaseUI::BaseRequestObject {
42 public:
45 };
46 
47 enum JumpUnit {
48  SECONDS = 0,
49  BEATS = 1,
50  BARS = 2
51 };
52 
53 struct JumpDistance {
54  JumpDistance () : value (1.0), unit (BEATS) {}
55  JumpDistance (double v, JumpUnit u) : value (v), unit (u) {}
56  JumpDistance (const JumpDistance& o) : value (o.value), unit (o.unit) {}
58  value = o.value;
59  unit = o.unit;
60  return *this;
61  }
62 
63  double value;
65 };
66 
67 class ButtonBase;
68 
69 
72  , public AbstractUI<ContourDesignControlUIRequest>
73 {
74 public:
77 
78  enum DeviceType {
79  None = 0,
83  };
84 
85  DeviceType device_type() const { return _device_type; }
86 
87  static bool available ();
88  static bool match_usb (uint16_t, uint16_t);
89 
90  int set_active (bool yn);
91 
92  XMLNode& get_state () const;
93  int set_state (const XMLNode&, int version);
94 
96 
97  void handle_event ();
98 
99  static const int num_shuttle_speeds = 7;
100 
103 
106 
107  std::shared_ptr<ButtonBase> make_button_action (std::string action_string);
108 
109  int usb_errorcode () const { return _error; }
110 
111  bool keep_rolling () const { return _keep_rolling; }
112  void set_keep_rolling (bool kr) { _keep_rolling = kr; }
113 
114  bool test_mode () const { return _test_mode; }
115  void set_test_mode (bool tm) { _test_mode = tm; }
116 
117  int get_button_count() const { return _button_actions.size(); }
118  const std::shared_ptr<ButtonBase> get_button_action (unsigned int index) const;
119  void set_button_action (unsigned int index, const std::shared_ptr<ButtonBase> btn_act);
120 
123 
124  void set_shuttle_speed (unsigned int index, double speed);
125  double shuttle_speed (unsigned int index) const {
126  return _shuttle_speeds[index];
127  }
128 
129  PBD::Signal<void(unsigned short)> ButtonPress;
130  PBD::Signal<void(unsigned short)> ButtonRelease;
131 
133 
134 private:
136  void start ();
137  void stop ();
138 
139  bool has_editor () const { return true; }
140  void* get_gui () const;
141  void tear_down_gui ();
142 
143  void thread_init ();
144 
146  void release_device ();
147 
149  void handle_button_press (unsigned short btn);
150  void handle_button_release (unsigned short btn);
151 
154 
156 
157  bool wait_for_event ();
158  GSource* _io_source;
159  libusb_device_handle* _dev_handle;
160  libusb_transfer* _usb_transfer;
162 
163  unsigned char _buf[5];
164 
166 
168 
169  struct State {
170  int8_t shuttle;
171  uint8_t jog;
172  uint16_t buttons;
173  };
175 
177 
178  // Config stuff
179 
181  std::vector<double> _shuttle_speeds;
183 
184  std::vector<std::shared_ptr<ButtonBase> > _button_actions;
185 
186  mutable ContourDesignGUI* _gui;
187  void build_gui ();
188 
189  int _error;
191 };
192 
193 
194 
196 {
197 public:
199  virtual ~ButtonBase () {}
200  virtual void execute () = 0;
201 
202  virtual XMLNode& get_state (XMLNode& node) const = 0;
203 
204 protected:
206 };
207 
208 
209 class ButtonJump : public ButtonBase
210 {
211 public:
213  : ButtonBase (ccp)
214  , _dist (dist) {}
216 
217  void execute ();
218  JumpDistance get_jump_distance () const { return _dist; };
219 
220  XMLNode& get_state (XMLNode& node) const;
221 
222 private:
224 };
225 
226 class ButtonAction : public ButtonBase
227 {
228 public:
229  ButtonAction (const std::string as, ContourDesignControlProtocol& ccp)
230  : ButtonBase (ccp)
231  , _action_string (as) {}
233 
234  void execute ();
235  std::string get_path () const { return _action_string; }
236 
237  XMLNode& get_state (XMLNode& node) const;
238 
239 private:
240  const std::string _action_string;
241 };
242 
243 
244 
245 } // namespace
246 
247 #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:55
JumpDistance(const JumpDistance &o)
Definition: contourdesign.h:56
JumpDistance & operator=(const JumpDistance &o)
Definition: contourdesign.h:57