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"
37 using namespace Gtkmm2ext;
41 Editor::editor_mixer_button_toggled ()
43 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
45 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
46 show_editor_mixer (tact->get_active());
51 Editor::editor_list_button_toggled ()
53 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
55 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
56 show_editor_list (tact->get_active());
61 Editor::cms_new (boost::shared_ptr<ARDOUR::Route> r)
63 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(), *session, r);
64 current_mixer_strip->GoingAway.connect (mem_fun (*this, &Editor::cms_deleted));
68 Editor::cms_deleted ()
70 current_mixer_strip = 0;
74 Editor::show_editor_mixer (bool yn)
76 show_editor_mixer_when_tracks_arrive = false;
80 if (current_mixer_strip == 0) {
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 AudioTimeAxisView* atv;
92 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
93 cms_new (atv->route ());
100 sort_track_selection ();
102 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
103 AudioTimeAxisView* atv;
105 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
106 cms_new (atv->route ());
113 if (current_mixer_strip == 0) {
118 if (current_mixer_strip->get_parent() == 0) {
119 current_mixer_strip->set_embedded (true);
120 current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
121 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
122 current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
124 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
125 global_hpacker.reorder_child (*current_mixer_strip, 0);
127 current_mixer_strip->show_all ();
132 if (current_mixer_strip) {
133 editor_mixer_strip_width = current_mixer_strip->get_width ();
134 if (current_mixer_strip->get_parent() != 0) {
135 global_hpacker.remove (*current_mixer_strip);
140 /* XXX gtk problem here */
141 ruler_label_event_box.queue_draw ();
142 time_button_event_box.queue_draw ();
143 controls_layout.queue_draw ();
148 Editor::show_editor_list (bool yn)
158 Editor::set_selected_mixer_strip (TimeAxisView& view)
160 RouteTimeAxisView* rt;
163 if (!session || (rt = dynamic_cast<RouteTimeAxisView*>(&view)) == 0) {
167 if (current_mixer_strip) {
169 /* might be nothing to do */
171 if (current_mixer_strip->route() == rt->route()) {
175 if (current_mixer_strip->get_parent()) {
178 delete current_mixer_strip;
179 current_mixer_strip = 0;
182 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
185 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
188 show_editor_mixer (true);
192 double current = 0.0;
193 bool currentInitialized = 0;
196 Editor::update_current_screen ()
198 if (session && session->engine().running()) {
202 frame = session->audible_frame();
204 if (_dragging_playhead) {
208 /* only update if the playhead is on screen or we are following it */
210 if (_follow_playhead && session->requested_return_frame() < 0) {
212 //playhead_cursor->canvas_item.show();
214 if (frame != last_update_frame) {
217 #undef CONTINUOUS_SCROLL
218 #ifndef CONTINUOUS_SCROLL
219 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
221 if (session->transport_speed() < 0) {
222 if (frame > (current_page_frames()/2)) {
223 center_screen (frame-(current_page_frames()/2));
225 center_screen (current_page_frames()/2);
228 center_screen (frame+(current_page_frames()/2));
232 playhead_cursor->set_position (frame);
234 #else // CONTINUOUS_SCROLL
236 /* don't do continuous scroll till the new position is in the rightmost quarter of the
240 if (session->transport_speed()) {
241 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
242 if (target <= 0.0) target = 0.0;
243 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
244 target = (target * 0.15) + (current * 0.85);
248 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
250 horizontal_adjustment.set_value ( current );
253 playhead_cursor->set_position (frame);
255 #endif // CONTINUOUS_SCROLL
261 if (frame != last_update_frame) {
262 playhead_cursor->set_position (frame);
267 last_update_frame = frame;
268 if (current_mixer_strip) {
269 current_mixer_strip->fast_update ();
276 Editor::current_mixer_strip_removed ()
278 if (current_mixer_strip) {
279 /* it is being deleted */
280 current_mixer_strip = 0;
285 Editor::current_mixer_strip_hidden ()
287 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
289 AudioTimeAxisView* tmp;
291 if ((tmp = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
292 if (tmp->route() == current_mixer_strip->route()) {
293 (*i)->set_selected (false);
299 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
301 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
302 tact->set_active (false);
307 Editor::session_going_away ()
311 for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
317 cut_buffer->clear ();
319 clicked_regionview = 0;
320 clicked_axisview = 0;
321 clicked_routeview = 0;
322 clicked_crossfadeview = 0;
323 entered_regionview = 0;
325 last_update_frame = 0;
327 last_canvas_frame = 0;
329 playhead_cursor->canvas_item.hide ();
331 /* hide all tracks */
333 hide_all_tracks (false);
335 /* rip everything out of the list displays */
337 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
338 route_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
339 named_selection_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
340 edit_group_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
342 region_list_model->clear ();
343 route_display_model->clear ();
344 named_selection_model->clear ();
345 group_model->clear ();
347 region_list_display.set_model (region_list_model);
348 route_list_display.set_model (route_display_model);
349 named_selection_display.set_model (named_selection_model);
350 edit_group_display.set_model (group_model);
352 edit_point_clock_connection_a.disconnect();
353 edit_point_clock_connection_b.disconnect();
355 edit_point_clock.set_session (0);
356 zoom_range_clock.set_session (0);
357 nudge_clock.set_session (0);
359 editor_list_button.set_active(false);
360 editor_list_button.set_sensitive(false);
362 /* clear tempo/meter rulers */
363 remove_metric_marks ();
365 clear_marker_display ();
367 if (current_bbt_points) {
368 delete current_bbt_points;
369 current_bbt_points = 0;
372 /* mixer strip will be deleted all by itself
373 when its route is deleted.
376 current_mixer_strip = 0;
378 WindowTitle title(Glib::get_application_name());
379 title += _("Editor");
381 set_title (title.get_string());
387 Editor::maybe_add_mixer_strip_width (XMLNode& node)
389 if (current_mixer_strip) {
390 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width()));