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