5305fe7eb8a7712d81fc4ed1fb965c8dfcfa8d31
[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         Surface( uint32_t max_strips, uint32_t unit_strips = 8 );
42         virtual ~Surface();
43
44         /// Calls the virtual initialisation methods. This *must* be called after
45         /// construction, because c++ is too dumb to call virtual methods from
46         /// inside a constructor
47         void init();
48
49         typedef std::vector<Control*> Controls;
50         
51         /// This collection has ownership of all the controls
52         Controls controls;
53
54         /**
55                 These are alternative addressing schemes
56                 They use maps because the indices aren't always
57                 0-based.
58                 
59                 Indexed by raw_id not by id. @see Control for the distinction.
60         */
61         std::map<int,Fader*> faders;
62         std::map<int,Pot*> pots;
63         std::map<int,Button*> buttons;
64         std::map<int,Led*> leds;
65
66         /// no strip controls in here because they usually
67         /// have the same names.
68         std::map<std::string,Control*> controls_by_name;
69
70         /// The collection of all numbered strips. No master
71         /// strip in here.
72         typedef std::vector<Strip*> Strips;
73         Strips strips;
74
75         /// This collection owns the groups
76         typedef std::map<std::string,Group*> Groups;
77         Groups groups;
78
79         uint32_t max_strips() const
80         {
81                 return _max_strips;
82         }
83         
84         /// map button ids to calls to press_ and release_ in mbh
85         virtual void handle_button( MackieButtonHandler & mbh, ButtonState bs, Button & button ) = 0;
86
87 public:
88         /// display an indicator of the first switched-in Route. Do nothing by default.
89         virtual void display_bank_start( SurfacePort &, MackieMidiBuilder &, uint32_t current_bank ) {};
90                 
91         /// called from MackieControlPRotocol::zero_all to turn things off
92         virtual void zero_all( SurfacePort &, MackieMidiBuilder & ) {};
93
94         /// turn off leds around the jog wheel. This is for surfaces that use a pot
95         /// pretending to be a jog wheel.
96         virtual void blank_jog_ring( SurfacePort &, MackieMidiBuilder & ) {};
97
98         virtual bool has_timecode_display() const = 0;
99         virtual void display_timecode( SurfacePort &, MackieMidiBuilder &, const std::string & timecode, const std::string & timecode_last ) {};
100         
101 public:
102         /**
103                 This is used to calculate the clicks per second that define
104                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
105                 per second, 50.5 is 5 clicks per second.
106         */
107         virtual float scrub_scaling_factor() = 0;
108
109         /**
110                 The scaling factor function for speed increase and decrease. At
111                 low transport speeds this should return a small value, for high transport
112                 speeds, this should return an exponentially larger value. This provides
113                 high definition control at low speeds and quick speed changes to/from
114                 higher speeds.
115         */
116         virtual float scaled_delta( const ControlState & state, float current_speed ) = 0;
117
118 protected:
119         virtual void init_controls() = 0;
120         virtual void init_strips( uint32_t max_strips, uint32_t unit_strips );
121
122 private:
123         uint32_t _max_strips;
124         uint32_t _unit_strips;
125 };
126
127 }
128
129 #endif