drastic, fundamental redesign of MCP code
[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_midi_builder.h"
11 #include "mackie_jog_wheel.h"
12
13 namespace MIDI {
14         class Parser;
15 }
16
17 class MidiByteArray;
18 class MackieControlProtocol;
19
20 namespace Mackie
21 {
22
23 class MackieButtonHandler;
24 class SurfacePort;
25 class MackieMidiBuilder;
26 class Button;
27 class Meter;
28 class Fader;
29 class Jog;
30 class Pot;
31 class Led;
32 class LedRing;
33
34 class Surface : public PBD::ScopedConnectionList
35 {
36 public:
37         Surface (MackieControlProtocol&, jack_client_t* jack, const std::string& device_name, uint32_t number, surface_type_t stype);
38         virtual ~Surface();
39
40         surface_type_t type() const { return _stype; }
41         uint32_t number() const { return _number; }
42
43         MackieControlProtocol& mcp() const { return _mcp; }
44
45         bool active() const { return _active; }
46         void drop_routes ();
47
48         typedef std::vector<Control*> Controls;
49         Controls controls;
50
51         std::map<int,Fader*> faders;
52         std::map<int,Pot*> pots;
53         std::map<int,Button*> buttons;
54         std::map<int,Led*> leds;
55         std::map<int,Meter*> meters;
56
57         /// no strip controls in here because they usually
58         /// have the same names.
59         std::map<std::string,Control*> controls_by_name;
60         
61         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
62
63         /// The collection of all numbered strips. No master
64         /// strip in here.
65         typedef std::vector<Strip*> Strips;
66         Strips strips;
67
68         uint32_t n_strips () const;
69         Strip* nth_strip (uint32_t n) const;
70
71         /// This collection owns the groups
72         typedef std::map<std::string,Group*> Groups;
73         Groups groups;
74
75         SurfacePort& port() const { return *_port; }
76
77         const MidiByteArray& sysex_hdr() const;
78
79         void periodic ();
80
81         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
82         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
83         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
84
85         /// Connect the any signal from the parser to handle_midi_any
86         /// unless it's already connected
87         void connect_to_signals ();
88
89         /// notification from a MackiePort that it's now inactive
90         void handle_port_inactive(Mackie::SurfacePort *);
91
92         /// write a sysex message
93         void write_sysex (const MidiByteArray& mba);
94         void write_sysex (MIDI::byte msg);
95         /// proxy write for port
96         void write (const MidiByteArray&);
97
98         /// display an indicator of the first switched-in Route. Do nothing by default.
99         void display_bank_start (uint32_t /*current_bank*/);
100                 
101         /// called from MackieControlProtocol::zero_all to turn things off
102         void zero_all ();
103
104         /// turn off leds around the jog wheel. This is for surfaces that use a pot
105         /// pretending to be a jog wheel.
106         void blank_jog_ring ();
107
108         bool has_timecode_display() const;
109         void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
110
111         /**
112                 This is used to calculate the clicks per second that define
113                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
114                 per second, 50.5 is 5 clicks per second.
115         */
116         float scrub_scaling_factor() const;
117
118         /**
119                 The scaling factor function for speed increase and decrease. At
120                 low transport speeds this should return a small value, for high transport
121                 speeds, this should return an exponentially larger value. This provides
122                 high definition control at low speeds and quick speed changes to/from
123                 higher speeds.
124         */
125         float scaled_delta (const ControlState & state, float current_speed);
126
127         void handle_control_event (Mackie::Control & control, const Mackie::ControlState & state);
128
129   protected:
130         void init_controls();
131         void init_strips ();
132
133   private:
134         MackieControlProtocol& _mcp;
135         SurfacePort* _port;
136         surface_type_t _stype;
137         uint32_t _number;
138         bool _active;
139         bool _connected;
140         Mackie::JogWheel* _jog_wheel;
141         MackieMidiBuilder builder;
142
143         void jog_wheel_state_display (Mackie::JogWheel::State state);
144 };
145
146 }
147
148 #endif