do not pass a non-zero offset to plugins AFTER the first call to connect_and_run...
[ardour.git] / gtk2_ardour / editor_mixer.cc
index 58a2d55a0c399ef14c75dd08ef9eb2d86b7fe28c..de0a27c687cbc59c2bd9ae088c29b3aa81aa45fb 100644 (file)
@@ -61,6 +61,7 @@ Editor::show_editor_mixer (bool yn)
        show_editor_mixer_when_tracks_arrive = false;
 
        if (!session) {
+               show_editor_mixer_when_tracks_arrive = yn;
                return;
        }
 
@@ -97,33 +98,31 @@ Editor::show_editor_mixer (bool yn)
                }
 
                if (r) {
+                       bool created;
+
                        if (current_mixer_strip == 0) {
-                               
-                               current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
-                                                                     *session,
-                                                                     false);
-                               current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));                                          
+                               create_editor_mixer ();
+                               created = true;
+                       } else {
+                               created = false;
                        }
-                       
+
                        current_mixer_strip->set_route (r);
+
+                       if (created) {
+                               current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
+                       }
                }
                
                if (current_mixer_strip->get_parent() == 0) {
-                       current_mixer_strip->set_embedded (true);
-                       current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
-                       current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
-                       current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
-
                        global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
                        global_hpacker.reorder_child (*current_mixer_strip, 0);
-
                        current_mixer_strip->show_all ();
                }
 
        } else {
 
                if (current_mixer_strip) {
-                       editor_mixer_strip_width = current_mixer_strip->get_width ();
                        if (current_mixer_strip->get_parent() != 0) {
                                global_hpacker.remove (*current_mixer_strip);
                        }
@@ -132,51 +131,83 @@ Editor::show_editor_mixer (bool yn)
 
 #ifdef GTKOSX
        /* XXX gtk problem here */
+       ensure_all_elements_drawn();
+#endif
+}
+
+#ifdef GTKOSX
+void
+Editor::ensure_all_elements_drawn ()
+{
+       controls_layout.queue_draw ();
        ruler_label_event_box.queue_draw ();
        time_button_event_box.queue_draw ();
-       controls_layout.queue_draw ();
-#endif
 }
+#endif
+
+void
+Editor::create_editor_mixer ()
+{
+       current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
+                                             *session,
+                                             false);
+       current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
+       current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
+#ifdef GTKOSX
+       current_mixer_strip->WidthChanged.connect (mem_fun(*this, &Editor::ensure_all_elements_drawn));
+#endif
+       current_mixer_strip->set_embedded (true);
+}      
 
 void
 Editor::set_selected_mixer_strip (TimeAxisView& view)
 {
        AudioTimeAxisView* at;
        bool show = false;
+       bool created;
 
        if (!session || (at = dynamic_cast<AudioTimeAxisView*>(&view)) == 0) {
                return;
        }
-       
-       if (current_mixer_strip) {
 
-               /* might be nothing to do */
-
-               if (current_mixer_strip->route() == at->route()) {
+       Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
+       if (act) {
+               Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
+               if (!tact || !tact->get_active()) {
+                       /* not showing mixer strip presently */
                        return;
                }
+       }
 
-               if (current_mixer_strip->get_parent()) {
-                       show = true;
-               }
-
+       if (current_mixer_strip == 0) {
+               create_editor_mixer ();
+               created = true;
        } else {
-               
-               current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
-                                                     *session,
-                                                     false);
-               current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
+               created = false;
+       }
+
+       /* might be nothing to do */
+       
+       if (current_mixer_strip->route() == at->route()) {
+               return;
+       }
+       
+       if (current_mixer_strip->get_parent()) {
+               show = true;
        }
 
        current_mixer_strip->set_route (at->route());
 
+       if (created) {
+               current_mixer_strip->set_width (editor_mixer_strip_width, (void*) this);
+       }
+
        if (show) {
                show_editor_mixer (true);
        }
 }
 
 double current = 0.0;
-bool currentInitialized = 0;
 
 void
 Editor::update_current_screen ()
@@ -191,6 +222,17 @@ Editor::update_current_screen ()
                        goto almost_done;
                }
 
+#undef DEBUG_CURRENT_SCREEN
+#if DEBUG_CURRENT_SCREEN
+
+               cerr << "@ " << frame << " last " << last_update_frame << " follow " << _follow_playhead 
+                    << " ret " << session->requested_return_frame()
+                    << " left " << leftmost_frame
+                    << " right " << leftmost_frame + current_page_frames()
+                    << " speed " << session->transport_speed ()
+                    << endl;
+#endif
+
                /* only update if the playhead is on screen or we are following it */
 
                if (_follow_playhead && session->requested_return_frame() < 0) {
@@ -203,7 +245,10 @@ Editor::update_current_screen ()
 #undef CONTINUOUS_SCROLL
 #ifndef  CONTINUOUS_SCROLL
                                if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
-                                       
+
+#ifdef DEBUG_CURRENT_SCREEN
+                                       cerr << "\trecenter...\n";
+#endif                                         
                                        if (session->transport_speed() < 0) {
                                                if (frame > (current_page_frames()/2)) {
                                                        center_screen (frame-(current_page_frames()/2));
@@ -351,11 +396,15 @@ Editor::session_going_away ()
                current_bbt_points = 0;
        }
 
-       /* mixer strip will be deleted all by itself 
-          when its route is deleted.
-       */
+       /* get rid of any existing editor mixer strip */
 
-       current_mixer_strip = 0;
+       if (current_mixer_strip) {
+               if (current_mixer_strip->get_parent() != 0) {
+                       global_hpacker.remove (*current_mixer_strip);
+               }
+               delete current_mixer_strip;
+               current_mixer_strip = 0;
+       }
 
        WindowTitle title(Glib::get_application_name());
        title += _("Editor");