Remove extend-range-to-{start,end}-of-region and replace with move-range-{start,end...
authorCarl Hetherington <carl@carlh.net>
Sun, 17 Apr 2011 13:55:41 +0000 (13:55 +0000)
committerCarl Hetherington <carl@carlh.net>
Sun, 17 Apr 2011 13:55:41 +0000 (13:55 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@9360 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour.menus.in
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/mnemonic-us.bindings.in
gtk2_ardour/selection.cc
gtk2_ardour/selection.h

index 7e6c16a50e88e99651b0fb9b32aff35b9bb55814..29aaf167578842fcd42aba3e668a4b94438514aa 100644 (file)
                   <menuitem action='select-all-in-loop-range'/>
                   <separator/>
                    <menuitem action='select-range-between-cursors'/>
-                   <menuitem action='extend-range-to-start-of-region'/>
-                   <menuitem action='extend-range-to-end-of-region'/>
+                   <menuitem action='move-range-start-to-previous-region-boundary'/>
+                   <menuitem action='move-range-start-to-next-region-boundary'/>
+                   <menuitem action='move-range-end-to-previous-region-boundary'/>
+                   <menuitem action='move-range-end-to-next-region-boundary'/>
                    <menuitem action='start-range'/>
                    <menuitem action='finish-range'/>
                    <menuitem action='finish-add-range'/>
index 91a391cc1c44cfff7bdb8c96b4a5be5177c22dc0..f0719676a27756f1bb15357f66f4e367a77179d3 100644 (file)
@@ -1803,12 +1803,36 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (SeparatorElem());
        edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
 
-       if (!selection->regions.empty()) {
-               edit_items.push_back (SeparatorElem());
-               edit_items.push_back (MenuElem (_("Extend Range to End of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_end_of_region), false)));
-               edit_items.push_back (MenuElem (_("Extend Range to Start of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_start_of_region), false)));
-       }
+       edit_items.push_back (SeparatorElem());
 
+       edit_items.push_back (
+               MenuElem (
+                       _("Move Range Start to Previous Region Boundary"),
+                       sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, false)
+                       )
+               );
+
+       edit_items.push_back (
+               MenuElem (
+                       _("Move Range Start to Next Region Boundary"),
+                       sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, true)
+                       )
+               );
+       
+       edit_items.push_back (
+               MenuElem (
+                       _("Move Range End to Previous Region Boundary"),
+                       sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, false)
+                       )
+               );
+
+       edit_items.push_back (
+               MenuElem (
+                       _("Move Range End to Next Region Boundary"),
+                       sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, true)
+                       )
+               );
+       
        edit_items.push_back (SeparatorElem());
        edit_items.push_back (MenuElem (_("Convert to Region In-Place"), mem_fun(*this, &Editor::separate_region_from_selection)));
        edit_items.push_back (MenuElem (_("Convert to Region in Region List"), sigc::mem_fun(*this, &Editor::new_region_from_selection)));
index 6ac03194535ddad15ff499f0ddc8991cf21240e9..80f3f6182adf5aa331910520d92fdef4f67e7fb4 100644 (file)
@@ -1286,9 +1286,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool have_pending_keyboard_selection;
        framepos_t pending_keyboard_selection_start;
 
-       boost::shared_ptr<ARDOUR::Region> select_region_for_operation (int dir, TimeAxisView **tv);
-       void extend_selection_to_end_of_region (bool next);
-       void extend_selection_to_start_of_region (bool previous);
+       void move_range_selection_start_or_end_to_region_boundary (bool, bool);
 
        Editing::SnapType _snap_type;
        Editing::SnapMode _snap_mode;
index 7f3d6db148d531fac7525f6b1465129c4eae2f38..e557fe79997de77fe517c6893219171f80446500 100644 (file)
@@ -315,9 +315,34 @@ Editor::register_actions ()
        reg_sens (editor_actions, "finish-range", _("Finish Range"), sigc::bind (sigc::mem_fun(*this, &Editor::keyboard_selection_finish), false));
        reg_sens (editor_actions, "finish-add-range", _("Finish Add Range"), sigc::bind (sigc::mem_fun(*this, &Editor::keyboard_selection_finish), true));
 
-       reg_sens (editor_actions, "extend-range-to-end-of-region", _("Extend Range to End of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_end_of_region), false));
-       reg_sens (editor_actions, "extend-range-to-start-of-region", _("Extend Range to Start of Region"), sigc::bind (sigc::mem_fun(*this, &Editor::extend_selection_to_start_of_region), false));
-
+       reg_sens (
+               editor_actions,
+               "move-range-start-to-previous-region-boundary",
+               _("Move Range Start to Previous Region Boundary"),
+               sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, false)
+               );
+       
+       reg_sens (
+               editor_actions,
+               "move-range-start-to-next-region-boundary",
+               _("Move Range Start to Next Region Boundary"),
+               sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, true)
+               );
+       
+       reg_sens (
+               editor_actions,
+               "move-range-end-to-previous-region-boundary",
+               _("Move Range End to Previous Region Boundary"),
+               sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, false)
+               );
+       
+       reg_sens (
+               editor_actions,
+               "move-range-end-to-next-region-boundary",
+               _("Move Range End to Next Region Boundary"),
+               sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, true)
+               );
+       
        toggle_reg_sens (editor_actions, "toggle-follow-playhead", _("Follow Playhead"), (sigc::mem_fun(*this, &Editor::toggle_follow_playhead)));
        act = reg_sens (editor_actions, "remove-last-capture", _("Remove Last Capture"), (sigc::mem_fun(*this, &Editor::remove_last_capture)));
 
index a1bb3c0c9967e3e5fcbe9e6c09091096cdc53583..288802a5a727eecd9fba5cc1804e0613053182bc 100644 (file)
@@ -204,92 +204,50 @@ Editor::split_regions_at (framepos_t where, RegionSelection& regions)
        }
 }
 
