debug ardour->MCP fader mapping
[ardour.git] / libs / surfaces / mackie / surface.h
1 #ifndef mackie_surface_h
2 #define mackie_surface_h
3
4 #include "controls.h"
5 #include "types.h"
6 #include <stdint.h>
7
8 namespace Mackie
9 {
10
11 class MackieButtonHandler;
12 class SurfacePort;
13 class MackieMidiBuilder;
14
15 /**
16         This represents an entire control surface, made up of Groups,
17         Strips and Controls. There are several collections for
18         ease of addressing in different ways, but only one collection
19         has definitive ownership.
20
21         It handles mapping button ids to press_ and release_ calls.
22
23         There are various emulations of the Mackie around, so specific
24         emulations will inherit from this to change button mapping, or 
25         have 7 fader channels instead of 8, or whatever.
26
27         Currently there are BcfSurface and MackieSurface.
28
29         TODO maybe make Group inherit from Control, for ease of ownership.
30 */
31 class Surface
32 {
33 public:
34         /**
35                 A Surface can be made up of multiple units. eg one Mackie MCU plus
36                 one or more Mackie MCU extenders.
37                 
38                 \param max_strips is the number of strips for the entire surface.
39                 \param unit_strips is the number of strips per unit.
40         */
41
42         Surface (uint32_t max_strips, uint32_t unit_strips);
43         virtual ~Surface();
44
45         /// Calls the virtual initialisation methods. This *must* be called after
46         /// construction, because c++ is too dumb to call virtual methods from
47         /// inside a constructor
48         void init();
49
50         typedef std::vector<Control*> Controls;
51         
52         /// This collection has ownership of all the controls
53         Controls controls;
54
55         /**
56                 These are alternative addressing schemes
57                 They use maps because the indices aren't always
58                 0-based.
59                 
60                 Indexed by raw_id not by id. @see Control for the distinction.
61         */
62         std::map<int,Fader*> faders;
63         std::map<int,Pot*> pots;
64         std::map<int,Button*> buttons;
65         std::map<int,Led*> leds;
66
67         /// no strip controls in here because they usually
68         /// have the same names.
69         std::map<std::string,Control*> controls_by_name;
70
71         /// The collection of all numbered strips. No master
72         /// strip in here.
73         typedef std::vector<Strip*> Strips;
74         Strips strips;
75
76         /// This collection owns the groups
77         typedef std::map<std::string,Group*> Groups;
78         Groups groups;
79
80         uint32_t max_strips() const { return _max_strips; }
81         
82         /// map button ids to calls to press_ and release_ in mbh
83         virtual void handle_button( MackieButtonHandler & mbh, ButtonState bs, Button & button ) = 0;
84
85 public:
86         /// display an indicator of the first switched-in Route. Do nothing by default.
87         virtual void display_bank_start( SurfacePort &, MackieMidiBuilder &, uint32_t /*current_bank*/ ) {};
88                 
89         /// called from MackieControlPRotocol::zero_all to turn things off
90         virtual void zero_all( SurfacePort &, MackieMidiBuilder & ) {};
91
92         /// turn off leds around the jog wheel. This is for surfaces that use a pot
93         /// pretending to be a jog wheel.
94         virtual void blank_jog_ring( SurfacePort &, MackieMidiBuilder & ) {};
95
96         virtual bool has_timecode_display() const = 0;
97         virtual void display_timecode( SurfacePort &, MackieMidiBuilder &, const std::string & /*timecode*/, const std::string & /*timecode_last*/) {};
98         
99 public:
100         /**
101                 This is used to calculate the clicks per second that define
102                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
103                 per second, 50.5 is 5 clicks per second.
104         */
105         virtual float scrub_scaling_factor() = 0;
106
107         /**
108                 The scaling factor function for speed increase and decrease. At
109                 low transport speeds this should return a small value, for high transport
110                 speeds, this should return an exponentially larger value. This provides
111                 high definition control at low speeds and quick speed changes to/from
112                 higher speeds.
113         */
114         virtual float scaled_delta( const ControlState & state, float current_speed ) = 0;
115
116 protected:
117         virtual void init_controls() = 0;
118         virtual void init_strips () {}
119
120         const uint32_t _max_strips;
121         const uint32_t _unit_strips;
122 };
123
124 }
125
126 #endif