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