MCP: maybe handle multiple MCUs better; add support for modifier keys; rearrange...
[ardour.git] / libs / surfaces / mackie / controls.cc
1  /*
2         Copyright (C) 2006,2007 John Anderson
3
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.
8
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.
13
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.
17 */
18
19 #include <iostream>
20 #include <iomanip>
21 #include <sstream>
22
23 #include "controls.h"
24 #include "types.h"
25 #include "mackie_midi_builder.h"
26 #include "surface.h"
27 #include "control_group.h"
28
29 #include "button.h"
30 #include "led.h"
31 #include "ledring.h"
32 #include "pot.h"
33 #include "fader.h"
34 #include "jog.h"
35 #include "meter.h"
36
37
38 using namespace Mackie;
39 using namespace std;
40
41 void Group::add (Control& control)
42 {
43         _controls.push_back (&control);
44 }
45
46 Control::Control (int id, int ordinal, std::string name, Group & group)
47         : _id (id)
48         , _ordinal (ordinal)
49         , _name (name)
50         , _group (group)
51         , _in_use (false)
52 {
53 }
54
55 /** @return true if the control is in use, or false otherwise.
56     Buttons are `in use' when they are held down.
57     Faders with touch support are `in use' when they are being touched.
58     Pots, or faders without touch support, are `in use' from the first move
59     event until a timeout after the last move event.
60 */
61 bool
62 Control::in_use () const
63 {
64         return _in_use;
65 }
66
67 void
68 Control::set_in_use (bool in_use)
69 {
70         _in_use = in_use;
71 }
72
73 ostream & Mackie::operator <<  (ostream & os, const Mackie::Control & control)
74 {
75         os << typeid (control).name();
76         os << " { ";
77         os << "name: " << control.name();
78         os << ", ";
79         os << "id: " << "0x" << setw(4) << setfill('0') << hex << control.id() << setfill(' ');
80         os << ", ";
81         os << "type: " << "0x" << setw(2) << setfill('0') << hex << control.type() << setfill(' ');
82         os << ", ";
83         os << "raw_id: " << "0x" << setw(2) << setfill('0') << hex << control.raw_id() << setfill(' ');
84         os << ", ";
85         os << "ordinal: " << dec << control.ordinal();
86         os << ", ";
87         os << "group: " << control.group().name();
88         os << " }";
89         
90         return os;
91 }
92
93 Control*
94 Pot::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
95 {
96         Pot* p = new Pot (id, ordinal, name, group);
97         surface.pots[id] = p;
98         surface.controls.push_back (p);
99         group.add (*p);
100         return p;
101 }
102
103 Control*
104 Led::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
105 {
106         Led* l = new Led (id, ordinal, name, group);
107         surface.leds[id] = l;
108         surface.controls.push_back (l);
109         group.add (*l);
110         return l;
111 }
112
113 Control*
114 Jog::factory (Surface& surface, int id, int ordinal, const char* name, Group& group)
115 {
116         Jog* j = new Jog (id, ordinal, name, group);
117         surface.controls.push_back (j);
118         surface.controls_by_name["jog"] = j;
119         group.add (*j);
120         return j;
121 }
122