change Controllable::set_value() API to include grouped control consideration.
[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 "ardour/automation_control.h"
24
25 #include "controls.h"
26 #include "types.h"
27 #include "surface.h"
28 #include "control_group.h"
29 #include "button.h"
30 #include "led.h"
31 #include "pot.h"
32 #include "fader.h"
33 #include "jog.h"
34 #include "meter.h"
35
36
37 using namespace std;
38 using namespace ArdourSurface;
39 using namespace Mackie;
40
41 using ARDOUR::AutomationControl;
42
43 void Group::add (Control& control)
44 {
45         _controls.push_back (&control);
46 }
47
48 Control::Control (int id, std::string name, Group & group)
49         : _id (id)
50         , _name (name)
51         , _group (group)
52         , _in_use (false)
53 {
54 }
55
56 /** @return true if the control is in use, or false otherwise.
57     Buttons are `in use' when they are held down.
58     Faders with touch support are `in use' when they are being touched.
59     Pots, or faders without touch support, are `in use' from the first move
60     event until a timeout after the last move event.
61 */
62 bool
63 Control::in_use () const
64 {
65         return _in_use;
66 }
67
68 void
69 Control::set_in_use (bool in_use)
70 {
71         _in_use = in_use;
72 }
73
74 void
75 Control::set_control (boost::shared_ptr<AutomationControl> ac)
76 {
77         normal_ac = ac;
78 }
79
80 void
81 Control::set_value (float val)
82 {
83         if (normal_ac) {
84                 normal_ac->set_value (normal_ac->interface_to_internal (val), PBD::Controllable::NoGroup);
85         }
86 }
87
88 float
89 Control::get_value ()
90 {
91         if (!normal_ac) {
92                 return 0.0f;
93         }
94         return normal_ac->internal_to_interface (normal_ac->get_value());
95 }
96
97 void
98 Control::start_touch (double when)
99 {
100         if (normal_ac) {
101                 return normal_ac->start_touch (when);
102         }
103 }
104
105 void
106 Control::stop_touch (bool mark, double when)
107 {
108         if (normal_ac) {
109                 return normal_ac->stop_touch (mark, when);
110         }
111 }
112
113 ostream & operator <<  (ostream & os, const ArdourSurface::Mackie::Control & control)
114 {
115         os << typeid (control).name();
116         os << " { ";
117         os << "name: " << control.name();
118         os << ", ";
119         os << "id: " << "0x" << setw(2) << setfill('0') << hex << control.id() << setfill(' ');
120         os << ", ";
121         os << "group: " << control.group().name();
122         os << " }";
123
124         return os;
125 }
126