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