non-primary music-locked regions follow tempo changes while dragging.
[ardour.git] / gtk2_ardour / mixer_ui.cc
index 49862c36a505564c1c308db8a582a419ed6c86ff..c42c426aeecf3d7207fbdfcdcb6ab326848805a7 100644 (file)
@@ -107,7 +107,6 @@ Mixer_UI::Mixer_UI ()
        , ignore_reorder (false)
         , _in_group_rebuild_or_clear (false)
         , _route_deletion_in_progress (false)
-       , _following_editor_selection (false)
        , _maximised (false)
        , _show_mixer_list (true)
        , myactions (X_("mixer"))
@@ -116,7 +115,7 @@ Mixer_UI::Mixer_UI ()
        load_bindings ();
        _content.set_data ("ardour-bindings", bindings);
 
-       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::sync_treeview_from_presentation_info, this), gui_context());
+       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::presentation_info_changed, this, _1), gui_context());
 
        scroller.set_can_default (true);
        // set_default (scroller);
@@ -142,6 +141,7 @@ Mixer_UI::Mixer_UI ()
        b->pack_start (*_group_tabs, PACK_SHRINK);
        b->pack_start (strip_packer);
        b->show_all ();
+       b->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
 
        scroller.add (*b);
        scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
@@ -383,12 +383,6 @@ Mixer_UI::escape ()
        select_none ();
 }
 
-void
-Mixer_UI::track_editor_selection ()
-{
-       PublicEditor::instance().get_selection().TracksChanged.connect (sigc::mem_fun (*this, &Mixer_UI::follow_editor_selection));
-}
-
 Gtk::Window*
 Mixer_UI::use_own_window (bool and_fill_it)
 {
@@ -400,7 +394,6 @@ Mixer_UI::use_own_window (bool and_fill_it)
        if (win && new_window) {
                win->set_name ("MixerWindow");
                ARDOUR_UI::instance()->setup_toplevel_window (*win, _("Mixer"), this);
-               win->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
                win->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), win));
                win->set_data ("ardour-bindings", bindings);
                update_title ();
@@ -687,6 +680,19 @@ Mixer_UI::remove_strip (MixerStrip* strip)
        }
 }
 
+void
+Mixer_UI::presentation_info_changed (PropertyChange const & what_changed)
+{
+       PropertyChange soh;
+       soh.add (Properties::selected);
+       soh.add (Properties::order);
+       soh.add (Properties::hidden);
+
+       if (what_changed.contains (soh)) {
+               sync_treeview_from_presentation_info (what_changed);
+       }
+}
+
 void
 Mixer_UI::sync_presentation_info_from_treeview ()
 {
@@ -714,6 +720,8 @@ Mixer_UI::sync_presentation_info_from_treeview ()
                order++;
        }
 
+       PresentationInfo::ChangeSuspender cs;
+
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                bool visible = (*ri)[stripable_columns.visible];
                boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
@@ -742,7 +750,7 @@ Mixer_UI::sync_presentation_info_from_treeview ()
                }
 
                if (order != stripable->presentation_info().order()) {
-                       stripable->set_presentation_order (order, false);
+                       stripable->set_presentation_order (order);
                        change = true;
                }
 
@@ -761,17 +769,24 @@ Mixer_UI::sync_presentation_info_from_treeview ()
                                change = true;
                        }
                }
+               if (change) {
+                       n = 0;
+                       for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
+                               if (sr->stripable->presentation_info().order() != n) {
+                                       sr->stripable->set_presentation_order (n);
+                               }
+                       }
+               }
        }
 
        if (change) {
                DEBUG_TRACE (DEBUG::OrderKeys, "... notify PI change from mixer GUI\n");
-               _session->notify_presentation_info_change ();
                _session->set_dirty();
        }
 }
 
 void
