faderport: factor out encoder divider into a const double
[ardour.git] / libs / surfaces / faderport / operations.cc
1 /*
2     Copyright (C) 2015 Paul Davis
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
20 #include "ardour/async_midi_port.h"
21 #include "ardour/monitor_processor.h"
22 #include "ardour/pannable.h"
23 #include "ardour/rc_configuration.h"
24 #include "ardour/session.h"
25 #include "ardour/track.h"
26 #include "ardour/types.h"
27
28 #include "faderport.h"
29
30 using namespace ARDOUR;
31 using namespace ArdourSurface;
32
33 /* this value is chosen to given smooth motion from 0..1.0 in about 270 degrees
34  * of encoder rotation.
35  */
36 static const double encoder_divisor = 24.0;
37
38 void
39 FaderPort::left ()
40 {
41         access_action ("Editor/select-prev-route");
42
43         //ToDo:  bank by 8?
44         //if ( (button_state & ShiftDown) == ShiftDown )
45
46 }
47
48 void
49 FaderPort::right ()
50 {
51         access_action ("Editor/select-next-route");
52
53         //ToDo:  bank by 8?
54         //if ( (button_state & ShiftDown) == ShiftDown )
55 }
56
57
58 void
59 FaderPort::read ()
60 {
61         if (_current_route) {
62                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
63                 if (gain) {
64                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Play );
65                 }
66         }
67 }
68
69 void
70 FaderPort::write ()
71 {
72         if (_current_route) {
73                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
74                 if (gain) {
75                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Write );
76                 }
77         }
78 }
79
80 void
81 FaderPort::touch ()
82 {
83         if (_current_route) {
84                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
85                 if (gain) {
86                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Touch );
87                 }
88         }
89 }
90
91 void
92 FaderPort::off ()
93 {
94         if (_current_route) {
95                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
96                 if (gain) {
97                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Off );
98                 }
99         }
100 }
101
102
103
104
105 void
106 FaderPort::undo ()
107 {
108         ControlProtocol::Undo (); /* EMIT SIGNAL */
109 }
110
111 void
112 FaderPort::redo ()
113 {
114         ControlProtocol::Redo (); /* EMIT SIGNAL */
115 }
116
117 void
118 FaderPort::mute ()
119 {
120         if (!_current_route) {
121                 return;
122         }
123
124         if (_current_route == session->monitor_out()) {
125                 boost::shared_ptr<MonitorProcessor> mp = _current_route->monitor_control();
126                 mp->set_cut_all (!mp->cut_all());
127                 return;
128         }
129
130         boost::shared_ptr<RouteList> rl (new RouteList);
131         rl->push_back (_current_route);
132         session->set_mute (rl, !_current_route->muted());
133 }
134
135 void
136 FaderPort::solo ()
137 {
138         if (!_current_route) {
139                 return;
140         }
141
142         boost::shared_ptr<RouteList> rl (new RouteList);
143         rl->push_back (_current_route);
144
145         if (Config->get_solo_control_is_listen_control()) {
146                 session->set_listen (rl, !_current_route->listening_via_monitor());
147         } else {
148                 session->set_solo (rl, !_current_route->soloed());
149         }
150 }
151
152 void
153 FaderPort::rec_enable ()
154 {
155         if (!_current_route) {
156                 return;
157         }
158
159         boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_current_route);
160
161         if (!t) {
162                 return;
163         }
164
165         boost::shared_ptr<RouteList> rl (new RouteList);
166         rl->push_back (_current_route);
167
168         session->set_record_enabled (rl, !t->record_enabled());
169 }
170
171 void
172 FaderPort::use_master ()
173 {
174         boost::shared_ptr<Route> r = session->master_out();
175         if (r) {
176                 if (_current_route == r) {
177                         r = pre_master_route.lock();
178                         set_current_route (r);
179                         get_button(Output).set_led_state (_output_port, false);
180                         blinkers.remove (Output);
181                 } else {
182                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
183                                 pre_master_route = boost::weak_ptr<Route> (_current_route);
184                         }
185                         set_current_route (r);
186                         get_button(Output).set_led_state (_output_port, true);
187                         blinkers.remove (Output);
188                 }
189         }
190 }
191
192 void
193 FaderPort::use_monitor ()
194 {
195         boost::shared_ptr<Route> r = session->monitor_out();
196
197         if (r) {
198                 if (_current_route == r) {
199                         r = pre_monitor_route.lock();
200                         set_current_route (r);
201                         get_button(Output).set_led_state (_output_port, false);
202                         blinkers.remove (Output);
203                 } else {
204                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
205                                 pre_monitor_route = boost::weak_ptr<Route> (_current_route);
206                         }
207                         set_current_route (r);
208                         get_button(Output).set_led_state (_output_port, true);
209                         blinkers.push_back (Output);
210                 }
211         } else {
212         }
213 }
214
215 void
216 FaderPort::ardour_pan_azimuth (int delta)
217 {
218         if (!_current_route) {
219                 return;
220         }
221
222         boost::shared_ptr<Pannable> pannable = _current_route->pannable ();
223
224         if (!pannable) {
225                 return;
226         }
227
228         boost::shared_ptr<AutomationControl> azimuth = pannable->pan_azimuth_control;
229
230         if (!azimuth) {
231                 return;
232         }
233
234         azimuth->set_value (azimuth->interface_to_internal (azimuth->internal_to_interface (azimuth->get_value()) + (delta / encoder_divider)));
235 }
236
237
238 void
239 FaderPort::ardour_pan_width(int delta)
240 {
241         if (!_current_route) {
242                 return;
243         }
244
245         boost::shared_ptr<Pannable> pannable = _current_route->pannable ();
246
247         if (!pannable) {
248                 return;
249         }
250
251         boost::shared_ptr<AutomationControl> width = pannable->pan_width_control;
252
253         if (!width) {
254                 return;
255         }
256
257         width->set_value (width->interface_to_internal (width->internal_to_interface (width->get_value()) + (delta / encoder_divider)));
258 }
259
260 void
261 FaderPort::mixbus_pan (int delta)
262 {
263
264 }
265
266 void
267 FaderPort::punch ()
268 {
269         access_action ("Transport/TogglePunch");
270 }