Ardour  9.0-pre0-582-g084a23a80d
faderport.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015 Ben Loftis <ben@harrisonconsoles.com>
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_surface_faderport_h
21 #define ardour_surface_faderport_h
22 
23 #include <list>
24 #include <map>
25 #include <set>
26 #include <glibmm/threads.h>
27 
28 #define ABSTRACT_UI_EXPORTS
29 #include "pbd/abstract_ui.h"
30 
31 #include "ardour/types.h"
32 
34 
35 namespace PBD {
36  class Controllable;
37 }
38 
39 #include <midi++/types.h>
40 
43 
44 #include "glibmm/main.h"
45 
46 namespace MIDI {
47  class Parser;
48  class Port;
49 }
50 
51 
52 namespace ARDOUR {
53  class AsyncMIDIPort;
54  class Bundle;
55  class Port;
56  class Session;
57  class MidiPort;
58 }
59 
60 
61 class MIDIControllable;
62 class MIDIFunction;
63 class MIDIAction;
64 
65 namespace ArdourSurface {
66 
67 class FaderPort : public MIDISurface {
68  public:
70  virtual ~FaderPort();
71 
72  int set_active (bool yn);
73 
74  std::string input_port_name () const;
75  std::string output_port_name () const;
76 
77  XMLNode& get_state () const;
78  int set_state (const XMLNode&, int version);
79 
80  bool has_editor () const { return true; }
81  void* get_gui () const;
82  void tear_down_gui ();
83 
84  /* Note: because the FaderPort speaks an inherently duplex protocol,
85  we do not implement get/set_feedback() since this aspect of
86  support for the protocol is not optional.
87  */
88 
89  /* In a feat of engineering brilliance, the Presonus Faderport sends
90  * one button identifier when the button is pressed/released, but
91  * responds to another button identifier as a command to light the LED
92  * corresponding to the button. These ID's define what is sent
93  * for press/release; a separate data structure contains information
94  * on what to send to turn the LED on/off.
95  *
96  * One can only conclude that Presonus just didn't want to fix this
97  * issue because it contradicts their own documentation and is more or
98  * less the first thing you discover when programming the device.
99  */
100 
101  enum ButtonID {
102  Mute = 18,
103  Solo = 17,
104  Rec = 16,
105  Left = 19,
106  Bank = 20,
107  Right = 21,
108  Output = 22,
109  FP_Read = 10,
110  FP_Write = 9,
111  FP_Touch = 8,
112  FP_Off = 23,
113  Mix = 11,
114  Proj = 12,
115  Trns = 13,
116  Undo = 14,
117  Shift = 2,
118  Punch = 1,
119  User = 0,
120  Loop = 15,
121  Rewind = 3,
122  Ffwd = 4,
123  Stop = 5,
124  Play = 6,
126  Footswitch = 126,
127  FaderTouch = 127,
128  };
129 
130  enum ButtonState {
131  ShiftDown = 0x1,
132  RewindDown = 0x2,
133  StopDown = 0x4,
134  /* gap when we removed UserMode as a modifier */
135  LongPress = 0x10
136  };
137 
138  void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
139  std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
140 
144 
145  private:
146  std::shared_ptr<ARDOUR::Stripable> _current_stripable;
147  std::weak_ptr<ARDOUR::Stripable> pre_master_stripable;
148  std::weak_ptr<ARDOUR::Stripable> pre_monitor_stripable;
149 
150  mutable void *gui;
151  void build_gui ();
152 
153  void connected ();
157 
161 
166 
169  int device_acquire () { return 0; }
170  void device_release () { }
171  void run_event_loop ();
173 
175 
176  friend class Button;
177 
178  class Button {
179  public:
180 
181  enum ActionType {
184  };
185 
186  Button (FaderPort& f, std::string const& str, ButtonID i, int o)
187  : fp (f)
188  , name (str)
189  , id (i)
190  , out (o)
191  , flash (false)
192  {}
193 
194  void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
195  void set_action (std::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
196  std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
197 
198  void set_led_state (bool onoff);
199  bool invoke (ButtonState bs, bool press);
200  bool uses_flash () const { return flash; }
201  void set_flash (bool yn) { flash = yn; }
202 
203  XMLNode& get_state () const;
204  int set_state (XMLNode const&);
205 
206  sigc::connection timeout_connection;
207 
208  private:
210  std::string name;
212  int out;
213  bool flash;
214 
215  struct ToDo {
217  /* could be a union if std::function didn't require a
218  * constructor
219  */
220  std::string action_name;
221  std::function<void()> function;
222  };
223 
224  typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
227  };
228 
229  typedef std::map<ButtonID,Button> ButtonMap;
230 
233 
234  std::set<ButtonID> buttons_down;
235  std::set<ButtonID> consumed;
236 
239 
240  void all_lights_out ();
241 
244 
245  sigc::connection periodic_connection;
246  bool periodic ();
247 
248  sigc::connection blink_connection;
249  typedef std::list<ButtonID> Blinkers;
252  bool blink ();
255 
256  void set_current_stripable (std::shared_ptr<ARDOUR::Stripable>);
258  void use_master ();
259  void use_monitor ();
263 
265  void map_solo ();
266  void map_mute ();
268  void map_recenable ();
269  void map_gain ();
270  void map_cut ();
271  void map_auto ();
272  void parameter_changed (std::string);
273 
274  /* operations (defined in operations.cc) */
275 
276  void read ();
277  void write ();
278 
279  void left ();
280  void right ();
281 
282  void touch ();
283  void off ();
284 
285  void undo ();
286  void redo ();
287  void solo ();
288  void mute ();
289  void rec_enable ();
290 
291  void pan_azimuth (int);
292  void pan_width (int);
293 
294  void punch ();
295 };
296 
297 }
298 
299 #endif /* ardour_surface_faderport_h */
sigc::connection timeout_connection
Definition: faderport.h:206
int set_state(XMLNode const &)
void set_action(std::string const &action_name, bool on_press, FaderPort::ButtonState=ButtonState(0))
void set_action(std::function< void()> function, bool on_press, FaderPort::ButtonState=ButtonState(0))
Button(FaderPort &f, std::string const &str, ButtonID i, int o)
Definition: faderport.h:186
bool invoke(ButtonState bs, bool press)
std::string get_action(bool press, FaderPort::ButtonState bs=ButtonState(0))
std::map< FaderPort::ButtonState, ToDo > ToDoMap
Definition: faderport.h:224
std::weak_ptr< ARDOUR::Stripable > pre_monitor_stripable
Definition: faderport.h:148
std::weak_ptr< ARDOUR::Stripable > pre_master_stripable
Definition: faderport.h:147
void set_action(ButtonID, std::string const &action_name, bool on_press, FaderPort::ButtonState=ButtonState(0))
FaderPort(ARDOUR::Session &)
Button & get_button(ButtonID) const
std::list< ButtonID > Blinkers
Definition: faderport.h:249
void stop_blinking(ButtonID)
std::string get_action(ButtonID, bool on_press, FaderPort::ButtonState=ButtonState(0))
int set_state(const XMLNode &, int version)
void handle_midi_controller_message(MIDI::Parser &, MIDI::EventTwoBytes *tb)
bool button_long_press_timeout(ButtonID id)
ButtonState button_state
Definition: faderport.h:174
sigc::connection blink_connection
Definition: faderport.h:248
void parameter_changed(std::string)
std::shared_ptr< ARDOUR::Stripable > _current_stripable
Definition: faderport.h:146
void start_press_timeout(Button &, ButtonID)
void * get_gui() const
bool has_editor() const
Definition: faderport.h:80
std::set< ButtonID > buttons_down
Definition: faderport.h:234
std::string output_port_name() const
void handle_midi_sysex(MIDI::Parser &p, MIDI::byte *, size_t)
std::string input_port_name() const
PBD::ScopedConnection selection_connection
Definition: faderport.h:261
XMLNode & get_state() const
PBD::microseconds_t last_encoder_time
Definition: faderport.h:158
void start_blinking(ButtonID)
void handle_midi_polypressure_message(MIDI::Parser &, MIDI::EventTwoBytes *tb)
sigc::connection periodic_connection
Definition: faderport.h:245
std::set< ButtonID > consumed
Definition: faderport.h:235
PBD::ScopedConnectionList stripable_connections
Definition: faderport.h:262
void set_current_stripable(std::shared_ptr< ARDOUR::Stripable >)
std::map< ButtonID, Button > ButtonMap
Definition: faderport.h:229
void handle_midi_pitchbend_message(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