MCP: some debug tracing for meters
[ardour.git] / libs / surfaces / mackie / strip.cc
1 /*
2         Copyright (C) 2006,2007 John Anderson
3         Copyright (C) 2012 Paul Davis
4
5         This program is free software; you can redistribute it and/or modify
6         it under the terms of the GNU General Public License as published by
7         the Free Software Foundation; either version 2 of the License, or
8         (at your option) any later version.
9
10         This program is distributed in the hope that it will be useful,
11         but WITHOUT ANY WARRANTY; without even the implied warranty of
12         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13         GNU General Public License for more details.
14
15         You should have received a copy of the GNU General Public License
16         along with this program; if not, write to the Free Software
17         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <sstream>
21 #include <stdint.h>
22 #include "strip.h"
23
24 #include "button.h"
25 #include "led.h"
26 #include "ledring.h"
27 #include "pot.h"
28 #include "fader.h"
29 #include "jog.h"
30 #include "meter.h"
31
32 using namespace Mackie;
33 using namespace std;
34
35 Strip::Strip (const std::string& name, int index)
36         : Group (name)
37         , _solo (0)
38         , _recenable (0)
39         , _mute (0)
40         , _select (0)
41         , _vselect (0)
42         , _fader_touch (0)
43         , _vpot (0)
44         , _gain (0)
45         , _index (index)
46 {
47         /* master strip only */
48 }
49
50 Strip::Strip (Surface& surface, const std::string& name, int index, int unit_index, StripControlDefinition* ctls)
51         : Group (name)
52         , _solo (0)
53         , _recenable (0)
54         , _mute (0)
55         , _select (0)
56         , _vselect (0)
57         , _fader_touch (0)
58         , _vpot (0)
59         , _gain (0)
60         , _index (index)
61 {
62         /* build the controls for this track, which will automatically add them
63            to the Group 
64         */
65
66         for (uint32_t i = 0; ctls[i].name[0]; ++i) {
67                 ctls[i].factory (surface, ctls[i].base_id + unit_index, unit_index+1, ctls[i].name, *this);
68         }
69 }       
70
71 /**
72         TODO could optimise this to use enum, but it's only
73         called during the protocol class instantiation.
74 */
75 void Strip::add (Control & control)
76 {
77         Group::add (control);
78
79         if  (control.name() == "gain") {
80                 _gain = reinterpret_cast<Fader*>(&control);
81         } else if  (control.name() == "vpot") {
82                 _vpot = reinterpret_cast<Pot*>(&control);
83         } else if  (control.name() == "recenable") {
84                 _recenable = reinterpret_cast<Button*>(&control);
85         } else if  (control.name() == "solo") {
86                 _solo = reinterpret_cast<Button*>(&control);
87         } else if  (control.name() == "mute") {
88                 _mute = reinterpret_cast<Button*>(&control);
89         } else if  (control.name() == "select") {
90                 _select = reinterpret_cast<Button*>(&control);
91         } else if  (control.name() == "vselect") {
92                 _vselect = reinterpret_cast<Button*>(&control);
93         } else if  (control.name() == "fader_touch") {
94                 _fader_touch = reinterpret_cast<Button*>(&control);
95         } else if  (control.name() == "meter") {
96                 _meter = reinterpret_cast<Meter*>(&control);
97         } else if  (control.type() == Control::type_led || control.type() == Control::type_led_ring) {
98                 // relax
99         } else {
100                 ostringstream os;
101                 os << "Strip::add: unknown control type " << control;
102                 throw MackieControlException (os.str());
103         }
104 }
105
106 Fader& 
107 Strip::gain()
108 {
109         if  (_gain == 0) {
110                 throw MackieControlException ("gain is null");
111         }
112         return *_gain;
113 }
114
115 Pot& 
116 Strip::vpot()
117 {
118         if  (_vpot == 0) {
119                 throw MackieControlException ("vpot is null");
120         }
121         return *_vpot;
122 }
123
124 Button& 
125 Strip::recenable()
126 {
127         if  (_recenable == 0) {
128                 throw MackieControlException ("recenable is null");
129         }
130         return *_recenable;
131 }
132
133 Button& 
134 Strip::solo()
135 {
136         if  (_solo == 0) {
137                 throw MackieControlException ("solo is null");
138         }
139         return *_solo;
140 }
141 Button& 
142 Strip::mute()
143 {
144         if  (_mute == 0) {
145                 throw MackieControlException ("mute is null");
146         }
147         return *_mute;
148 }
149
150 Button& 
151 Strip::select()
152 {
153         if  (_select == 0) {
154                 throw MackieControlException ("select is null");
155         }
156         return *_select;
157 }
158
159 Button& 
160 Strip::vselect()
161 {
162         if  (_vselect == 0) {
163                 throw MackieControlException ("vselect is null");
164         }
165         return *_vselect;
166 }
167
168 Button& 
169 Strip::fader_touch()
170 {
171         if  (_fader_touch == 0) {
172                 throw MackieControlException ("fader_touch is null");
173         }
174         return *_fader_touch;
175 }
176
177 Meter& 
178 Strip::meter()
179 {
180         if  (_meter == 0) {
181                 throw MackieControlException ("meter is null");
182         }
183         return *_meter;
184 }
185
186 std::ostream & Mackie::operator <<  (std::ostream & os, const Strip & strip)
187 {
188         os << typeid (strip).name();
189         os << " { ";
190         os << "has_solo: " << boolalpha << strip.has_solo();
191         os << ", ";
192         os << "has_recenable: " << boolalpha << strip.has_recenable();
193         os << ", ";
194         os << "has_mute: " << boolalpha << strip.has_mute();
195         os << ", ";
196         os << "has_select: " << boolalpha << strip.has_select();
197         os << ", ";
198         os << "has_vselect: " << boolalpha << strip.has_vselect();
199         os << ", ";
200         os << "has_fader_touch: " << boolalpha << strip.has_fader_touch();
201         os << ", ";
202         os << "has_vpot: " << boolalpha << strip.has_vpot();
203         os << ", ";
204         os << "has_gain: " << boolalpha << strip.has_gain();
205         os << " }";
206         
207         return os;
208 }