87c96b3687b30513247e5b3ca2929246273a5faa
[ardour.git] / libs / surfaces / mackie / strip.h
1 #ifndef __ardour_mackie_control_protocol_strip_h__
2 #define __ardour_mackie_control_protocol_strip_h__
3
4 #include <string>
5 #include <iostream>
6
7 #include "evoral/Parameter.hpp"
8
9 #include "pbd/property_basics.h"
10 #include "pbd/ringbuffer.h"
11 #include "pbd/signals.h"
12
13 #include "ardour/types.h"
14 #include "control_protocol/types.h"
15
16 #include "control_group.h"
17 #include "types.h"
18 #include "midi_byte_array.h"
19 #include "device_info.h"
20
21 namespace ARDOUR {
22         class Route;
23         class Bundle;
24         class ChannelCount;
25 }
26
27 namespace ArdourSurface {
28
29 namespace Mackie {
30
31 class Control;
32 class Surface;
33 class Button;
34 class Pot;
35 class Fader;
36 class Meter;
37 class SurfacePort;
38
39 struct GlobalControlDefinition {
40     const char* name;
41     int id;
42     Control* (*factory)(Surface&, int index, const char* name, Group&);
43     const char* group_name;
44 };
45
46 /**
47         This is the set of controls that make up a strip.
48 */
49 class Strip : public Group
50 {
51 public:
52         Strip (Surface&, const std::string & name, int index, const std::map<Button::ID,StripButtonInfo>&);
53         ~Strip();
54
55         boost::shared_ptr<ARDOUR::Route> route() const { return _route; }
56
57         void add (Control & control);
58         int index() const { return _index; } // zero based
59
60         void set_route (boost::shared_ptr<ARDOUR::Route>, bool with_messages = true);
61
62         // call all signal handlers manually
63         void notify_all();
64
65         void handle_button (Button&, ButtonState bs);
66         void handle_fader (Fader&, float position);
67         void handle_fader_touch (Fader&, bool touch_on);
68         void handle_pot (Pot&, float delta);
69
70         void periodic (uint64_t now_usecs);
71         void redisplay ();
72
73         MidiByteArray display (uint32_t line_number, const std::string&);
74         MidiByteArray blank_display (uint32_t line_number);
75
76         void zero ();
77
78         void flip_mode_changed (bool notify=false);
79         void potmode_changed (bool notify=false);
80
81         void lock_controls ();
82         void unlock_controls ();
83         bool locked() const { return _controls_locked; }
84
85         void gui_selection_changed (const ARDOUR::StrongRouteNotificationList&);
86
87         void notify_metering_state_changed();
88
89 private:
90         Button*  _solo;
91         Button*  _recenable;
92         Button*  _mute;
93         Button*  _select;
94         Button*  _vselect;
95         Button*  _fader_touch;
96         Pot*     _vpot;
97         Fader*   _fader;
98         Meter*   _meter;
99         int      _index;
100         Surface* _surface;
101         bool     _controls_locked;
102         bool     _transport_is_rolling;
103         bool     _metering_active;
104         uint64_t _reset_display_at;
105         boost::shared_ptr<ARDOUR::Route> _route;
106         PBD::ScopedConnectionList route_connections;
107
108         int      _pan_mode;
109
110         float _last_gain_position_written;
111         float _last_pan_azi_position_written;
112         float _last_pan_width_position_written;
113         float _last_trim_position_written;
114
115         void notify_solo_changed ();
116         void notify_mute_changed ();
117         void notify_record_enable_changed ();
118         void notify_gain_changed (bool force_update = true);
119         void notify_property_changed (const PBD::PropertyChange&);
120         void notify_panner_azi_changed (bool force_update = true);
121         void notify_panner_width_changed (bool force_update = true);
122         void notify_active_changed ();
123         void notify_route_deleted ();
124         void notify_trim_changed (bool force_update = true);
125
126         void update_automation ();
127         void update_meter ();
128
129         std::string vpot_mode_string () const;
130
131         void queue_display_reset (uint32_t msecs);
132         void return_to_vpot_mode_display ();
133
134         struct RedisplayRequest {
135                 ARDOUR::AutomationType type;
136                 float val;
137         };
138
139         RingBuffer<RedisplayRequest> redisplay_requests;
140
141         void do_parameter_display (ARDOUR::AutomationType, float val);
142         void queue_parameter_display (ARDOUR::AutomationType, float val);
143
144         typedef std::map<std::string,boost::shared_ptr<ARDOUR::Bundle> > BundleMap;
145         BundleMap input_bundles;
146         BundleMap output_bundles;
147
148         void build_input_list (const ARDOUR::ChanCount&);
149         void build_output_list (const ARDOUR::ChanCount&);
150         void maybe_add_to_bundle_map (BundleMap& bm, boost::shared_ptr<ARDOUR::Bundle>, bool for_input, const ARDOUR::ChanCount&);
151
152         void select_event (Button&, ButtonState);
153         void vselect_event (Button&, ButtonState);
154         void fader_touch_event (Button&, ButtonState);
155
156         std::vector<Evoral::Parameter> possible_pot_parameters;
157         void next_pot_mode ();
158         void set_vpot_parameter (Evoral::Parameter);
159
160         void reset_saved_values ();
161
162         std::map<Evoral::Parameter,Control*> control_by_parameter;
163 };
164
165 }
166 }
167
168 #endif /* __ardour_mackie_control_protocol_strip_h__ */