Merge branch 'master' into windows
[ardour.git] / gtk2_ardour / mixer_actor.cc
1 /*
2     Copyright (C) 2000-2004 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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include <boost/foreach.hpp>
25
26 #include "pbd/file_utils.h"
27 #include "pbd/error.h"
28
29 #include "ardour/filesystem_paths.h"
30
31 #include "actions.h"
32 #include "mixer_actor.h"
33 #include "mixer_strip.h"
34 #include "route_ui.h"
35
36 #include "i18n.h"
37
38 #ifdef SearchPath
39 #undef SearchPath
40 #endif
41
42 using namespace ARDOUR;
43 using namespace Gtk;
44 using namespace PBD;
45
46 MixerActor::MixerActor ()
47 {
48         register_actions ();
49         load_bindings ();
50 }
51
52 MixerActor::~MixerActor ()
53 {
54 }
55
56 void
57 MixerActor::register_actions ()
58 {
59         myactions.register_action ("Mixer", "solo", _("Toggle Solo on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::solo_action));
60         myactions.register_action ("Mixer", "mute", _("Toggle Mute on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::mute_action));
61         myactions.register_action ("Mixer", "recenable", _("Toggle Rec-enable on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::rec_enable_action));
62         myactions.register_action ("Mixer", "increment-gain", _("Decrease Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::step_gain_up_action));
63         myactions.register_action ("Mixer", "decrement-gain", _("Increase Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::step_gain_down_action));
64         myactions.register_action ("Mixer", "unity-gain", _("Set Gain to 0dB on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::unity_gain_action));
65
66
67         myactions.register_action ("Mixer", "copy-processors", _("Copy Selected Processors"), sigc::mem_fun (*this, &MixerActor::copy_processors));
68         myactions.register_action ("Mixer", "cut-processors", _("Cut Selected Processors"), sigc::mem_fun (*this, &MixerActor::cut_processors));
69         myactions.register_action ("Mixer", "paste-processors", _("Paste Selected Processors"), sigc::mem_fun (*this, &MixerActor::paste_processors));
70         myactions.register_action ("Mixer", "delete-processors", _("Delete Selected Processors"), sigc::mem_fun (*this, &MixerActor::delete_processors));
71         myactions.register_action ("Mixer", "select-all-processors", _("Select All (visible) Processors"), sigc::mem_fun (*this, &MixerActor::select_all_processors));
72         myactions.register_action ("Mixer", "toggle-processors", _("Toggle Selected Processors"), sigc::mem_fun (*this, &MixerActor::toggle_processors));
73         myactions.register_action ("Mixer", "ab-plugins", _("Toggle Selected Plugins"), sigc::mem_fun (*this, &MixerActor::ab_plugins));
74
75
76         myactions.register_action ("Mixer", "scroll-left", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &MixerActor::scroll_left));
77         myactions.register_action ("Mixer", "scroll-right", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &MixerActor::scroll_right));
78
79         myactions.register_action ("Mixer", "toggle-midi-input-active", _("Toggle MIDI Input Active for Mixer-Selected Tracks/Busses"), 
80                                    sigc::bind (sigc::mem_fun (*this, &MixerActor::toggle_midi_input_active), false));
81 }
82
83 void
84 MixerActor::load_bindings ()
85 {
86         /* XXX move this to a better place */
87         
88         bindings.set_action_map (myactions);
89
90         std::string binding_file;
91
92         if (find_file_in_search_path (ardour_config_search_path(), "mixer.bindings", binding_file)) {
93                 bindings.load (binding_file);
94                 info << string_compose (_("Loaded mixer bindings from %1"), binding_file) << endmsg;
95         } else {
96                 error << string_compose (_("Could not find mixer.bindings in search path %1"), ardour_config_search_path().to_string()) << endmsg;
97         }
98 }
99
100 void
101 MixerActor::solo_action ()
102 {
103         GdkEventButton ev;
104
105         ev.type = GDK_BUTTON_PRESS;
106         ev.button = 1;
107         ev.state = 0;
108
109         set_route_targets_for_operation ();
110
111         BOOST_FOREACH(RouteUI* r, _route_targets) {
112                 r->solo_press (&ev);
113         }
114 }
115
116 void
117 MixerActor::mute_action ()
118 {
119         GdkEventButton ev;
120
121         ev.type = GDK_BUTTON_PRESS;
122         ev.button = 1;
123         ev.state = 0;
124
125         set_route_targets_for_operation ();
126
127         BOOST_FOREACH(RouteUI* r, _route_targets) {
128                 r->mute_press (&ev);
129         }
130 }
131
132 void
133 MixerActor::rec_enable_action ()
134 {
135         GdkEventButton ev;
136
137         ev.type = GDK_BUTTON_PRESS;
138         ev.button = 1;
139         ev.state = 0;
140
141         set_route_targets_for_operation ();
142
143         BOOST_FOREACH(RouteUI* r, _route_targets) {
144                 r->rec_enable_press (&ev);
145         }
146 }
147
148 void
149 MixerActor::step_gain_up_action ()
150 {
151         set_route_targets_for_operation ();
152
153         BOOST_FOREACH(RouteUI* r, _route_targets) {
154                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
155                 if (ms) {
156                         ms->step_gain_up ();
157                 }
158         }
159 }
160
161 void
162 MixerActor::step_gain_down_action ()
163 {
164         set_route_targets_for_operation ();
165
166         BOOST_FOREACH(RouteUI* r, _route_targets) {
167                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
168                 if (ms) {
169                         ms->step_gain_down ();
170                 }
171         }
172 }
173
174 void
175 MixerActor::unity_gain_action ()
176 {
177         set_route_targets_for_operation ();
178
179         BOOST_FOREACH(RouteUI* r, _route_targets) {
180                 boost::shared_ptr<Route> rp = r->route();
181                 if (rp) {
182                         rp->set_gain (1.0, this);
183                 }
184         }
185 }
186
187 void
188 MixerActor::copy_processors ()
189 {
190         set_route_targets_for_operation ();
191
192         BOOST_FOREACH(RouteUI* r, _route_targets) {
193                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
194                 if (ms) {
195                         ms->copy_processors ();
196                 }
197         }
198 }
199 void
200 MixerActor::cut_processors ()
201 {
202         set_route_targets_for_operation ();
203
204         BOOST_FOREACH(RouteUI* r, _route_targets) {
205                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
206                 if (ms) {
207                         ms->cut_processors ();
208                 }
209         }
210 }
211 void
212 MixerActor::paste_processors ()
213 {
214         set_route_targets_for_operation ();
215
216         BOOST_FOREACH(RouteUI* r, _route_targets) {
217                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
218                 if (ms) {
219                         ms->paste_processors ();
220                 }
221         }
222 }
223 void
224 MixerActor::select_all_processors ()
225 {
226         set_route_targets_for_operation ();
227
228         BOOST_FOREACH(RouteUI* r, _route_targets) {
229                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
230                 if (ms) {
231                         ms->select_all_processors ();
232                 }
233         }
234 }
235 void
236 MixerActor::delete_processors ()
237 {
238         set_route_targets_for_operation ();
239
240         BOOST_FOREACH(RouteUI* r, _route_targets) {
241                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
242                 if (ms) {
243                         ms->delete_processors ();
244                 }
245         }
246 }
247 void
248 MixerActor::toggle_processors ()
249 {
250         set_route_targets_for_operation ();
251
252         BOOST_FOREACH(RouteUI* r, _route_targets) {
253                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
254                 if (ms) {
255                         ms->toggle_processors ();
256                 }
257         }
258 }
259 void
260 MixerActor::ab_plugins ()
261 {
262         set_route_targets_for_operation ();
263
264         BOOST_FOREACH(RouteUI* r, _route_targets) {
265                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
266                 if (ms) {
267                         ms->ab_plugins ();
268                 }
269         }
270 }
271