Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / surfaces / mackie / surface.h
1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.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 mackie_surface_h
21 #define mackie_surface_h
22
23 #include <stdint.h>
24
25 #include <sigc++/trackable.h>
26
27 #include "pbd/signals.h"
28 #include "pbd/xml++.h"
29 #include "midi++/types.h"
30
31 #include "ardour/types.h"
32
33 #include "control_protocol/types.h"
34
35 #include "controls.h"
36 #include "types.h"
37 #include "jog_wheel.h"
38
39 namespace MIDI {
40         class Parser;
41 }
42
43 namespace ARDOUR {
44         class Stripable;
45         class Port;
46 }
47
48 class MidiByteArray;
49
50 namespace ArdourSurface {
51
52 class MackieControlProtocol;
53
54 namespace Mackie
55 {
56
57 class MackieButtonHandler;
58 class SurfacePort;
59 class MackieMidiBuilder;
60 class Button;
61 class Meter;
62 class Fader;
63 class Jog;
64 class Pot;
65 class Led;
66
67 class Surface : public PBD::ScopedConnectionList, public sigc::trackable
68 {
69 public:
70         Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
71         virtual ~Surface();
72
73         surface_type_t type() const { return _stype; }
74         uint32_t number() const { return _number; }
75         const std::string& name() { return _name; }
76
77         void connected ();
78
79         bool active() const { return _active; }
80
81         typedef std::vector<Control*> Controls;
82         Controls controls;
83
84         std::map<int,Fader*> faders;
85         std::map<int,Pot*> pots;
86         std::map<int,Button*> buttons; // index is device-DEPENDENT
87         std::map<int,Led*> leds;
88         std::map<int,Meter*> meters;
89         std::map<int,Control*> controls_by_device_independent_id;
90
91         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
92         Fader* master_fader() const { return _master_fader; }
93
94         /// The collection of all numbered strips.
95         typedef std::vector<Strip*> Strips;
96         Strips strips;
97
98         uint32_t n_strips (bool with_locked_strips = true) const;
99         Strip* nth_strip (uint32_t n) const;
100
101         bool stripable_is_locked_to_strip (boost::shared_ptr<ARDOUR::Stripable>) const;
102         bool stripable_is_mapped (boost::shared_ptr<ARDOUR::Stripable>) const;
103
104         /// This collection owns the groups
105         typedef std::map<std::string,Group*> Groups;
106         Groups groups;
107
108         SurfacePort& port() const { return *_port; }
109
110         void map_stripables (const std::vector<boost::shared_ptr<ARDOUR::Stripable> >&);
111
112         void update_strip_selection ();
113
114         const MidiByteArray& sysex_hdr() const;
115
116         void periodic (ARDOUR::microseconds_t now_usecs);
117         void redisplay (ARDOUR::microseconds_t now_usecs, bool force);
118         void hui_heartbeat ();
119
120         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
121         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
122         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
123
124         /// Connect the any signal from the parser to handle_midi_any
125         /// unless it's already connected
126         void connect_to_signals ();
127
128         /// write a sysex message
129         void write_sysex (const MidiByteArray& mba);
130         void write_sysex (MIDI::byte msg);
131         /// proxy write for port
132         void write (const MidiByteArray&);
133
134         /// display an indicator of the first switched-in Route. Do nothing by default.
135         void display_bank_start (uint32_t /*current_bank*/);
136
137         /// called from MackieControlProtocol::zero_all to turn things off
138         void zero_all ();
139         void zero_controls ();
140
141         /// turn off leds around the jog wheel. This is for surfaces that use a pot
142         /// pretending to be a jog wheel.
143         void blank_jog_ring ();
144
145         void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
146
147         /// sends MCP "reset" message to surface
148         void reset ();
149
150         void recalibrate_faders ();
151         void toggle_backlight ();
152         void set_touch_sensitivity (int);
153
154         /**
155                 This is used to calculate the clicks per second that define
156                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
157                 per second, 50.5 is 5 clicks per second.
158         */
159         float scrub_scaling_factor() const;
160
161         /**
162                 The scaling factor function for speed increase and decrease. At
163                 low transport speeds this should return a small value, for high transport
164                 speeds, this should return an exponentially larger value. This provides
165                 high definition control at low speeds and quick speed changes to/from
166                 higher speeds.
167         */
168         float scaled_delta (float delta, float current_speed);
169
170         // display the first 2 chars of the msg in the 2 char display
171         // . is appended to the previous character, so A.B. would
172         // be two characters
173         void show_two_char_display (const std::string & msg, const std::string & dots = "  ");
174         void show_two_char_display (unsigned int value, const std::string & dots = "  ");
175
176         void update_view_mode_display (bool with_helpful_text);
177         void update_flip_mode_display ();
178
179         void subview_mode_changed ();
180
181         MackieControlProtocol& mcp() const { return _mcp; }
182
183         void next_jog_mode ();
184         void set_jog_mode (Mackie::JogWheel::Mode);
185
186         void notify_metering_state_changed();
187         void turn_it_on ();
188
189         void display_message_for (std::string const& msg, uint64_t msecs);
190
191         bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
192
193         void master_monitor_may_have_changed ();
194
195         XMLNode& get_state ();
196         int set_state (const XMLNode&, int version);
197
198         bool get_qcon_flag() { return is_qcon; }
199
200   private:
201         MackieControlProtocol& _mcp;
202         SurfacePort*           _port;
203         surface_type_t         _stype;
204         uint32_t               _number;
205         std::string            _name;
206         bool                   _active;
207         bool                   _connected;
208         Mackie::JogWheel*      _jog_wheel;
209         Fader*                 _master_fader;
210         float                  _last_master_gain_written;
211         PBD::ScopedConnection   master_connection;
212
213         void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
214         MidiByteArray host_connection_query (MidiByteArray& bytes);
215         MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
216
217         void say_hello ();
218         void init_controls ();
219         void init_strips (uint32_t n);
220         void setup_master ();
221         void master_gain_changed ();
222
223         enum ConnectionState {
224                 InputConnected = 0x1,
225                 OutputConnected = 0x2
226         };
227
228         int connection_state;
229
230         // QCon Flag
231         bool is_qcon;
232
233         MidiByteArray display_line (std::string const& msg, int line_num);
234
235   public:
236         /* IP MIDI devices need to keep a handle on this and destroy it */
237         GSource*    input_source;
238 };
239
240 }
241 }
242
243 #endif