replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[ardour.git] / gtk2_ardour / editor_mixer.cc
1 /*
2     Copyright (C) 2003-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 <glibmm/miscutils.h>
25 #include <gtkmm/messagedialog.h>
26 #include <gtkmm2ext/utils.h>
27 #include <gtkmm2ext/window_title.h>
28
29 #include "pbd/enumwriter.h"
30
31 #include "ardour/rc_configuration.h"
32
33 #include "control_protocol/control_protocol.h"
34
35 #include "actions.h"
36 #include "ardour_ui.h"
37 #include "audio_time_axis.h"
38 #include "automation_time_axis.h"
39 #include "editor.h"
40 #include "editor_route_groups.h"
41 #include "editor_regions.h"
42 #include "enums_convert.h"
43 #include "gui_thread.h"
44 #include "midi_time_axis.h"
45 #include "mixer_strip.h"
46 #include "mixer_ui.h"
47 #include "selection.h"
48 #include "ui_config.h"
49
50 #include "pbd/i18n.h"
51
52 using namespace std;
53 using namespace Gtkmm2ext;
54 using namespace PBD;
55
56 void
57 Editor::editor_mixer_button_toggled ()
58 {
59         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
60         if (act) {
61                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
62                 show_editor_mixer (tact->get_active());
63         }
64 }
65
66 void
67 Editor::editor_list_button_toggled ()
68 {
69         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
70         if (act) {
71                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
72                 show_editor_list (tact->get_active());
73         }
74 }
75
76 void
77 Editor::show_editor_mixer (bool yn)
78 {
79         boost::shared_ptr<ARDOUR::Route> r;
80
81         show_editor_mixer_when_tracks_arrive = false;
82
83         if (yn) {
84                 Gtk::Window* toplevel = current_toplevel();
85                 Glib::RefPtr<Gdk::Window> win;
86                 Glib::RefPtr<Gdk::Screen> screen;
87
88                 if (toplevel) {
89                         win = toplevel->get_window();
90                 }
91
92                 if (win) {
93                         screen = win->get_screen();
94                 } else {
95                         screen = Gdk::Screen::get_default();
96                 }
97
98                 if (g_getenv ("ARDOUR_LOVES_STUPID_TINY_SCREENS") == 0 && screen && screen->get_height() < 700) {
99                         Gtk::MessageDialog msg (_("This screen is not tall enough to display the editor mixer"));
100                         msg.run ();
101                         return;
102                 }
103         }
104
105         if (!_session) {
106                 show_editor_mixer_when_tracks_arrive = yn;
107                 return;
108         }
109
110         if (yn) {
111
112                 if (selection->tracks.empty()) {
113
114                         if (track_views.empty()) {
115                                 show_editor_mixer_when_tracks_arrive = true;
116                                 return;
117                         }
118
119                         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
120                                 RouteTimeAxisView* atv;
121
122                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
123                                         r = atv->route();
124                                         break;
125                                 }
126                         }
127
128                 } else {
129                         sort_track_selection (selection->tracks);
130
131                         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
132                                 RouteTimeAxisView* atv;
133
134                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
135                                         r = atv->route();
136                                         break;
137                                 }
138                         }
139                 }
140
141                 if (r) {
142                         if (current_mixer_strip == 0) {
143                                 create_editor_mixer ();
144                         }
145                 }
146
147                 if (current_mixer_strip && current_mixer_strip->get_parent() == 0) {
148                         global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
149                         global_hpacker.reorder_child (*current_mixer_strip, 0);
150                         current_mixer_strip->show ();
151                 }
152
153                 if (r) {
154                         current_mixer_strip->set_route (r);
155                         current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
156                 }
157
158         } else {
159
160                 if (current_mixer_strip) {
161                         if (current_mixer_strip->get_parent() != 0) {
162                                 global_hpacker.remove (*current_mixer_strip);
163                         }
164                 }
165         }
166
167 #ifdef __APPLE__
168         /* XXX gtk problem here */
169         ensure_all_elements_drawn();
170 #endif
171 }
172
173 #ifdef __APPLE__
174 void
175 Editor::ensure_all_elements_drawn ()
176 {
177         controls_layout.queue_draw ();
178         time_bars_event_box.queue_draw ();
179 }
180 #endif
181
182 void
183 Editor::create_editor_mixer ()
184 {
185         current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(), _session, false);
186         current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
187         current_mixer_strip->WidthChanged.connect (sigc::mem_fun (*this, &Editor::mixer_strip_width_changed));
188
189 #ifdef __APPLE__
190         current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
191 #endif
192         current_mixer_strip->set_embedded (true);
193
194 }
195
196 void
197 Editor::set_selected_mixer_strip (TimeAxisView& view)
198 {
199         if (!_session) {
200                 return;
201         }
202
203         // if this is an automation track, then we shold the mixer strip should
204         // show the parent
205
206         boost::shared_ptr<ARDOUR::Stripable> stripable;
207         AutomationTimeAxisView* atv;
208
209         if ((atv = dynamic_cast<AutomationTimeAxisView*>(&view)) != 0) {
210                 AudioTimeAxisView *parent = dynamic_cast<AudioTimeAxisView*>(view.get_parent());
211                 if (parent) {
212                         stripable = parent->stripable ();
213                 }
214         } else {
215                 StripableTimeAxisView* stav = dynamic_cast<StripableTimeAxisView*> (&view);
216                 if (stav) {
217                         stripable = stav->stripable();
218                 }
219         }
220
221         /* Typically this is set by changing the TAV selection but if for any
222          * reason we decide to show a different strip for some reason, make
223          * sure that control surfaces can find it.
224          */
225         ARDOUR::ControlProtocol::set_first_selected_stripable (stripable);
226
227         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
228
229         if (act) {
230                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
231                 if (!tact || !tact->get_active()) {
232                         /* not showing mixer strip presently */
233                         return;
234                 }
235         }
236
237         if (current_mixer_strip == 0) {
238                 create_editor_mixer ();
239         }
240
241         boost::shared_ptr<ARDOUR::Route> route = boost::dynamic_pointer_cast<ARDOUR::Route> (stripable);
242         if (current_mixer_strip->route() == route) {
243                 return;
244         }
245
246         if (route) {
247                 current_mixer_strip->set_route (route);
248                 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
249         }
250 }
251
252 void
253 Editor::current_mixer_strip_hidden ()
254 {
255         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
256         if (act) {
257                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
258                 tact->set_active (false);
259         }
260 }
261
262 void
263 Editor::maybe_add_mixer_strip_width (XMLNode& node)
264 {
265         if (current_mixer_strip) {
266                 node.set_property ("mixer-width", editor_mixer_strip_width);
267         }
268 }
269
270 void
271 Editor::mixer_strip_width_changed ()
272 {
273 #ifdef __APPLE__
274         ensure_all_elements_drawn ();
275 #endif
276
277         editor_mixer_strip_width = current_mixer_strip->get_width_enum ();
278 }