2 Copyright (C) 2006,2007 John Anderson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "mackie_midi_builder.h"
28 using namespace Mackie;
31 void Group::add (Control& control)
33 _controls.push_back (&control);
36 Strip::Strip (const std::string& name, int index)
48 /* master strip only */
51 Strip::Strip (Surface& surface, const std::string& name, int index, int unit_index, StripControlDefinition* ctls)
63 /* build the controls for this track, which will automatically add them
67 for (uint32_t i = 0; ctls[i].name[0]; ++i) {
68 ctls[i].factory (surface, ctls[i].base_id + unit_index, unit_index+1, ctls[i].name, *this);
73 TODO could optimise this to use enum, but it's only
74 called during the protocol class instantiation.
76 void Strip::add (Control & control)
80 if (control.name() == "gain") {
81 _gain = reinterpret_cast<Fader*>(&control);
82 } else if (control.name() == "vpot") {
83 _vpot = reinterpret_cast<Pot*>(&control);
84 } else if (control.name() == "recenable") {
85 _recenable = reinterpret_cast<Button*>(&control);
86 } else if (control.name() == "solo") {
87 _solo = reinterpret_cast<Button*>(&control);
88 } else if (control.name() == "mute") {
89 _mute = reinterpret_cast<Button*>(&control);
90 } else if (control.name() == "select") {
91 _select = reinterpret_cast<Button*>(&control);
92 } else if (control.name() == "vselect") {
93 _vselect = reinterpret_cast<Button*>(&control);
94 } else if (control.name() == "fader_touch") {
95 _fader_touch = reinterpret_cast<Button*>(&control);
96 } else if (control.type() == Control::type_led || control.type() == Control::type_led_ring) {
100 os << "Strip::add: unknown control type " << control;
101 throw MackieControlException (os.str());
105 Control::Control (int id, int ordinal, std::string name, Group & group)
118 throw MackieControlException ("gain is null");
127 throw MackieControlException ("vpot is null");
135 if (_recenable == 0) {
136 throw MackieControlException ("recenable is null");
145 throw MackieControlException ("solo is null");
153 throw MackieControlException ("mute is null");
162 throw MackieControlException ("select is null");
171 throw MackieControlException ("vselect is null");
179 if (_fader_touch == 0) {
180 throw MackieControlException ("fader_touch is null");
182 return *_fader_touch;
185 /** @return true if the control is in use, or false otherwise.
186 Buttons are `in use' when they are held down.
187 Faders with touch support are `in use' when they are being touched.
188 Pots, or faders without touch support, are `in use' from the first move
189 event until a timeout after the last move event.
192 Control::in_use () const
198 Control::set_in_use (bool in_use)
203 ostream & Mackie::operator << (ostream & os, const Mackie::Control & control)
205 os << typeid (control).name();
207 os << "name: " << control.name();
209 os << "id: " << "0x" << setw(4) << setfill('0') << hex << control.id() << setfill(' ');
211 os << "type: " << "0x" << setw(2) << setfill('0') << hex << control.type() << setfill(' ');
213 os << "raw_id: " << "0x" << setw(2) << setfill('0') << hex << control.raw_id() << setfill(' ');
215 os << "ordinal: " << dec << control.ordinal();
217 os << "group: " << control.group().name();
223 std::ostream & Mackie::operator << (std::ostream & os, const Strip & strip)
225 os << typeid (strip).name();
227 os << "has_solo: " << boolalpha << strip.has_solo();
229 os << "has_recenable: " << boolalpha << strip.has_recenable();
231 os << "has_mute: " << boolalpha << strip.has_mute();
233 os << "has_select: " << boolalpha << strip.has_select();
235 os << "has_vselect: " << boolalpha << strip.has_vselect();
237 os << "has_fader_touch: " << boolalpha << strip.has_fader_touch();
239 os << "has_vpot: " << boolalpha << strip.has_vpot();
241 os << "has_gain: " << boolalpha << strip.has_gain();
248 Button::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
250 Button* b = new Button (id, ordinal, name, group);
251 surface.buttons[id] = b;
252 surface.controls.push_back (b);
258 Fader::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
260 Fader* f = new Fader (id, ordinal, name, group);
261 surface.faders[id] = f;
262 surface.controls.push_back (f);
268 Pot::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
270 Pot* p = new Pot (id, ordinal, name, group);
271 surface.pots[id] = p;
272 surface.controls.push_back (p);
278 Led::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
280 Led* l = new Led (id, ordinal, name, group);
281 surface.leds[id] = l;
282 surface.controls.push_back (l);
288 Jog::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
290 Jog* j = new Jog (id, ordinal, name, group);
291 surface.controls.push_back (j);
292 surface.controls_by_name["jog"] = j;