-Mixer_UI::sync_treeview_from_presentation_info ()
+Mixer_UI::sync_treeview_from_presentation_info (PropertyChange const & what_changed)
 {
        if (!_session || _session->deletion_in_progress()) {
                return;
@@ -822,35 +837,25 @@ Mixer_UI::sync_treeview_from_presentation_info ()
                track_model->reorder (neworder);
        }
 
-       redisplay_track_list ();
-}
-
-void
-Mixer_UI::follow_editor_selection ()
-{
-       if (_following_editor_selection) {
-               return;
-       }
+       if (what_changed.contains (Properties::selected)) {
 
-       _following_editor_selection = true;
-       _selection.block_routes_changed (true);
+               PresentationInfo::ChangeSuspender cs;
 
-       TrackSelection& s (PublicEditor::instance().get_selection().tracks);
-
-       _selection.clear_routes ();
-
-       for (TrackViewList::iterator i = s.begin(); i != s.end(); ++i) {
-               TimeAxisView* tav = dynamic_cast<TimeAxisView*> (*i);
-               if (tav) {
-                       AxisView* axis = axis_by_stripable (tav->stripable());
-                       if (axis) {
-                               _selection.add (axis);
+               for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+                       boost::shared_ptr<Stripable> stripable = (*i)->stripable();
+                       if (stripable && stripable->presentation_info().selected()) {
+                               _selection.add (*i);
+                       } else {
+                               _selection.remove (*i);
                        }
                }
+
+               if (!_selection.axes.empty()) {
+                       move_stripable_into_view ((*_selection.axes.begin())->stripable());
+               }
        }
 
-       _following_editor_selection = false;
-       _selection.block_routes_changed (false);
+       redisplay_track_list ();
 }
 
 
@@ -866,6 +871,18 @@ Mixer_UI::strip_by_route (boost::shared_ptr<Route> r) const
        return 0;
 }
 
+MixerStrip*
+Mixer_UI::strip_by_stripable (boost::shared_ptr<Stripable> s) const
+{
+       for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               if ((*i)->stripable() == s) {
+                       return (*i);
+               }
+       }
+
+       return 0;
+}
+
 AxisView*
 Mixer_UI::axis_by_stripable (boost::shared_ptr<Stripable> s) const
 {
@@ -903,8 +920,19 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
 
                                tmp.push_back (strip);
 
+                               OrderingKeys sorted;
+                               const size_t cmp_max = strips.size ();
                                for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
-                                       if ((*i) == strip) {
+                                       sorted.push_back (OrderKeys (-1, (*i)->stripable(), cmp_max));
+                               }
+                               SortByNewDisplayOrder cmp;
+                               sort (sorted.begin(), sorted.end(), cmp);
+
+                               for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr) {
+                                       MixerStrip* ms = strip_by_stripable (sr->stripable);
+                                       assert (ms);
+
+                                       if (ms == strip) {
                                                /* hit clicked strip, start accumulating till we hit the first
                                                   selected strip
                                                */
@@ -914,7 +942,7 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                } else {
                                                        accumulate = true;
                                                }
-                                       } else if (_selection.selected (*i)) {
+                                       } else if (_selection.selected (ms)) {
                                                /* hit selected strip. if currently accumulating others,
                                                   we're done. if not accumulating others, start doing so.
                                                */
@@ -927,7 +955,7 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                }
                                        } else {
                                                if (accumulate) {
-                                                       tmp.push_back (*i);
+                                                       tmp.push_back (ms);
                                                }
                                        }
                                }
@@ -1354,11 +1382,13 @@ Mixer_UI::redisplay_track_list ()
                return;
        }
 
-       boost::shared_ptr<VCA> sv = spilled_vca.lock ();
-
-       if (sv) {
-               spill_redisplay (sv);
-               return;
+       boost::shared_ptr<Stripable> ss = spilled_strip.lock ();
+       if (ss) {
+               boost::shared_ptr<VCA> sv = boost::dynamic_pointer_cast<VCA> (ss);
+               if (sv) {
+                       spill_redisplay (sv);
+                       return;
+               }
        }
 
        TreeModel::Children rows = track_model->children();
@@ -1503,8 +1533,7 @@ Mixer_UI::initial_track_display ()
                add_stripables (sl);
        }
 
-       redisplay_track_list ();
-       sync_treeview_from_presentation_info ();
+       sync_treeview_from_presentation_info (Properties::order);
 }
 
 void
@@ -1556,11 +1585,13 @@ Mixer_UI::move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
 #endif
        bool found = false;
        int x0 = 0;
+       Gtk::Allocation alloc;
        for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
                if ((*i)->route() == s) {
                        int y;
                        found = true;
                        (*i)->translate_coordinates (strip_packer, 0, 0, x0, y);
+                       alloc = (*i)->get_allocation ();
                        break;
                }
        }
@@ -1569,7 +1600,13 @@ Mixer_UI::move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
        }
 
        Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
-       scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), x0 - 1.0)));
+
+       if (x0 < adj->get_value()) {
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x0)));
+       } else if (x0 + alloc.get_width() >= adj->get_value() + adj->get_page_size()) {
+               int x1 = x0 + alloc.get_width() - adj->get_page_size();
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x1)));
+       }
 }
 
 void
@@ -2830,13 +2867,13 @@ Mixer_UI::do_vca_unassign (boost::shared_ptr<VCA> vca)
 }
 
 void
-Mixer_UI::show_vca_slaves (boost::shared_ptr<VCA> vca)
+Mixer_UI::show_spill (boost::shared_ptr<Stripable> s)
 {
-       boost::shared_ptr<VCA> v = spilled_vca.lock();
-       if (v != vca) {
-               spilled_vca = vca;
-               show_vca_change (vca); /* EMIT SIGNAL */
-               if (vca) {
+       boost::shared_ptr<Stripable> ss = spilled_strip.lock();
+       if (ss != s) {
+               spilled_strip = s;
+               show_spill_change (s); /* EMIT SIGNAL */
+               if (s) {
                        _group_tabs->hide ();
                } else {
                        _group_tabs->show ();
@@ -2846,9 +2883,9 @@ Mixer_UI::show_vca_slaves (boost::shared_ptr<VCA> vca)
 }
 
 bool
-Mixer_UI::showing_vca_slaves_for (boost::shared_ptr<VCA> vca) const
+Mixer_UI::showing_spill_for (boost::shared_ptr<Stripable> s) const
 {
-       return vca == spilled_vca.lock();
+       return s == spilled_strip.lock();
 }
 
 void
@@ -3050,26 +3087,22 @@ void
 Mixer_UI::vca_assign (boost::shared_ptr<VCA> vca)
 {
        set_axis_targets_for_operation ();
-#if 0
        BOOST_FOREACH(AxisView* r, _axis_targets) {
                MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
                if (ms) {
                        ms->vca_assign (vca);
                }
        }
-#endif
 }
 
 void
 Mixer_UI::vca_unassign (boost::shared_ptr<VCA> vca)
 {
        set_axis_targets_for_operation ();
-#if 0
        BOOST_FOREACH(AxisView* r, _axis_targets) {
                MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
                if (ms) {
                        ms->vca_unassign (vca);
                }
        }
-#endif
 }