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"
27 #include "ardour/session.h"
30 #include "mixer_strip.h"
31 #include "ardour_ui.h"
32 #include "selection.h"
33 #include "audio_time_axis.h"
35 #include "editor_routes.h"
36 #include "editor_route_groups.h"
37 #include "editor_regions.h"
38 #include "gui_thread.h"
43 using namespace Gtkmm2ext;
47 Editor::editor_mixer_button_toggled ()
49 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
51 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
52 show_editor_mixer (tact->get_active());
57 Editor::editor_list_button_toggled ()
59 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
61 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
62 show_editor_list (tact->get_active());
67 Editor::cms_deleted ()
69 current_mixer_strip = 0;
73 Editor::show_editor_mixer (bool yn)
75 boost::shared_ptr<ARDOUR::Route> r;
77 show_editor_mixer_when_tracks_arrive = false;
80 show_editor_mixer_when_tracks_arrive = yn;
86 if (selection->tracks.empty()) {
88 if (track_views.empty()) {
89 show_editor_mixer_when_tracks_arrive = true;
93 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
94 RouteTimeAxisView* atv;
96 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
103 sort_track_selection ();
105 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
106 RouteTimeAxisView* atv;
108 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
116 if (current_mixer_strip == 0) {
117 create_editor_mixer ();
120 current_mixer_strip->set_route (r);
121 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
124 if (current_mixer_strip->get_parent() == 0) {
125 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
126 global_hpacker.reorder_child (*current_mixer_strip, 0);
127 current_mixer_strip->show_all ();
132 if (current_mixer_strip) {
133 if (current_mixer_strip->get_parent() != 0) {
134 global_hpacker.remove (*current_mixer_strip);
140 /* XXX gtk problem here */
141 ensure_all_elements_drawn();
147 Editor::ensure_all_elements_drawn ()
149 controls_layout.queue_draw ();
150 ruler_label_event_box.queue_draw ();
151 time_button_event_box.queue_draw ();
156 Editor::show_editor_list (bool yn)
166 Editor::create_editor_mixer ()
168 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
171 current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
172 current_mixer_strip->CatchDeletion.connect (*this, boost::bind (&Editor::current_mixer_strip_removed, this), gui_context());
174 current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
176 current_mixer_strip->set_embedded (true);
180 Editor::set_selected_mixer_strip (TimeAxisView& view)
182 RouteTimeAxisView* at;
184 if (!_session || (at = dynamic_cast<RouteTimeAxisView*>(&view)) == 0) {
188 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
191 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
192 if (!tact || !tact->get_active()) {
193 /* not showing mixer strip presently */
198 if (current_mixer_strip == 0) {
199 create_editor_mixer ();
202 /* might be nothing to do */
204 if (current_mixer_strip->route() == at->route()) {
208 current_mixer_strip->set_route (at->route());
209 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
212 double current = 0.0;
215 Editor::update_current_screen ()
217 if (_pending_locate_request) {
218 /* we don't update things when there's a pending locate request, otherwise
219 when the editor requests a locate there is a chance that this method
220 will move the playhead before the locate request is processed, causing
225 if (_session && _session->engine().running()) {
227 nframes64_t const frame = _session->audible_frame();
229 if (_dragging_playhead) {
233 /* only update if the playhead is on screen or we are following it */
235 if (_follow_playhead && _session->requested_return_frame() < 0) {
237 //playhead_cursor->canvas_item.show();
239 if (frame != last_update_frame) {
242 #undef CONTINUOUS_SCROLL
243 #ifndef CONTINUOUS_SCROLL
244 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
246 if (_session->transport_speed() < 0) {
247 if (frame > (current_page_frames()/2)) {
248 center_screen (frame-(current_page_frames()/2));
250 center_screen (current_page_frames()/2);
253 center_screen (frame+(current_page_frames()/2));
257 playhead_cursor->set_position (frame);
259 #else // CONTINUOUS_SCROLL
261 /* don't do continuous scroll till the new position is in the rightmost quarter of the
265 if (_session->transport_speed()) {
266 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
267 if (target <= 0.0) target = 0.0;
268 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
269 target = (target * 0.15) + (current * 0.85);
273 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
275 horizontal_adjustment.set_value ( current );
278 playhead_cursor->set_position (frame);
280 #endif // CONTINUOUS_SCROLL
285 if (frame != last_update_frame) {
286 playhead_cursor->set_position (frame);
291 last_update_frame = frame;
292 if (current_mixer_strip) {
293 current_mixer_strip->fast_update ();
300 Editor::current_mixer_strip_removed ()
302 if (current_mixer_strip) {
303 /* it is being deleted elsewhere */
304 current_mixer_strip = 0;
309 Editor::current_mixer_strip_hidden ()
311 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
313 RouteTimeAxisView* tmp;
315 if ((tmp = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
316 if (tmp->route() == current_mixer_strip->route()) {
317 (*i)->set_selected (false);
323 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
325 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
326 tact->set_active (false);
331 Editor::session_going_away ()
335 _session_connections.drop_connections ();
339 cut_buffer->clear ();
341 clicked_regionview = 0;
342 clicked_axisview = 0;
343 clicked_routeview = 0;
344 clicked_crossfadeview = 0;
345 entered_regionview = 0;
347 last_update_frame = 0;
350 playhead_cursor->canvas_item.hide ();
352 /* rip everything out of the list displays */
356 _route_groups->clear ();
358 /* do this first so that deleting a track doesn't reset cms to null
359 and thus cause a leak.
362 if (current_mixer_strip) {
363 if (current_mixer_strip->get_parent() != 0) {
364 global_hpacker.remove (*current_mixer_strip);
366 delete current_mixer_strip;
367 current_mixer_strip = 0;
370 /* delete all trackviews */
372 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
375 track_views.clear ();
377 zoom_range_clock.set_session (0);
378 nudge_clock.set_session (0);
380 editor_list_button.set_active(false);
381 editor_list_button.set_sensitive(false);
383 /* clear tempo/meter rulers */
384 remove_metric_marks ();
386 clear_marker_display ();
388 delete current_bbt_points;
389 current_bbt_points = 0;
391 /* get rid of any existing editor mixer strip */
393 WindowTitle title(Glib::get_application_name());
394 title += _("Editor");
396 set_title (title.get_string());
398 SessionHandlePtr::session_going_away ();
402 Editor::maybe_add_mixer_strip_width (XMLNode& node)
404 if (current_mixer_strip) {
405 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width_enum()));