-boost::shared_ptr<Region>
-Editor::select_region_for_operation (int /*dir*/, TimeAxisView **tv)
+/** Move one extreme of the current range selection.  If more than one range is selected,
+ *  the start of the earliest range or the end of the latest range is moved.
+ *
+ *  @param move_end true to move the end of the current range selection, false to move
+ *  the start.
+ *  @param next true to move the extreme to the next region boundary, false to move to
+ *  the previous.
+ */
+void
+Editor::move_range_selection_start_or_end_to_region_boundary (bool move_end, bool next)
 {
-       RegionView* rv;
-       boost::shared_ptr<Region> region;
-       framepos_t start = 0;
-
-       if (selection->time.start () == selection->time.end_frame ()) {
-
-               /* no current selection-> is there a selected regionview? */
-
-               if (selection->regions.empty()) {
-                       return region;
-               }
-
+       if (selection->time.start() == selection->time.end_frame()) {
+               return;
        }
 
-       if (!selection->regions.empty()) {
-
-               rv = *(selection->regions.begin());
-               (*tv) = &rv->get_time_axis_view();
-               region = rv->region();
+       framepos_t start = selection->time.start ();
+       framepos_t end = selection->time.end_frame ();
 
-       } else if (!selection->tracks.empty()) {
-
-               (*tv) = selection->tracks.front();
-
-               RouteTimeAxisView* rtv;
-
-               if ((rtv = dynamic_cast<RouteTimeAxisView*> (*tv)) != 0) {
-                       boost::shared_ptr<Playlist> pl;
+       /* the position of the thing we may move */
+       framepos_t pos = move_end ? end : start;
+       int dir = next ? 1 : -1;
 
-                       if ((pl = rtv->playlist()) == 0) {
-                               return region;
-                       }
-
-                       region = pl->top_region_at (start);
-               }
+       /* so we don't find the current region again */
+       if (dir > 0 || pos > 0) {
+               pos += dir;
        }
 
-       return region;
-}
-
-void
-Editor::extend_selection_to_end_of_region (bool next)
-{
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t start;
-
-       if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) {
+       framepos_t const target = get_region_boundary (pos, dir, false, false);
+       if (target < 0) {
                return;
        }
 
-       if (region && selection->time.start () == selection->time.end_frame ()) {
-               start = region->position();
+       if (move_end) {
+               end = target;
        } else {
-               start = selection->time.start ();
+               start = target;
        }
 
-       begin_reversible_command (_("extend selection"));
-       selection->set (start, region->position() + region->length());
-       commit_reversible_command ();
-}
-
-void
-Editor::extend_selection_to_start_of_region (bool previous)
-{
-       TimeAxisView *tv;
-       boost::shared_ptr<Region> region;
-       framepos_t end;
-
-       if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) {
+       if (end < start) {
                return;
        }
-
-       if (region && selection->time.start () == selection->time.end_frame ()) {
-               end = region->position() + region->length();
-       } else {
-               end = selection->time.end_frame ();
-       }
-
-       /* Try to leave the selection with the same route if possible */
-
-       begin_reversible_command (_("extend selection"));
-       selection->set (region->position(), end);
+       
+       begin_reversible_command (_("alter selection"));
+       selection->set_preserving_all_ranges (start, end);
        commit_reversible_command ();
 }
 
index f5d38e68a85a5888dc8ce93c4c746ac3b2905a6c..99bc729120b23e2eecaa8f71528a7217ea2f5fc7 100644 (file)
@@ -97,8 +97,10 @@ This mode provides many different operations on both regions and control points,
 @eep|Editor/cycle-edit-point|grave|next EP w/o marker
 @eep|Editor/cycle-edit-point-with-marker|<@PRIMARY@>asciicircum|next EP w/marker
 
-@aep|Editor/extend-range-to-end-of-region|rightanglebracket|align sync point relative
-@-group|Editor/extend-range-to-start-of-region|leftanglebracket|some text
+@aep|Editor/move-range-start-to-previous-region-boundary|less|move range start to previous region boundary
+@aep|Editor/move-range-start-to-next-region-boundary|<@PRIMARY@>less|move range start to next region boundary
+@aep|Editor/move-range-end-to-previous-region-boundary|greater|move range end to next region boundary
+@aep|Editor/move-range-end-to-next-region-boundary|<@PRIMARY@>greater|move range end to previous region boundary
 
 @trans|Transport/ToggleRoll|space|toggle roll
 @epp|Editor/play-edit-range|<@SECONDARY@>space|play edit range
index d0b2cab5c7749a67ff763e3574886bf56c54aff8..f734d07375a9927ba1a3defd366c30151d29dc46 100644 (file)
@@ -769,6 +769,34 @@ Selection::set (framepos_t start, framepos_t end)
        return time.front().id;
 }
 
+/** Set the start and end of the range selection.  If more than one range
+ *  is currently selected, the start of the earliest range and the end of the
+ *  latest range are set.  If no range is currently selected, this method
+ *  selects a single range from start to end.
+ *
+ *  @param start New start time.
+ *  @param end New end time.
+ */
+void
+Selection::set_preserving_all_ranges (framepos_t start, framepos_t end)
+{
+       if ((start == 0 && end == 0) || (end < start)) {
+               return;
+       }
+
+       if (time.empty ()) {
+               time.push_back (AudioRange (start, end, next_time_id++));
+       } else {
+               time.sort (AudioRangeComparator ());
+               time.front().start = start;
+               time.back().end = end;
+       }
+
+       time.consolidate ();
+       
+       TimeChanged ();
+}
+
 void
 Selection::set (boost::shared_ptr<Evoral::ControlList> ac)
 {
index c9d3e9b7590a774ee7c8b7d3dacb520e6283118e..ac3c9330f0599890b3622746ecabe62e7e1b69c0 100644 (file)
@@ -122,6 +122,7 @@ class Selection : public sigc::trackable, public PBD::ScopedConnectionList
        void set (MidiRegionView*);
        void set (std::vector<RegionView*>&);
        long set (framepos_t, framepos_t);
+       void set_preserving_all_ranges (framepos_t, framepos_t);
        void set (boost::shared_ptr<Evoral::ControlList>);
        void set (boost::shared_ptr<ARDOUR::Playlist>);
        void set (const std::list<boost::shared_ptr<ARDOUR::Playlist> >&);