Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / surfaces / mackie / controls.cc
1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.com>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <iostream>
21 #include <iomanip>
22 #include <sstream>
23
24 #include "ardour/automation_control.h"
25 #include "pbd/enumwriter.h"
26
27 #include "controls.h"
28 #include "types.h"
29 #include "surface.h"
30 #include "control_group.h"
31 #include "button.h"
32 #include "led.h"
33 #include "pot.h"
34 #include "fader.h"
35 #include "jog.h"
36 #include "meter.h"
37
38
39 using namespace std;
40 using namespace ArdourSurface;
41 using namespace Mackie;
42
43 using ARDOUR::AutomationControl;
44
45 void Group::add (Control& control)
46 {
47         _controls.push_back (&control);
48 }
49
50 Control::Control (int id, std::string name, Group & group)
51         : _id (id)
52         , _name (name)
53         , _group (group)
54         , _in_use (false)
55 {
56 }
57
58 /** @return true if the control is in use, or false otherwise.
59     Buttons are `in use' when they are held down.
60     Faders with touch support are `in use' when they are being touched.
61     Pots, or faders without touch support, are `in use' from the first move
62     event until a timeout after the last move event.
63 */
64 bool
65 Control::in_use () const
66 {
67         return _in_use;
68 }
69
70 void
71 Control::set_in_use (bool in_use)
72 {
73         _in_use = in_use;
74 }
75
76 void
77 Control::set_control (boost::shared_ptr<AutomationControl> ac)
78 {
79         normal_ac = ac;
80 }
81
82 void
83 Control::set_value (float val, PBD::Controllable::GroupControlDisposition group_override)
84 {
85         if (normal_ac) {
86                 normal_ac->set_value (normal_ac->interface_to_internal (val), group_override);
87         }
88 }
89
90 float
91 Control::get_value ()
92 {
93         if (!normal_ac) {
94                 return 0.0f;
95         }
96         return normal_ac->internal_to_interface (normal_ac->get_value());
97 }
98
99 void
100 Control::start_touch (double when)
101 {
102         if (normal_ac) {
103                 return normal_ac->start_touch (when);
104         }
105 }
106
107 void
108 Control::stop_touch (double when)
109 {
110         if (normal_ac) {
111                 return normal_ac->stop_touch (when);
112         }
113 }
114
115 ostream & operator <<  (ostream & os, const ArdourSurface::Mackie::Control & control)
116 {
117         os << typeid (control).name();
118         os << " { ";
119         os << "name: " << control.name();
120         os << ", ";
121         os << "id: " << "0x" << setw(2) << setfill('0') << hex << control.id() << setfill(' ');
122         os << ", ";
123         os << "group: " << control.group().name();
124         os << " }";
125
126         return os;
127 }
128