Prevent erroneous splitting icons in the editor mixer strip's processor box.
[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 <gtkmm2ext/utils.h>
26 #include <gtkmm2ext/window_title.h>
27
28 #include "pbd/enumwriter.h"
29
30 #include "actions.h"
31 #include "ardour_ui.h"
32 #include "audio_time_axis.h"
33 #include "automation_time_axis.h"
34 #include "editor.h"
35 #include "editor_routes.h"
36 #include "editor_route_groups.h"
37 #include "editor_regions.h"
38 #include "gui_thread.h"
39 #include "midi_time_axis.h"
40 #include "mixer_strip.h"
41 #include "selection.h"
42
43 #include "i18n.h"
44
45 using namespace std;
46 using namespace Gtkmm2ext;
47 using namespace PBD;
48
49 void
50 Editor::editor_mixer_button_toggled ()
51 {
52         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
53         if (act) {
54                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
55                 show_editor_mixer (tact->get_active());
56         }
57 }
58
59 void
60 Editor::editor_list_button_toggled ()
61 {
62         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
63         if (act) {
64                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
65                 show_editor_list (tact->get_active());
66         }
67 }
68
69 void
70 Editor::show_editor_mixer (bool yn)
71 {
72         boost::shared_ptr<ARDOUR::Route> r;
73
74         show_editor_mixer_when_tracks_arrive = false;
75
76         if (!_session) {
77                 show_editor_mixer_when_tracks_arrive = yn;
78                 return;
79         }
80
81         if (yn) {
82
83                 if (selection->tracks.empty()) {
84
85                         if (track_views.empty()) {
86                                 show_editor_mixer_when_tracks_arrive = true;
87                                 return;
88                         }
89
90                         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
91                                 RouteTimeAxisView* atv;
92
93                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
94                                         r = atv->route();
95                                         break;
96                                 }
97                         }
98
99                 } else {
100                         sort_track_selection ();
101
102                         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
103                                 RouteTimeAxisView* atv;
104
105                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
106                                         r = atv->route();
107                                         break;
108                                 }
109                         }
110                 }
111
112                 if (r) {
113                         if (current_mixer_strip == 0) {
114                                 create_editor_mixer ();
115                         }
116
117                         current_mixer_strip->set_route (r);
118                         current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
119                 }
120
121                 if (current_mixer_strip->get_parent() == 0) {
122                         global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
123                         global_hpacker.reorder_child (*current_mixer_strip, 0);
124                         current_mixer_strip->show ();
125                 }
126
127         } else {
128
129                 if (current_mixer_strip) {
130                         if (current_mixer_strip->get_parent() != 0) {
131                                 global_hpacker.remove (*current_mixer_strip);
132                         }
133                 }
134         }
135
136 #ifdef GTKOSX
137         /* XXX gtk problem here */
138         ensure_all_elements_drawn();
139 #endif
140 }
141
142 #ifdef GTKOSX
143 void
144 Editor::ensure_all_elements_drawn ()
145 {
146         controls_layout.queue_draw ();
147         ruler_label_event_box.queue_draw ();
148         time_button_event_box.queue_draw ();
149 }
150 #endif
151
152 void
153 Editor::create_editor_mixer ()
154 {
155         current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
156                                               _session,
157                                               false);
158         current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
159         current_mixer_strip->WidthChanged.connect (sigc::mem_fun (*this, &Editor::mixer_strip_width_changed));
160
161 #ifdef GTKOSX
162         current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
163 #endif
164         current_mixer_strip->set_embedded (true);
165 }
166
167 void
168 Editor::set_selected_mixer_strip (TimeAxisView& view)
169 {
170         if (!_session) {
171                 return;
172         }
173
174         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
175
176         if (act) {
177                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
178                 if (!tact || !tact->get_active()) {
179                         /* not showing mixer strip presently */
180                         return;
181                 }
182         }
183
184         if (current_mixer_strip == 0) {
185                 create_editor_mixer ();
186         }
187
188
189         // if this is an automation track, then we shold the mixer strip should
190         // show the parent
191
192         boost::shared_ptr<ARDOUR::Route> route;
193         AutomationTimeAxisView* atv;
194         
195         if ((atv = dynamic_cast<AutomationTimeAxisView*>(&view)) != 0) {
196
197                 AudioTimeAxisView *parent = dynamic_cast<AudioTimeAxisView*>(view.get_parent());
198
199                 if (parent) {
200                         route = parent->route ();
201                 }
202
203         } else {
204
205                 AudioTimeAxisView* at = dynamic_cast<AudioTimeAxisView*> (&view);
206
207                 if (at) {
208                         route = at->route();
209                 } else {
210                         MidiTimeAxisView* mt = dynamic_cast<MidiTimeAxisView*> (&view);
211                         if (mt) {
212                                 route = mt->route();
213                         }
214                 }
215         }
216                 
217         if (current_mixer_strip->route() == route) {
218                 return;
219         }
220
221         if (route) {
222                 current_mixer_strip->set_route (route);
223                 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
224         }
225 }
226
227 void
228 Editor::current_mixer_strip_hidden ()
229 {
230         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
231         if (act) {
232                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
233                 tact->set_active (false);
234         }
235 }
236
237 void
238 Editor::maybe_add_mixer_strip_width (XMLNode& node)
239 {
240         if (current_mixer_strip) {
241                 node.add_property ("mixer-width", enum_2_string (editor_mixer_strip_width));
242         }
243 }
244
245 void
246 Editor::mixer_strip_width_changed ()
247 {
248 #ifdef GTKOSX
249         ensure_all_elements_drawn ();
250 #endif
251
252         editor_mixer_strip_width = current_mixer_strip->get_width_enum ();
253 }