MCP: more view mode stuff
[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 "midi++/types.h"
7
8 #include "controls.h"
9 #include "types.h"
10 #include "mackie_jog_wheel.h"
11
12 namespace MIDI {
13         class Parser;
14 }
15
16 namespace ARDOUR {
17         class Route;
18 }
19
20 class MidiByteArray;
21 class MackieControlProtocol;
22
23 namespace Mackie
24 {
25
26 class MackieButtonHandler;
27 class SurfacePort;
28 class MackieMidiBuilder;
29 class Button;
30 class Meter;
31 class Fader;
32 class Jog;
33 class Pot;
34 class Led;
35
36 class Surface : public PBD::ScopedConnectionList
37 {
38 public:
39         Surface (MackieControlProtocol&, jack_client_t* jack, const std::string& device_name, uint32_t number, surface_type_t stype);
40         virtual ~Surface();
41
42         surface_type_t type() const { return _stype; }
43         uint32_t number() const { return _number; }
44
45         MackieControlProtocol& mcp() const { return _mcp; }
46
47         bool active() const { return _active; }
48         void drop_routes ();
49
50         typedef std::vector<Control*> Controls;
51         Controls controls;
52
53         std::map<int,Fader*> faders;
54         std::map<int,Pot*> pots;
55         std::map<int,Button*> buttons;
56         std::map<int,Led*> leds;
57         std::map<int,Meter*> meters;
58
59         /// no strip controls in here because they usually
60         /// have the same names.
61         std::map<std::string,Control*> controls_by_name;
62         
63         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
64
65         /// The collection of all numbered strips. No master
66         /// strip in here.
67         typedef std::vector<Strip*> Strips;
68         Strips strips;
69
70         uint32_t n_strips () const;
71         Strip* nth_strip (uint32_t n) const;
72
73         /// This collection owns the groups
74         typedef std::map<std::string,Group*> Groups;
75         Groups groups;
76
77         SurfacePort& port() const { return *_port; }
78
79         void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
80
81         const MidiByteArray& sysex_hdr() const;
82
83         void periodic ();
84
85         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
86         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
87         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
88
89         /// Connect the any signal from the parser to handle_midi_any
90         /// unless it's already connected
91         void connect_to_signals ();
92
93         /// notification from a MackiePort that it's now inactive
94         void handle_port_inactive(Mackie::SurfacePort *);
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
108         /// turn off leds around the jog wheel. This is for surfaces that use a pot
109         /// pretending to be a jog wheel.
110         void blank_jog_ring ();
111
112         bool has_timecode_display() const;
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         MidiByteArray two_char_display (const std::string & msg, const std::string & dots = "  ");
135         MidiByteArray two_char_display (unsigned int value, const std::string & dots = "  ");
136         
137         /**
138                 Timecode display. Only the difference between timecode and last_timecode will
139                 be encoded, to save midi bandwidth. If they're the same, an empty array will
140                 be returned
141         */
142         MidiByteArray timecode_display (const std::string & timecode, const std::string & last_timecode = "");
143
144         void update_view_mode_display ();
145
146   protected:
147         void init_controls();
148         void init_strips ();
149
150   private:
151         MackieControlProtocol& _mcp;
152         SurfacePort* _port;
153         surface_type_t _stype;
154         uint32_t _number;
155         bool _active;
156         bool _connected;
157         Mackie::JogWheel* _jog_wheel;
158
159         void jog_wheel_state_display (Mackie::JogWheel::State state);
160 };
161
162 }
163
164 #endif