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