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