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"
29 #include "mixer_strip.h"
30 #include "ardour_ui.h"
31 #include "selection.h"
32 #include "audio_time_axis.h"
34 #include "editor_route_list.h"
39 using namespace Gtkmm2ext;
43 Editor::editor_mixer_button_toggled ()
45 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
47 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
48 show_editor_mixer (tact->get_active());
53 Editor::editor_list_button_toggled ()
55 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
57 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
58 show_editor_list (tact->get_active());
63 Editor::cms_deleted ()
65 current_mixer_strip = 0;
69 Editor::show_editor_mixer (bool yn)
71 boost::shared_ptr<ARDOUR::Route> r;
73 show_editor_mixer_when_tracks_arrive = false;
76 show_editor_mixer_when_tracks_arrive = yn;
82 if (selection->tracks.empty()) {
84 if (track_views.empty()) {
85 show_editor_mixer_when_tracks_arrive = true;
89 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
90 RouteTimeAxisView* atv;
92 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
99 sort_track_selection ();
101 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
102 RouteTimeAxisView* atv;
104 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
114 if (current_mixer_strip == 0) {
115 create_editor_mixer ();
121 current_mixer_strip->set_route (r);
124 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
128 if (current_mixer_strip->get_parent() == 0) {
129 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
130 global_hpacker.reorder_child (*current_mixer_strip, 0);
131 current_mixer_strip->show_all ();
136 if (current_mixer_strip) {
137 if (current_mixer_strip->get_parent() != 0) {
138 global_hpacker.remove (*current_mixer_strip);
144 /* XXX gtk problem here */
145 ensure_all_elements_drawn();
151 Editor::ensure_all_elements_drawn ()
153 controls_layout.queue_draw ();
154 ruler_label_event_box.queue_draw ();
155 time_button_event_box.queue_draw ();
160 Editor::show_editor_list (bool yn)
170 Editor::create_editor_mixer ()
172 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
175 current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
176 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
178 current_mixer_strip->WidthChanged.connect (mem_fun(*this, &Editor::ensure_all_elements_drawn));
180 current_mixer_strip->set_embedded (true);
184 Editor::set_selected_mixer_strip (TimeAxisView& view)
186 RouteTimeAxisView* at;
189 if (!session || (at = dynamic_cast<RouteTimeAxisView*>(&view)) == 0) {
193 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
196 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
197 if (!tact || !tact->get_active()) {
198 /* not showing mixer strip presently */
203 if (current_mixer_strip == 0) {
204 create_editor_mixer ();
210 /* might be nothing to do */
212 if (current_mixer_strip->route() == at->route()) {
217 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
220 current_mixer_strip->set_route (at->route());
223 double current = 0.0;
226 Editor::update_current_screen ()
228 if (_pending_locate_request) {
229 /* we don't update things when there's a pending locate request, otherwise
230 when the editor requests a locate there is a chance that this method
231 will move the playhead before the locate request is processed, causing
236 if (session && session->engine().running()) {
238 nframes64_t const frame = session->audible_frame();
240 if (_dragging_playhead) {
244 /* only update if the playhead is on screen or we are following it */
246 if (_follow_playhead && session->requested_return_frame() < 0) {
248 //playhead_cursor->canvas_item.show();
250 if (frame != last_update_frame) {
253 #undef CONTINUOUS_SCROLL
254 #ifndef CONTINUOUS_SCROLL
255 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
257 if (session->transport_speed() < 0) {
258 if (frame > (current_page_frames()/2)) {
259 center_screen (frame-(current_page_frames()/2));
261 center_screen (current_page_frames()/2);
264 center_screen (frame+(current_page_frames()/2));
268 playhead_cursor->set_position (frame);
270 #else // CONTINUOUS_SCROLL
272 /* don't do continuous scroll till the new position is in the rightmost quarter of the
276 if (session->transport_speed()) {
277 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
278 if (target <= 0.0) target = 0.0;
279 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
280 target = (target * 0.15) + (current * 0.85);
284 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
286 horizontal_adjustment.set_value ( current );
289 playhead_cursor->set_position (frame);
291 #endif // CONTINUOUS_SCROLL
296 if (frame != last_update_frame) {
297 playhead_cursor->set_position (frame);
302 last_update_frame = frame;
303 if (current_mixer_strip) {
304 current_mixer_strip->fast_update ();
311 Editor::current_mixer_strip_removed ()
313 if (current_mixer_strip) {
314 /* it is being deleted elsewhere */
315 current_mixer_strip = 0;
320 Editor::current_mixer_strip_hidden ()
322 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
324 RouteTimeAxisView* tmp;
326 if ((tmp = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
327 if (tmp->route() == current_mixer_strip->route()) {
328 (*i)->set_selected (false);
334 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
336 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
337 tact->set_active (false);
342 Editor::session_going_away ()
346 for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
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 /* hide all tracks */
367 _route_list->hide_all_tracks (false);
369 /* rip everything out of the list displays */
371 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
372 _route_list->clear ();
373 named_selection_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
374 route_group_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
376 region_list_model->clear ();
377 named_selection_model->clear ();
378 group_model->clear ();
380 region_list_display.set_model (region_list_model);
381 named_selection_display.set_model (named_selection_model);
382 route_group_display.set_model (group_model);
384 edit_point_clock_connection_a.disconnect();
385 edit_point_clock_connection_b.disconnect();
387 edit_point_clock.set_session (0);
388 zoom_range_clock.set_session (0);
389 nudge_clock.set_session (0);
391 editor_list_button.set_active(false);
392 editor_list_button.set_sensitive(false);
394 /* clear tempo/meter rulers */
395 remove_metric_marks ();
397 clear_marker_display ();
399 delete current_bbt_points;
400 current_bbt_points = 0;
402 /* get rid of any existing editor mixer strip */
404 if (current_mixer_strip) {
405 if (current_mixer_strip->get_parent() != 0) {
406 global_hpacker.remove (*current_mixer_strip);
408 delete current_mixer_strip;
409 current_mixer_strip = 0;
412 WindowTitle title(Glib::get_application_name());
413 title += _("Editor");
415 set_title (title.get_string());
421 Editor::maybe_add_mixer_strip_width (XMLNode& node)
423 if (current_mixer_strip) {
424 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width_enum()));