fd9930be0c4d0d3d05357725d8d95bba570b9697
[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/rc_configuration.h"
23 #include "ardour/session.h"
24 #include "ardour/track.h"
25 #include "ardour/types.h"
26
27 #include "faderport.h"
28
29 using namespace ARDOUR;
30 using namespace ArdourSurface;
31
32 void
33 FaderPort::left ()
34 {
35         access_action ("Editor/select-prev-route");
36
37         //ToDo:  bank by 8?
38         //if ( (button_state & ShiftDown) == ShiftDown )
39
40 }
41
42 void
43 FaderPort::right ()
44 {
45         access_action ("Editor/select-next-route");
46
47         //ToDo:  bank by 8?
48         //if ( (button_state & ShiftDown) == ShiftDown )
49 }
50
51
52 void
53 FaderPort::read ()
54 {
55         if (_current_route) {
56                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
57                 if (gain) {
58                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Play );
59                 }
60         }
61 }
62
63 void
64 FaderPort::write ()
65 {
66         if (_current_route) {
67                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
68                 if (gain) {
69                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Write );
70                 }
71         }
72 }
73
74 void
75 FaderPort::touch ()
76 {
77         if (_current_route) {
78                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
79                 if (gain) {
80                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Touch );
81                 }
82         }
83 }
84
85 void
86 FaderPort::off ()
87 {
88         if (_current_route) {
89                 boost::shared_ptr<AutomationControl> gain = _current_route->gain_control ();
90                 if (gain) {
91                         gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Off );
92                 }
93         }
94 }
95
96
97
98
99 void
100 FaderPort::undo ()
101 {
102         ControlProtocol::Undo (); /* EMIT SIGNAL */
103 }
104
105 void
106 FaderPort::redo ()
107 {
108         ControlProtocol::Redo (); /* EMIT SIGNAL */
109 }
110
111 void
112 FaderPort::mute ()
113 {
114         if (!_current_route) {
115                 return;
116         }
117
118         if (_current_route == session->monitor_out()) {
119                 boost::shared_ptr<MonitorProcessor> mp = _current_route->monitor_control();
120                 mp->set_cut_all (!mp->cut_all());
121                 return;
122         }
123
124         boost::shared_ptr<RouteList> rl (new RouteList);
125         rl->push_back (_current_route);
126         session->set_mute (rl, !_current_route->muted());
127 }
128
129 void
130 FaderPort::solo ()
131 {
132         if (!_current_route) {
133                 return;
134         }
135
136         boost::shared_ptr<RouteList> rl (new RouteList);
137         rl->push_back (_current_route);
138
139         if (Config->get_solo_control_is_listen_control()) {
140                 session->set_listen (rl, !_current_route->listening_via_monitor());
141         } else {
142                 session->set_solo (rl, !_current_route->soloed());
143         }
144 }
145
146 void
147 FaderPort::rec_enable ()
148 {
149         if (!_current_route) {
150                 return;
151         }
152
153         boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_current_route);
154
155         if (!t) {
156                 return;
157         }
158
159         boost::shared_ptr<RouteList> rl (new RouteList);
160         rl->push_back (_current_route);
161
162         session->set_record_enabled (rl, !t->record_enabled());
163 }
164
165 void
166 FaderPort::use_master ()
167 {
168         boost::shared_ptr<Route> r = session->master_out();
169         if (r) {
170                 if (_current_route == r) {
171                         r = pre_master_route.lock();
172                         set_current_route (r);
173                         button_info(Output).set_led_state (_output_port, false);
174                         blinkers.remove (Output);
175                 } else {
176                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
177                                 pre_master_route = boost::weak_ptr<Route> (_current_route);
178                         }
179                         set_current_route (r);
180                         button_info(Output).set_led_state (_output_port, true);
181                         blinkers.remove (Output);
182                 }
183         }
184 }
185
186 void
187 FaderPort::use_monitor ()
188 {
189         boost::shared_ptr<Route> r = session->monitor_out();
190
191         if (r) {
192                 if (_current_route == r) {
193                         r = pre_monitor_route.lock();
194                         set_current_route (r);
195                         button_info(Output).set_led_state (_output_port, false);
196                         blinkers.remove (Output);
197                 } else {
198                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
199                                 pre_monitor_route = boost::weak_ptr<Route> (_current_route);
200                         }
201                         set_current_route (r);
202                         button_info(Output).set_led_state (_output_port, true);
203                         blinkers.push_back (Output);
204                 }
205         } else {
206         }
207 }