make AU Cocoa plugin views with "client-side-windows" versions of GTK+; make keyboard...
[ardour2.git] / gtk2_ardour / editor_mixer.cc
blobd6fa49a132ac87e7633133b578f415008b357f5c
1 /*
2 Copyright (C) 2003-2004 Paul Davis
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.
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.
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.
20 #include <glibmm/miscutils.h>
21 #include <gtkmm2ext/utils.h>
22 #include <gtkmm2ext/window_title.h>
24 #include <pbd/enumwriter.h>
26 #include <ardour/audioengine.h>
28 #include "editor.h"
29 #include "mixer_strip.h"
30 #include "ardour_ui.h"
31 #include "selection.h"
32 #include "audio_time_axis.h"
33 #include "automation_time_axis.h"
34 #include "actions.h"
36 #include "i18n.h"
38 using namespace Gtkmm2ext;
39 using namespace PBD;
41 void
42 Editor::editor_mixer_button_toggled ()
44 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
45 if (act) {
46 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
47 show_editor_mixer (tact->get_active());
51 void
52 Editor::cms_deleted ()
54 current_mixer_strip = 0;
57 void
58 Editor::show_editor_mixer (bool yn)
60 boost::shared_ptr<ARDOUR::Route> r;
62 show_editor_mixer_when_tracks_arrive = false;
64 if (!session) {
65 show_editor_mixer_when_tracks_arrive = yn;
66 return;
69 if (yn) {
71 if (selection->tracks.empty()) {
73 if (track_views.empty()) {
74 show_editor_mixer_when_tracks_arrive = true;
75 return;
78 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
79 AudioTimeAxisView* atv;
81 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
82 r = atv->route();
83 break;
87 } else {
89 sort_track_selection ();
91 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
92 AudioTimeAxisView* atv;
94 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
95 r = atv->route();
96 break;
101 if (r) {
102 bool created;
104 if (current_mixer_strip == 0) {
105 create_editor_mixer ();
106 created = true;
107 } else {
108 created = false;
111 current_mixer_strip->set_route (r);
113 if (created) {
114 current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
118 if (current_mixer_strip->get_parent() == 0) {
119 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
120 global_hpacker.reorder_child (*current_mixer_strip, 0);
121 current_mixer_strip->show_all ();
124 } else {
126 if (current_mixer_strip) {
127 if (current_mixer_strip->get_parent() != 0) {
128 global_hpacker.remove (*current_mixer_strip);
133 #ifdef GTKOSX
134 /* XXX gtk problem here */
135 ensure_all_elements_drawn();
136 #endif
139 #ifdef GTKOSX
140 void
141 Editor::ensure_all_elements_drawn ()
143 controls_layout.queue_draw ();
144 ruler_label_event_box.queue_draw ();
145 time_button_event_box.queue_draw ();
147 #endif
149 void
150 Editor::create_editor_mixer ()
152 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
153 *session,
154 false);
155 current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
156 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
157 #ifdef GTKOSX
158 current_mixer_strip->WidthChanged.connect (mem_fun(*this, &Editor::ensure_all_elements_drawn));
159 #endif
160 current_mixer_strip->set_embedded (true);
163 void
164 Editor::set_selected_mixer_strip (TimeAxisView& view)
166 bool show = false;
167 bool created;
169 if (!session)
170 return;
172 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
173 if (act) {
174 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
175 if (!tact || !tact->get_active()) {
176 /* not showing mixer strip presently */
177 return;
181 if (current_mixer_strip == 0) {
182 create_editor_mixer ();
183 created = true;
184 } else {
185 created = false;
188 //if this is an automation track then we should show the parent
189 boost::shared_ptr<ARDOUR::Route> route;
190 AutomationTimeAxisView *auto_tav;
191 if ( (auto_tav = dynamic_cast<AutomationTimeAxisView*>(&view)) == 0 ) {
192 AudioTimeAxisView* at = dynamic_cast<AudioTimeAxisView*>(&view);
193 if (at != NULL)
194 route = at->route();
195 } else {
196 AudioTimeAxisView *parent = dynamic_cast<AudioTimeAxisView*>( view.get_parent() );
197 if (parent != NULL) {
198 route = parent->route();
202 if (current_mixer_strip->route() == route) {
203 return;
206 if (current_mixer_strip->get_parent()) {
207 show = true;
210 current_mixer_strip->set_route (route);
212 if (created) {
213 current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
216 if (show) {
217 show_editor_mixer (true);
221 double current = 0.0;
223 void
224 Editor::update_current_screen ()
226 if (session && session->engine().running()) {
228 nframes64_t frame;
230 //frame = session->audible_frame();
231 frame = session->transport_frame ();
233 if (_dragging_playhead) {
234 goto almost_done;
237 #undef DEBUG_CURRENT_SCREEN
238 #if DEBUG_CURRENT_SCREEN
240 cerr << "@ " << frame << " last " << last_update_frame << " follow " << _follow_playhead
241 << " ret " << session->requested_return_frame()
242 << " left " << leftmost_frame
243 << " right " << leftmost_frame + current_page_frames()
244 << " speed " << session->transport_speed ()
245 << endl;
246 #endif
248 /* only update if the playhead is on screen or we are following it */
250 if (_follow_playhead && session->requested_return_frame() < 0) {
252 //playhead_cursor->canvas_item.show();
254 if (frame != last_update_frame) {
257 if ( !_stationary_playhead ) {
258 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
260 #ifdef DEBUG_CURRENT_SCREEN
261 cerr << "\trecenter...\n";
262 #endif
263 if (session->transport_speed() < 0) {
264 if (frame > (current_page_frames()/2)) {
265 center_screen (frame-(current_page_frames()/2));
266 } else {
267 center_screen (current_page_frames()/2);
269 } else {
270 center_screen (frame+(current_page_frames()/2));
274 playhead_cursor->set_position (frame);
276 } else {
278 /* don't do continuous scroll till the new position is in the rightmost quarter of the
279 editor canvas
282 if (session->transport_speed()) {
283 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
284 if (target <= 0.0) target = 0.0;
285 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
286 target = (target * 0.15) + (current * 0.85);
287 } else {
288 /* relax */
290 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
291 current = target;
292 horizontal_adjustment.set_value ( current );
295 playhead_cursor->set_position (frame);
301 } else {
303 if (frame != last_update_frame) {
304 playhead_cursor->set_position (frame);
308 almost_done:
309 last_update_frame = frame;
310 if (current_mixer_strip) {
311 current_mixer_strip->fast_update ();
317 void
318 Editor::current_mixer_strip_removed ()
320 if (current_mixer_strip) {
321 /* it is being deleted elsewhere */
322 current_mixer_strip = 0;
326 void
327 Editor::current_mixer_strip_hidden ()
329 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
330 if (act) {
331 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
332 tact->set_active (false);
336 void
337 Editor::session_going_away ()
339 _have_idled = false;
341 for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
342 (*i).disconnect ();
345 stop_scrolling ();
346 selection->clear ();
347 cut_buffer->clear ();
349 clicked_regionview = 0;
350 clicked_trackview = 0;
351 clicked_audio_trackview = 0;
352 clicked_crossfadeview = 0;
353 entered_regionview = 0;
354 entered_track = 0;
355 last_update_frame = 0;
356 drag_info.item = 0;
358 playhead_cursor->canvas_item.hide ();
360 /* hide all tracks */
362 hide_all_tracks (false);
364 /* rip everything out of the list displays */
366 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
367 route_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
368 named_selection_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
369 edit_group_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
371 region_list_model->clear ();
372 route_display_model->clear ();
373 named_selection_model->clear ();
374 group_model->clear ();
376 region_list_display.set_model (region_list_model);
377 route_list_display.set_model (route_display_model);
378 named_selection_display.set_model (named_selection_model);
379 edit_group_display.set_model (group_model);
381 edit_point_clock_connection_a.disconnect();
382 edit_point_clock_connection_b.disconnect();
384 edit_point_clock.set_session (0);
385 zoom_range_clock.set_session (0);
386 nudge_clock.set_session (0);
388 /* clear tempo/meter rulers */
389 remove_metric_marks ();
390 hide_measures ();
391 clear_marker_display ();
393 if (current_bbt_points) {
394 delete current_bbt_points;
395 current_bbt_points = 0;
398 /* get rid of any existing editor mixer strip */
400 if (current_mixer_strip) {
401 if (current_mixer_strip->get_parent() != 0) {
402 global_hpacker.remove (*current_mixer_strip);
404 delete current_mixer_strip;
405 current_mixer_strip = 0;
408 WindowTitle title(Glib::get_application_name());
409 title += _("Editor");
411 set_title (title.get_string());
413 session = 0;
416 void
417 Editor::maybe_add_mixer_strip_width (XMLNode& node)
419 if (current_mixer_strip) {
420 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width()));