radically change Keyboard/Binding API design to disconnect Gtk::Action lookup from...
[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 "gtkmm2ext/bindings.h"
32
33 #include "actions.h"
34 #include "mixer_actor.h"
35 #include "mixer_strip.h"
36 #include "route_ui.h"
37
38 #include "i18n.h"
39
40 using namespace ARDOUR;
41 using namespace Gtk;
42 using namespace PBD;
43 using Gtkmm2ext::Actions;
44 using Gtkmm2ext::Bindings;
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         Glib::RefPtr<ActionGroup> group = Actions.create_action_group (X_("Mixer"));
60
61         Actions.register_action (group, "solo", _("Toggle Solo on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::solo_action));
62         Actions.register_action (group, "mute", _("Toggle Mute on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::mute_action));
63         Actions.register_action (group, "recenable", _("Toggle Rec-enable on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::rec_enable_action));
64         Actions.register_action (group, "increment-gain", _("Decrease Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::step_gain_up_action));
65         Actions.register_action (group, "decrement-gain", _("Increase Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::step_gain_down_action));
66         Actions.register_action (group, "unity-gain", _("Set Gain to 0dB on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &MixerActor::unity_gain_action));
67
68
69         Actions.register_action (group, "copy-processors", _("Copy Selected Processors"), sigc::mem_fun (*this, &MixerActor::copy_processors));
70         Actions.register_action (group, "cut-processors", _("Cut Selected Processors"), sigc::mem_fun (*this, &MixerActor::cut_processors));
71         Actions.register_action (group, "paste-processors", _("Paste Selected Processors"), sigc::mem_fun (*this, &MixerActor::paste_processors));
72         Actions.register_action (group, "delete-processors", _("Delete Selected Processors"), sigc::mem_fun (*this, &MixerActor::delete_processors));
73         Actions.register_action (group, "select-all-processors", _("Select All (visible) Processors"), sigc::mem_fun (*this, &MixerActor::select_all_processors));
74         Actions.register_action (group, "toggle-processors", _("Toggle Selected Processors"), sigc::mem_fun (*this, &MixerActor::toggle_processors));
75         Actions.register_action (group, "ab-plugins", _("Toggle Selected Plugins"), sigc::mem_fun (*this, &MixerActor::ab_plugins));
76         Actions.register_action (group, "select-none", _("Deselect all strips and processors"), sigc::mem_fun (*this, &MixerActor::select_none));
77
78         Actions.register_action (group, "scroll-left", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &MixerActor::scroll_left));
79         Actions.register_action (group, "scroll-right", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &MixerActor::scroll_right));
80
81         Actions.register_action (group, "toggle-midi-input-active", _("Toggle MIDI Input Active for Mixer-Selected Tracks/Busses"), 
82                                    sigc::bind (sigc::mem_fun (*this, &MixerActor::toggle_midi_input_active), false));
83 }
84
85 void
86 MixerActor::load_bindings ()
87 {
88         bindings = Bindings::get_bindings (X_("mixer"));
89 }
90
91 void
92 MixerActor::solo_action ()
93 {
94         GdkEventButton ev;
95
96         ev.type = GDK_BUTTON_PRESS;
97         ev.button = 1;
98         ev.state = 0;
99
100         set_route_targets_for_operation ();
101
102         BOOST_FOREACH(RouteUI* r, _route_targets) {
103                 r->solo_press (&ev);
104         }
105 }
106
107 void
108 MixerActor::mute_action ()
109 {
110         GdkEventButton ev;
111
112         ev.type = GDK_BUTTON_PRESS;
113         ev.button = 1;
114         ev.state = 0;
115
116         set_route_targets_for_operation ();
117
118         BOOST_FOREACH(RouteUI* r, _route_targets) {
119                 r->mute_press (&ev);
120         }
121 }
122
123 void
124 MixerActor::rec_enable_action ()
125 {
126         GdkEventButton ev;
127
128         ev.type = GDK_BUTTON_PRESS;
129         ev.button = 1;
130         ev.state = 0;
131
132         set_route_targets_for_operation ();
133
134         BOOST_FOREACH(RouteUI* r, _route_targets) {
135                 r->rec_enable_press (&ev);
136         }
137 }
138
139 void
140 MixerActor::step_gain_up_action ()
141 {
142         set_route_targets_for_operation ();
143
144         BOOST_FOREACH(RouteUI* r, _route_targets) {
145                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
146                 if (ms) {
147                         ms->step_gain_up ();
148                 }
149         }
150 }
151
152 void
153 MixerActor::step_gain_down_action ()
154 {
155         set_route_targets_for_operation ();
156
157         BOOST_FOREACH(RouteUI* r, _route_targets) {
158                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
159                 if (ms) {
160                         ms->step_gain_down ();
161                 }
162         }
163 }
164
165 void
166 MixerActor::unity_gain_action ()
167 {
168         set_route_targets_for_operation ();
169
170 printf("setting gain to unity (?)");
171         BOOST_FOREACH(RouteUI* r, _route_targets) {
172                 boost::shared_ptr<Route> rp = r->route();
173                 if (rp) {
174                         rp->set_gain (1.0, Controllable::NoGroup);
175                 }
176         }
177 }
178
179 void
180 MixerActor::copy_processors ()
181 {
182         set_route_targets_for_operation ();
183
184         BOOST_FOREACH(RouteUI* r, _route_targets) {
185                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
186                 if (ms) {
187                         ms->copy_processors ();
188                 }
189         }
190 }
191 void
192 MixerActor::cut_processors ()
193 {
194         set_route_targets_for_operation ();
195
196         BOOST_FOREACH(RouteUI* r, _route_targets) {
197                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
198                 if (ms) {
199                         ms->cut_processors ();
200                 }
201         }
202 }
203 void
204 MixerActor::paste_processors ()
205 {
206         set_route_targets_for_operation ();
207
208         BOOST_FOREACH(RouteUI* r, _route_targets) {
209                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
210                 if (ms) {
211                         ms->paste_processors ();
212                 }
213         }
214 }
215 void
216 MixerActor::select_all_processors ()
217 {
218         set_route_targets_for_operation ();
219
220         BOOST_FOREACH(RouteUI* r, _route_targets) {
221                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
222                 if (ms) {
223                         ms->select_all_processors ();
224                 }
225         }
226 }
227 void
228 MixerActor::toggle_processors ()
229 {
230         set_route_targets_for_operation ();
231
232         BOOST_FOREACH(RouteUI* r, _route_targets) {
233                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
234                 if (ms) {
235                         ms->toggle_processors ();
236                 }
237         }
238 }
239 void
240 MixerActor::ab_plugins ()
241 {
242         set_route_targets_for_operation ();
243
244         BOOST_FOREACH(RouteUI* r, _route_targets) {
245                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
246                 if (ms) {
247                         ms->ab_plugins ();
248                 }
249         }
250 }
251