Ardour  9.2-129-gdf5e1050bd
cc121.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 W.P. van Paass
3  * Copyright (C) 2017-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
5  *
6  * Thanks to Rolf Meyerhoff for reverse engineering the CC121 protocol.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef ardour_surface_cc121_h
24 #define ardour_surface_cc121_h
25 
26 #include <list>
27 #include <map>
28 #include <set>
29 
30 #define ABSTRACT_UI_EXPORTS
31 #include "pbd/abstract_ui.h"
32 
33 #include "ardour/types.h"
34 
36 
37 namespace PBD {
38  class Controllable;
39 }
40 
41 #include <midi++/types.h>
42 
43 //#include "midi_byte_array.h"
44 #include "control_protocol/types.h"
45 
46 #include <glibmm/main.h>
47 
48 namespace MIDI {
49  class Parser;
50  class Port;
51 }
52 
53 
54 namespace ARDOUR {
55  class AsyncMIDIPort;
56  class Bundle;
57  class Port;
58  class Session;
59  class MidiPort;
60 }
61 
62 
63 class MIDIControllable;
64 class MIDIFunction;
65 class MIDIAction;
66 
67 namespace ArdourSurface {
68 
69 struct CC121Request : public BaseUI::BaseRequestObject {
70 public:
73 };
74 
75 class CC121 : public ARDOUR::ControlProtocol, public AbstractUI<CC121Request> {
76  public:
78  virtual ~CC121();
79 
80  int set_active (bool yn);
81 
82  XMLNode& get_state () const;
83  int set_state (const XMLNode&, int version);
84 
85  bool has_editor () const { return true; }
86  void* get_gui () const;
87  void tear_down_gui ();
88 
89 
90  /* Note: because the CC121 speaks an inherently duplex protocol,
91  we do not implement get/set_feedback() since this aspect of
92  support for the protocol is not optional.
93  */
94 
96  int stop ();
97 
98  void thread_init ();
99 
101 
102  std::shared_ptr<ARDOUR::Port> input_port();
103  std::shared_ptr<ARDOUR::Port> output_port();
104 
105  enum ButtonID {
106  Rec = 0x00,
107  Solo = 0x08,
108  Mute = 0x10,
109  Left = 0x30,
110  Right = 0x31,
111  EButton = 0x33,
112  Function1 = 0x36,
113  Function2 = 0x37,
114  Function3 = 0x38,
115  Function4 = 0x39,
116  Value = 0x3A,
117  Footswitch = 0x3B,
118  FP_Read = 0x4A,
119  FP_Write = 0x4B,
120  Loop = 0x56,
121  ToStart = 0x58,
122  ToEnd = 0x5A,
123  Rewind = 0x5B,
124  Ffwd = 0x5C,
125  Stop = 0x5D,
126  Play = 0x5E,
127  RecEnable = 0x5F,
128  FaderTouch = 0x68,
129  EQ1Enable = 0x70,
130  EQ2Enable = 0x71,
131  EQ3Enable = 0x72,
132  EQ4Enable = 0x73,
133  EQType = 0x74,
134  AllBypass = 0x75,
135  Jog = 0x76,
136  Lock = 0x77,
137  InputMonitor = 0x78,
138  OpenVST = 0x79,
139  Output = 22
140  };
141 
142  enum ButtonState {
143  ShiftDown = 0x1,
144  RewindDown = 0x2,
145  StopDown = 0x4,
146  UserDown = 0x8,
147  LongPress = 0x10
148  };
149 
150  void set_action (ButtonID, std::string const& action_name, bool on_press, CC121::ButtonState = ButtonState (0));
151  std::string get_action (ButtonID, bool on_press, CC121::ButtonState = ButtonState (0));
152 
153  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
154 
156 
157  private:
158  std::shared_ptr<ARDOUR::Stripable> _current_stripable;
159  std::weak_ptr<ARDOUR::Stripable> pre_master_stripable;
160  std::weak_ptr<ARDOUR::Stripable> pre_monitor_stripable;
161 
162  std::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
163  std::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
164 
165  // Bundle to represent our input ports
166  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
167  // Bundle to represent our output ports
168  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
169 
171 
172  bool midi_input_handler (Glib::IOCondition ioc, std::shared_ptr<ARDOUR::AsyncMIDIPort> port);
173 
174  mutable void *gui;
175  void build_gui ();
176 
177  bool connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
179 
182  OutputConnected = 0x2
183  };
184 
186  void connected ();
191  enum JogMode { scroll=1, zoom=2 };
193 
197 
202  /* void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);*/
203 
205 
206  friend class Button;
207 
208  class Button {
209  public:
210 
211  enum ActionType {
214  };
215 
216  Button (CC121& f, std::string const& str, ButtonID i)
217  : fp (f)
218  , name (str)
219  , id (i)
220  , flash (false)
221  {}
222 
223  void set_action (std::string const& action_name, bool on_press, CC121::ButtonState = ButtonState (0));
224  void set_action (std::function<void()> function, bool on_press, CC121::ButtonState = ButtonState (0));
225  std::string get_action (bool press, CC121::ButtonState bs = ButtonState (0));
226 
227  void set_led_state (std::shared_ptr<MIDI::Port>, bool onoff);
228  void invoke (ButtonState bs, bool press);
229  bool uses_flash () const { return flash; }
230  void set_flash (bool yn) { flash = yn; }
231 
232  XMLNode& get_state () const;
233  int set_state (XMLNode const&);
234 
235  sigc::connection timeout_connection;
236 
237  private:
239  std::string name;
241  bool flash;
242 
243  struct ToDo {
245  /* could be a union if std::function didn't require a
246  * constructor
247  */
248  std::string action_name;
249  std::function<void()> function;
250  };
251 
252  typedef std::map<CC121::ButtonState,ToDo> ToDoMap;
255  };
256 
257  typedef std::map<ButtonID,Button> ButtonMap;
258 
261 
262  std::set<ButtonID> buttons_down;
263  std::set<ButtonID> consumed;
264 
265  void all_lights_out ();
266  void close ();
269 
274 
275  sigc::connection periodic_connection;
276  bool periodic ();
277 
278  sigc::connection heartbeat_connection;
279  sigc::connection blink_connection;
280  typedef std::list<ButtonID> Blinkers;
283  bool blink ();
284  bool beat ();
287 
288  void set_current_stripable (std::shared_ptr<ARDOUR::Stripable>);
290  void use_master ();
291  void use_monitor ();
295 
297  void map_solo ();
298  void map_mute ();
300  void map_recenable ();
301  void map_gain ();
302  void map_cut ();
303  void map_auto ();
304  void map_monitoring ();
305 
306  /* operations (defined in operations.cc) */
307 
308  void read ();
309  void write ();
310 
311  void input_monitor ();
312  void left ();
313  void right ();
314 
315  void touch ();
316  void off ();
317 
318  void undo ();
319  void redo ();
320  void solo ();
321  void mute ();
322  void jog ();
323  void rec_enable ();
324 
325  void set_controllable (std::shared_ptr<ARDOUR::AutomationControl>, float);
326 
327  void punch ();
328 };
329 
330 }
331 
332 #endif /* ardour_surface_cc121_h */
Button(CC121 &f, std::string const &str, ButtonID i)
Definition: cc121.h:216
sigc::connection timeout_connection
Definition: cc121.h:235
XMLNode & get_state() const
bool uses_flash() const
Definition: cc121.h:229
void set_led_state(std::shared_ptr< MIDI::Port >, bool onoff)
void invoke(ButtonState bs, bool press)
int set_state(XMLNode const &)
std::string get_action(bool press, CC121::ButtonState bs=ButtonState(0))
void set_action(std::string const &action_name, bool on_press, CC121::ButtonState=ButtonState(0))
void set_action(std::function< void()> function, bool on_press, CC121::ButtonState=ButtonState(0))
std::map< CC121::ButtonState, ToDo > ToDoMap
Definition: cc121.h:252
void set_flash(bool yn)
Definition: cc121.h:230
std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
std::shared_ptr< ARDOUR::AsyncMIDIPort > _input_port
Definition: cc121.h:162
bool midi_input_handler(Glib::IOCondition ioc, std::shared_ptr< ARDOUR::AsyncMIDIPort > port)
sigc::connection blink_connection
Definition: cc121.h:279
CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL()
std::shared_ptr< ARDOUR::AsyncMIDIPort > _output_port
Definition: cc121.h:163
void encoder_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
void stop_blinking(ButtonID)
std::string get_action(ButtonID, bool on_press, CC121::ButtonState=ButtonState(0))
std::set< ButtonID > consumed
Definition: cc121.h:263
PBD::ScopedConnectionList session_connections
Definition: cc121.h:270
Button & get_button(ButtonID) const
void connect_session_signals()
void button_press_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
std::shared_ptr< ARDOUR::Port > output_port()
int last_encoder_delta
Definition: cc121.h:196
PBD::ScopedConnectionList midi_connections
Definition: cc121.h:170
CC121(ARDOUR::Session &)
void stripable_selection_changed()
sigc::connection heartbeat_connection
Definition: cc121.h:278
XMLNode & get_state() const
JogMode _jogmode
Definition: cc121.h:192
bool has_editor() const
Definition: cc121.h:85
PBD::Signal< void()> ConnectionChange
Definition: cc121.h:100
std::shared_ptr< ARDOUR::Port > input_port()
std::shared_ptr< ARDOUR::Bundle > _input_bundle
Definition: cc121.h:166
std::map< ButtonID, Button > ButtonMap
Definition: cc121.h:257
PBD::microseconds_t last_encoder_time
Definition: cc121.h:194
void set_current_stripable(std::shared_ptr< ARDOUR::Stripable >)
bool connection_handler(std::weak_ptr< ARDOUR::Port >, std::string name1, std::weak_ptr< ARDOUR::Port >, std::string name2, bool yn)
void set_controllable(std::shared_ptr< ARDOUR::AutomationControl >, float)
bool fader_is_touched
Definition: cc121.h:190
ButtonMap buttons
Definition: cc121.h:259
void set_action(ButtonID, std::string const &action_name, bool on_press, CC121::ButtonState=ButtonState(0))
std::shared_ptr< ARDOUR::Stripable > _current_stripable
Definition: cc121.h:158
std::weak_ptr< ARDOUR::Stripable > pre_monitor_stripable
Definition: cc121.h:160
Blinkers blinkers
Definition: cc121.h:281
int set_active(bool yn)
int set_state(const XMLNode &, int version)
int last_good_encoder_delta
Definition: cc121.h:195
ButtonState button_state
Definition: cc121.h:204
std::set< ButtonID > buttons_down
Definition: cc121.h:262
sigc::connection periodic_connection
Definition: cc121.h:275
void start_blinking(ButtonID)
void do_request(CC121Request *)
std::shared_ptr< ARDOUR::Bundle > _output_bundle
Definition: cc121.h:168
int last_last_encoder_delta
Definition: cc121.h:196
void button_release_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
PBD::ScopedConnection selection_connection
Definition: cc121.h:293
PBD::ScopedConnectionList stripable_connections
Definition: cc121.h:294
void * get_gui() const
std::list< ButtonID > Blinkers
Definition: cc121.h:280
PBD::ScopedConnection port_connection
Definition: cc121.h:178
bool rec_enable_state
Definition: cc121.h:299
std::weak_ptr< ARDOUR::Stripable > pre_master_stripable
Definition: cc121.h:159
void fader_handler(MIDI::Parser &, MIDI::pitchbend_t pb)
Definition: xml++.h:114
std::shared_ptr< PBD::Controllable > Controllable
Definition: console1.h:80
unsigned short pitchbend_t
Definition: axis_view.h:42
int64_t microseconds_t
Definition: microseconds.h:28
Definition: lobject.h:100