merge with master
[ardour.git] / libs / surfaces / mackie / surface.h
1 #ifndef mackie_surface_h
2 #define mackie_surface_h
3
4 #include <stdint.h>
5
6 #include "pbd/xml++.h"
7 #include "midi++/types.h"
8
9 #include "control_protocol/types.h"
10
11 #include "controls.h"
12 #include "types.h"
13 #include "jog_wheel.h"
14
15 namespace MIDI {
16         class Parser;
17 }
18
19 namespace ARDOUR {
20         class Route;
21 }
22
23 class MidiByteArray;
24 class MackieControlProtocol;
25
26 namespace Mackie
27 {
28
29 class MackieButtonHandler;
30 class SurfacePort;
31 class MackieMidiBuilder;
32 class Button;
33 class Meter;
34 class Fader;
35 class Jog;
36 class Pot;
37 class Led;
38
39 class Surface : public PBD::ScopedConnectionList
40 {
41 public:
42         Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
43         virtual ~Surface();
44
45         surface_type_t type() const { return _stype; }
46         uint32_t number() const { return _number; }
47         const std::string& name() { return _name; }
48
49         void say_hello ();
50
51         bool active() const { return _active; }
52         void drop_routes ();
53
54         typedef std::vector<Control*> Controls;
55         Controls controls;
56
57         std::map<int,Fader*> faders;
58         std::map<int,Pot*> pots;
59         std::map<int,Button*> buttons; // index is device-DEPENDENT
60         std::map<int,Led*> leds;
61         std::map<int,Meter*> meters;
62         std::map<int,Control*> controls_by_device_independent_id;
63         
64         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
65         Fader* master_fader() const { return _master_fader; }
66
67         /// The collection of all numbered strips.
68         typedef std::vector<Strip*> Strips;
69         Strips strips;
70
71         uint32_t n_strips (bool with_locked_strips = true) const;
72         Strip* nth_strip (uint32_t n) const;
73
74         bool route_is_locked_to_strip (boost::shared_ptr<ARDOUR::Route>) const;
75
76         /// This collection owns the groups
77         typedef std::map<std::string,Group*> Groups;
78         Groups groups;
79
80         SurfacePort& port() const { return *_port; }
81
82         void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
83
84         const MidiByteArray& sysex_hdr() const;
85
86         void periodic (uint64_t now_usecs);
87
88         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
89         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
90         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
91
92         /// Connect the any signal from the parser to handle_midi_any
93         /// unless it's already connected
94         void connect_to_signals ();
95
96         /// write a sysex message
97         void write_sysex (const MidiByteArray& mba);
98         void write_sysex (MIDI::byte msg);
99         /// proxy write for port
100         void write (const MidiByteArray&);
101
102         /// display an indicator of the first switched-in Route. Do nothing by default.
103         void display_bank_start (uint32_t /*current_bank*/);
104                 
105         /// called from MackieControlProtocol::zero_all to turn things off
106         void zero_all ();
107         void zero_controls ();
108
109         /// turn off leds around the jog wheel. This is for surfaces that use a pot
110         /// pretending to be a jog wheel.
111         void blank_jog_ring ();
112
113         void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
114
115         /**
116                 This is used to calculate the clicks per second that define
117                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
118                 per second, 50.5 is 5 clicks per second.
119         */
120         float scrub_scaling_factor() const;
121
122         /**
123                 The scaling factor function for speed increase and decrease. At
124                 low transport speeds this should return a small value, for high transport
125                 speeds, this should return an exponentially larger value. This provides
126                 high definition control at low speeds and quick speed changes to/from
127                 higher speeds.
128         */
129         float scaled_delta (float delta, float current_speed);
130
131         // display the first 2 chars of the msg in the 2 char display
132         // . is appended to the previous character, so A.B. would
133         // be two characters
134         void show_two_char_display (const std::string & msg, const std::string & dots = "  ");
135         void show_two_char_display (unsigned int value, const std::string & dots = "  ");
136         
137         void update_view_mode_display ();
138         void update_flip_mode_display ();
139
140         void gui_selection_changed (const ARDOUR::StrongRouteNotificationList&);
141
142         MackieControlProtocol& mcp() const { return _mcp; }
143
144         void next_jog_mode ();
145         void set_jog_mode (Mackie::JogWheel::Mode);
146   
147         void notify_metering_state_changed();
148         void turn_it_on ();
149
150         XMLNode& get_state ();
151         int set_state (const XMLNode&, int version);
152
153   protected:
154         
155   private:
156         MackieControlProtocol& _mcp;
157         SurfacePort*           _port;
158         surface_type_t         _stype;
159         uint32_t               _number;
160         std::string            _name;
161         bool                   _active;
162         bool                   _connected;
163         Mackie::JogWheel*      _jog_wheel;
164         Fader*                 _master_fader;
165         float                  _last_master_gain_written;
166
167         void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
168         MidiByteArray host_connection_query (MidiByteArray& bytes);
169         MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
170
171         void init_controls ();
172         void init_strips (uint32_t n);
173         void setup_master ();
174         void master_gain_changed ();
175 };
176
177 }
178
179 #endif