faderport: simpler logic for master/monitor/other
[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
26 #include "faderport.h"
27
28 using namespace ARDOUR;
29 using namespace ArdourSurface;
30
31 void
32 FaderPort::undo ()
33 {
34         ControlProtocol::Undo (); /* EMIT SIGNAL */
35 }
36
37 void
38 FaderPort::redo ()
39 {
40         ControlProtocol::Redo (); /* EMIT SIGNAL */
41 }
42
43 void
44 FaderPort::mute ()
45 {
46         if (!_current_route) {
47                 return;
48         }
49
50         if (_current_route == session->monitor_out()) {
51                 boost::shared_ptr<MonitorProcessor> mp = _current_route->monitor_control();
52                 mp->set_cut_all (!mp->cut_all());
53                 return;
54         }
55
56         boost::shared_ptr<RouteList> rl (new RouteList);
57         rl->push_back (_current_route);
58         session->set_mute (rl, !_current_route->muted());
59 }
60
61 void
62 FaderPort::solo ()
63 {
64         if (!_current_route) {
65                 return;
66         }
67
68         boost::shared_ptr<RouteList> rl (new RouteList);
69         rl->push_back (_current_route);
70
71         if (Config->get_solo_control_is_listen_control()) {
72                 session->set_listen (rl, !_current_route->listening_via_monitor());
73         } else {
74                 session->set_solo (rl, !_current_route->soloed());
75         }
76 }
77
78 void
79 FaderPort::rec_enable ()
80 {
81         if (!_current_route) {
82                 return;
83         }
84
85         boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_current_route);
86
87         if (!t) {
88                 return;
89         }
90
91         boost::shared_ptr<RouteList> rl (new RouteList);
92         rl->push_back (_current_route);
93
94         session->set_record_enabled (rl, !t->record_enabled());
95 }
96
97 void
98 FaderPort::use_master ()
99 {
100         boost::shared_ptr<Route> r = session->master_out();
101         if (r) {
102                 if (_current_route == r) {
103                         r = pre_master_route.lock();
104                         set_current_route (r);
105                         button_info(Output).set_led_state (_output_port, false);
106                         blinkers.remove (Output);
107                 } else {
108                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
109                                 pre_master_route = boost::weak_ptr<Route> (_current_route);
110                         }
111                         set_current_route (r);
112                         button_info(Output).set_led_state (_output_port, true);
113                         blinkers.remove (Output);
114                 }
115         }
116 }
117
118 void
119 FaderPort::use_monitor ()
120 {
121         boost::shared_ptr<Route> r = session->monitor_out();
122
123         if (r) {
124                 if (_current_route == r) {
125                         r = pre_monitor_route.lock();
126                         set_current_route (r);
127                         button_info(Output).set_led_state (_output_port, false);
128                         blinkers.remove (Output);
129                 } else {
130                         if (_current_route != session->master_out() && _current_route != session->monitor_out()) {
131                                 pre_monitor_route = boost::weak_ptr<Route> (_current_route);
132                         }
133                         set_current_route (r);
134                         button_info(Output).set_led_state (_output_port, true);
135                         blinkers.push_back (Output);
136                 }
137         } else {
138         }
139 }