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"
39 #include "editor_drag.h"
44 using namespace Gtkmm2ext;
48 Editor::editor_mixer_button_toggled ()
50 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
52 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
53 show_editor_mixer (tact->get_active());
58 Editor::editor_list_button_toggled ()
60 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
62 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
63 show_editor_list (tact->get_active());
68 Editor::show_editor_mixer (bool yn)
70 boost::shared_ptr<ARDOUR::Route> r;
72 show_editor_mixer_when_tracks_arrive = false;
75 show_editor_mixer_when_tracks_arrive = yn;
81 if (selection->tracks.empty()) {
83 if (track_views.empty()) {
84 show_editor_mixer_when_tracks_arrive = true;
88 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
89 RouteTimeAxisView* atv;
91 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
98 sort_track_selection ();
100 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
101 RouteTimeAxisView* atv;
103 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
111 if (current_mixer_strip == 0) {
112 create_editor_mixer ();
115 current_mixer_strip->set_route (r);
116 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
119 if (current_mixer_strip->get_parent() == 0) {
120 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
121 global_hpacker.reorder_child (*current_mixer_strip, 0);
122 current_mixer_strip->show_all ();
127 if (current_mixer_strip) {
128 if (current_mixer_strip->get_parent() != 0) {
129 global_hpacker.remove (*current_mixer_strip);
135 /* XXX gtk problem here */
136 ensure_all_elements_drawn();
142 Editor::ensure_all_elements_drawn ()
144 controls_layout.queue_draw ();
145 ruler_label_event_box.queue_draw ();
146 time_button_event_box.queue_draw ();
151 Editor::show_editor_list (bool yn)
161 Editor::create_editor_mixer ()
163 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
166 current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
169 current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
171 current_mixer_strip->set_embedded (true);
175 Editor::set_selected_mixer_strip (TimeAxisView& view)
177 RouteTimeAxisView* at;
179 if (!_session || (at = dynamic_cast<RouteTimeAxisView*>(&view)) == 0) {
183 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
186 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
187 if (!tact || !tact->get_active()) {
188 /* not showing mixer strip presently */
193 if (current_mixer_strip == 0) {
194 create_editor_mixer ();
197 /* might be nothing to do */
199 if (current_mixer_strip->route() == at->route()) {
203 current_mixer_strip->set_route (at->route());
204 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
207 double current = 0.0;
210 Editor::update_current_screen ()
212 if (_pending_locate_request) {
213 /* we don't update things when there's a pending locate request, otherwise
214 when the editor requests a locate there is a chance that this method
215 will move the playhead before the locate request is processed, causing
220 if (_session && _session->engine().running()) {
222 nframes64_t const frame = _session->audible_frame();
224 if (_dragging_playhead) {
228 /* only update if the playhead is on screen or we are following it */
230 if (_follow_playhead && _session->requested_return_frame() < 0) {
232 //playhead_cursor->canvas_item.show();
234 if (frame != last_update_frame) {
237 #undef CONTINUOUS_SCROLL
238 #ifndef CONTINUOUS_SCROLL
239 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
241 if (_session->transport_speed() < 0) {
242 if (frame > (current_page_frames()/2)) {
243 center_screen (frame-(current_page_frames()/2));
245 center_screen (current_page_frames()/2);
250 if (frame < leftmost_frame) {
253 if (_session->transport_rolling()) {
254 /* rolling; end up with the playhead at the right of the page */
255 l = frame - current_page_frames ();
257 /* not rolling: end up with the playhead 3/4 of the way along the page */
258 l = frame - (3 * current_page_frames() / 4);
265 center_screen_internal (l + (current_page_frames() / 2), current_page_frames ());
268 if (_session->transport_rolling()) {
269 /* rolling: end up with the playhead on the left of the page */
270 center_screen_internal (frame + (current_page_frames() / 2), current_page_frames ());
272 /* not rolling: end up with the playhead 1/4 of the way along the page */
273 center_screen_internal (frame + (current_page_frames() / 4), current_page_frames ());
279 playhead_cursor->set_position (frame);
281 #else // CONTINUOUS_SCROLL
283 /* don't do continuous scroll till the new position is in the rightmost quarter of the
287 if (_session->transport_speed()) {
288 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
289 if (target <= 0.0) target = 0.0;
290 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
291 target = (target * 0.15) + (current * 0.85);
295 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
297 horizontal_adjustment.set_value ( current );
300 playhead_cursor->set_position (frame);
302 #endif // CONTINUOUS_SCROLL
307 if (frame != last_update_frame) {
308 playhead_cursor->set_position (frame);
313 last_update_frame = frame;
314 if (current_mixer_strip) {
315 current_mixer_strip->fast_update ();
322 Editor::current_mixer_strip_hidden ()
324 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
326 RouteTimeAxisView* tmp;
328 if ((tmp = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
329 if (tmp->route() == current_mixer_strip->route()) {
330 (*i)->set_selected (false);
336 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
338 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
339 tact->set_active (false);
344 Editor::session_going_away ()
348 _session_connections.drop_connections ();
352 cut_buffer->clear ();
354 clicked_regionview = 0;
355 clicked_axisview = 0;
356 clicked_routeview = 0;
357 clicked_crossfadeview = 0;
358 entered_regionview = 0;
360 last_update_frame = 0;
363 playhead_cursor->canvas_item.hide ();
365 /* rip everything out of the list displays */
369 _route_groups->clear ();
371 /* do this first so that deleting a track doesn't reset cms to null
372 and thus cause a leak.
375 if (current_mixer_strip) {
376 if (current_mixer_strip->get_parent() != 0) {
377 global_hpacker.remove (*current_mixer_strip);
379 delete current_mixer_strip;
380 current_mixer_strip = 0;
383 /* delete all trackviews */
385 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
388 track_views.clear ();
390 zoom_range_clock.set_session (0);
391 nudge_clock.set_session (0);
393 editor_list_button.set_active(false);
394 editor_list_button.set_sensitive(false);
396 /* clear tempo/meter rulers */
397 remove_metric_marks ();
399 clear_marker_display ();
401 delete current_bbt_points;
402 current_bbt_points = 0;
404 /* get rid of any existing editor mixer strip */
406 WindowTitle title(Glib::get_application_name());
407 title += _("Editor");
409 set_title (title.get_string());
411 SessionHandlePtr::session_going_away ();
415 Editor::maybe_add_mixer_strip_width (XMLNode& node)
417 if (current_mixer_strip) {
418 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width_enum()));