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::cms_deleted ()
53 current_mixer_strip = 0;
57 Editor::show_editor_mixer (bool yn)
59 show_editor_mixer_when_tracks_arrive = false;
63 if (current_mixer_strip == 0) {
65 if (selection->tracks.empty()) {
67 if (track_views.empty()) {
68 show_editor_mixer_when_tracks_arrive = true;
72 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
73 AudioTimeAxisView* atv;
75 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
77 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
81 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
88 sort_track_selection ();
90 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
91 AudioTimeAxisView* atv;
93 if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
95 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
98 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
105 if (current_mixer_strip == 0) {
110 if (current_mixer_strip->get_parent() == 0) {
111 current_mixer_strip->set_embedded (true);
112 current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
113 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
114 current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
116 global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
117 global_hpacker.reorder_child (*current_mixer_strip, 0);
119 current_mixer_strip->show_all ();
124 if (current_mixer_strip) {
125 editor_mixer_strip_width = current_mixer_strip->get_width ();
126 if (current_mixer_strip->get_parent() != 0) {
127 global_hpacker.remove (*current_mixer_strip);
134 Editor::set_selected_mixer_strip (TimeAxisView& view)
136 AudioTimeAxisView* at;
139 if (!session || (at = dynamic_cast<AudioTimeAxisView*>(&view)) == 0) {
143 if (current_mixer_strip) {
145 /* might be nothing to do */
147 if (current_mixer_strip->route() == at->route()) {
151 if (current_mixer_strip->get_parent()) {
154 delete current_mixer_strip;
155 current_mixer_strip = 0;
158 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
161 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
164 show_editor_mixer (true);
168 double current = 0.0;
169 bool currentInitialized = 0;
172 Editor::update_current_screen ()
174 if (session && session->engine().running()) {
178 frame = session->audible_frame();
180 if (_dragging_playhead) {
184 /* only update if the playhead is on screen or we are following it */
186 if (_follow_playhead && session->requested_return_frame() < 0) {
188 playhead_cursor->canvas_item.show();
190 if (frame != last_update_frame) {
193 #undef CONTINUOUS_SCROLL
194 #ifndef CONTINUOUS_SCROLL
195 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
197 if (session->transport_speed() < 0) {
198 if (frame > (current_page_frames()/2)) {
199 center_screen (frame-(current_page_frames()/2));
201 center_screen (current_page_frames()/2);
204 center_screen (frame+(current_page_frames()/2));
208 playhead_cursor->set_position (frame);
210 #else // CONTINUOUS_SCROLL
212 /* don't do continuous scroll till the new position is in the rightmost quarter of the
216 if (session->transport_speed()) {
217 double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
218 if (target <= 0.0) target = 0.0;
219 if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
220 target = (target * 0.15) + (current * 0.85);
224 //printf("frame: %d, cpf: %d, fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
226 horizontal_adjustment.set_value ( current );
229 playhead_cursor->set_position (frame);
231 #endif // CONTINUOUS_SCROLL
237 if (frame != last_update_frame) {
238 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
239 playhead_cursor->canvas_item.hide();
241 playhead_cursor->set_position (frame);
247 last_update_frame = frame;
249 if (current_mixer_strip) {
250 current_mixer_strip->fast_update ();
257 Editor::current_mixer_strip_removed ()
259 if (current_mixer_strip) {
260 /* it is being deleted */
261 current_mixer_strip = 0;
266 Editor::current_mixer_strip_hidden ()
268 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
270 AudioTimeAxisView* tmp;
272 if ((tmp = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
273 if (tmp->route() == current_mixer_strip->route()) {
274 (*i)->set_selected (false);
280 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
282 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
283 tact->set_active (false);
288 Editor::session_going_away ()
292 for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
298 cut_buffer->clear ();
300 clicked_regionview = 0;
301 clicked_trackview = 0;
302 clicked_audio_trackview = 0;
303 clicked_crossfadeview = 0;
304 entered_regionview = 0;
306 last_update_frame = 0;
308 last_canvas_frame = 0;
310 /* hide all tracks */
312 hide_all_tracks (false);
314 /* rip everything out of the list displays */
316 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
317 route_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
318 named_selection_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
319 edit_group_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
321 region_list_model->clear ();
322 route_display_model->clear ();
323 named_selection_model->clear ();
324 group_model->clear ();
326 region_list_display.set_model (region_list_model);
327 route_list_display.set_model (route_display_model);
328 named_selection_display.set_model (named_selection_model);
329 edit_group_display.set_model (group_model);
331 edit_point_clock_connection_a.disconnect();
332 edit_point_clock_connection_b.disconnect();
334 edit_point_clock.set_session (0);
335 zoom_range_clock.set_session (0);
336 nudge_clock.set_session (0);
338 /* put editor/mixer toggle button in off position and disable until a new session is loaded */
340 editor_mixer_button.set_active(false);
341 editor_mixer_button.set_sensitive(false);
342 /* clear tempo/meter rulers */
343 remove_metric_marks ();
345 clear_marker_display ();
347 if (current_bbt_points) {
348 delete current_bbt_points;
349 current_bbt_points = 0;
352 /* mixer strip will be deleted all by itself
353 when its route is deleted.
356 current_mixer_strip = 0;
358 WindowTitle title(Glib::get_application_name());
359 title += _("Editor");
361 set_title (title.get_string());
367 Editor::maybe_add_mixer_strip_width (XMLNode& node)
369 if (current_mixer_strip) {
370 node.add_property ("mixer-width", enum_2_string (current_mixer_strip->get_width()));