Add some new zoom-to-selection actions, so zoom tool is less needed.
authorBen Loftis <ben@harrisonconsoles.com>
Wed, 23 Jul 2014 16:28:45 +0000 (11:28 -0500)
committerBen Loftis <ben@harrisonconsoles.com>
Wed, 23 Jul 2014 16:31:06 +0000 (11:31 -0500)
Reverse order of items in the zoom menus to match Ardour.
Consolidate the extra zoom math into a function;  this fixes a problem in zoom-to-session.

gtk2_ardour/ardour.menus.in
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_ops.cc

index 3eac103a8a9e4086a413499f7fc15a0eaea9748a..bdf8bbcf338a7d7f3d9b7ab3903f218570dd2944 100644 (file)
         <menuitem action='zoom-to-session'/>
         <menuitem action='zoom-to-region'/>
         <menuitem action='zoom-to-region-both-axes'/>
+        <menuitem action='zoom-to-range'/>
+        <menuitem action='zoom-to-range-both-axes'/>
         <menuitem action='toggle-zoom'/>
         <menuitem action='expand-tracks'/>
         <menuitem action='shrink-tracks'/>
index f0e375114dc934cb4a37e2b2097cc2dd60cbc5ca..534ce863424138419f2bdd9c9e9fc77d8ed8d193 100644 (file)
@@ -1757,6 +1757,9 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::play_selection)));
        edit_items.push_back (MenuElem (_("Loop Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), true)));
 
+       edit_items.push_back (SeparatorElem());
+       edit_items.push_back (MenuElem (_("Zoom to Range"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), false)));
+
        edit_items.push_back (SeparatorElem());
        edit_items.push_back (MenuElem (_("Spectral Analysis"), sigc::mem_fun(*this, &Editor::analyze_range_selection)));
 
@@ -3494,26 +3497,28 @@ Editor::build_track_count_menu ()
                visible_tracks_selector.AddMenuElem (MenuElem (_("Selected"), sigc::mem_fun(*this, &Editor::fit_selected_tracks)));
                visible_tracks_selector.AddMenuElem (MenuElem (_("All"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 0)));
        } else {
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit current tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 0)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 48 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 48)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 32 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 32)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 24 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 24)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 16 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 16)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 8 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 8)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 4 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 4)));
-               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 2 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 2)));
                visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 1 track"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 1)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 2 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 2)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 4 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 4)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 8 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 8)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 16 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 16)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 24 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 24)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 32 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 32)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit 48 tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 48)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit All tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 0)));
+               visible_tracks_selector.AddMenuElem (MenuElem (_("Fit Selected tracks"), sigc::mem_fun(*this, &Editor::fit_selected_tracks)));
 
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to Session"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), -1)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 24 hours"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 24 * 60 * 60 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 8 hours"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 8 * 60 * 60 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 hour"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 60 * 60 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 10 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 60 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 60 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 10 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 1 * 1000)));
-               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 100 ms"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 100)));
                zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 10 ms"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 100 ms"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 100)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 1 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 10 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 60 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 10 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 60 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 1 hour"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 60 * 60 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 8 hours"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 8 * 60 * 60 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to 24 hours"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 24 * 60 * 60 * 1000)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to Session"), sigc::mem_fun(*this, &Editor::temporal_zoom_session)));
+               zoom_preset_selector.AddMenuElem (MenuElem (_("Zoom to Range/Region Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), false)));
        }
 }
 
index 00fe0e04ea607344d8d9e6ea565c75dab9e407a4..d3d240611a4418198b3ed9b52fe8dfc7e7d13b2c 100644 (file)
@@ -1216,7 +1216,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void play_location (ARDOUR::Location&);
        void loop_location (ARDOUR::Location&);
 
-       void temporal_zoom_selection ();
+       void calc_extra_zoom_edges(framepos_t &start, framepos_t &end);
+       void temporal_zoom_selection (bool both_axes = false);
        void temporal_zoom_region (bool both_axes);
        void zoom_to_region (bool both_axes);
        void temporal_zoom_session ();
index d977d27b860079dedc20e5d359b5da13ff239bc1..01e9fd15f69e92468f6764c9e1bd5420960a0b7f 100644 (file)
@@ -263,6 +263,8 @@ Editor::register_actions ()
        reg_sens (editor_actions, "zoom-to-session", _("Zoom to Session"), sigc::mem_fun(*this, &Editor::temporal_zoom_session));
        reg_sens (editor_actions, "zoom-to-region", _("Zoom to Region"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_to_region), false));
        reg_sens (editor_actions, "zoom-to-region-both-axes", _("Zoom to Region (Width and Height)"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_to_region), true));
+       reg_sens (editor_actions, "zoom-to-range", _("Zoom to Range"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), false));
+       reg_sens (editor_actions, "zoom-to-range-both-axes", _("Zoom to Range (Width and Height)"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), true));
        reg_sens (editor_actions, "toggle-zoom", _("Toggle Zoom State"), sigc::mem_fun(*this, &Editor::swap_visual_state));
 
        reg_sens (editor_actions, "expand-tracks", _("Expand Track Height"), sigc::bind (sigc::mem_fun (*this, &Editor::tav_zoom_step), false));
index 88a76983bb7001fe09a2e6a2d23caa3ebe43c8ff..edf0570ec78239f34f40f9a5a8b508983f41c8d2 100644 (file)
@@ -1628,6 +1628,38 @@ Editor::temporal_zoom (framecnt_t fpp)
        reposition_and_zoom (leftmost_after_zoom, nfpp);
 }
 
+void
+Editor::calc_extra_zoom_edges(framepos_t &start, framepos_t &end)
+{
+       /* this func helps make sure we leave a little space
+          at each end of the editor so that the zoom doesn't fit the region
+          precisely to the screen.
+       */
+
+       GdkScreen* screen = gdk_screen_get_default ();
+       gint pixwidth = gdk_screen_get_width (screen);
+       gint mmwidth = gdk_screen_get_width_mm (screen);
+       double pix_per_mm = (double) pixwidth/ (double) mmwidth;
+       double one_centimeter_in_pixels = pix_per_mm * 10.0;
+
+       framepos_t range = end - start;
+       double new_fpp = (double) range / (double) _visible_canvas_width;
+       framepos_t extra_samples = (framepos_t) floor (one_centimeter_in_pixels * new_fpp);
+
+       if (start > extra_samples) {
+               start -= extra_samples;
+       } else {
+               start = 0;
+       }
+
+       if (max_framepos - extra_samples > end) {
+               end += extra_samples;
+       } else {
+               end = max_framepos;
+       }
+}
+
+
 void
 Editor::temporal_zoom_region (bool both_axes)
 {
@@ -1654,36 +1686,11 @@ Editor::temporal_zoom_region (bool both_axes)
                tracks.insert (&((*i)->get_time_axis_view()));
        }
 
-       /* now comes an "interesting" hack ... make sure we leave a little space
-          at each end of the editor so that the zoom doesn't fit the region
-          precisely to the screen.
-       */
-
-       GdkScreen* screen = gdk_screen_get_default ();
-       gint pixwidth = gdk_screen_get_width (screen);
-       gint mmwidth = gdk_screen_get_width_mm (screen);
-       double pix_per_mm = (double) pixwidth/ (double) mmwidth;
-       double one_centimeter_in_pixels = pix_per_mm * 10.0;
-
        if ((start == 0 && end == 0) || end < start) {
                return;
        }
 
-       framepos_t range = end - start;
-       double new_fpp = (double) range / (double) _visible_canvas_width;
-       framepos_t extra_samples = (framepos_t) floor (one_centimeter_in_pixels * new_fpp);
-
-       if (start > extra_samples) {
-               start -= extra_samples;
-       } else {
-               start = 0;
-       }
-
-       if (max_framepos - extra_samples > end) {
-               end += extra_samples;
-       } else {
-               end = max_framepos;
-       }
+       calc_extra_zoom_edges(start, end);
 
        /* if we're zooming on both axes we need to save track heights etc.
         */
@@ -1726,18 +1733,28 @@ Editor::zoom_to_region (bool both_axes)
 }
 
 void
-Editor::temporal_zoom_selection ()
+Editor::temporal_zoom_selection (bool both_axes)
 {
        if (!selection) return;
 
-       if (selection->time.empty()) {
-               return;
+       //if a range is selected, zoom to that
+       if (!selection->time.empty()) {
+
+               framepos_t start = selection->time.start();
+               framepos_t end = selection->time.end_frame();
+
+               calc_extra_zoom_edges(start, end);
+
+               temporal_zoom_by_frame (start, end);
+
+               if (both_axes)
+                       fit_selected_tracks();
+
+       } else {
+               temporal_zoom_region(both_axes);
        }
 
-       framepos_t start = selection->time[clicked_selection].start;
-       framepos_t end = selection->time[clicked_selection].end;
 
-       temporal_zoom_by_frame (start, end);
 }
 
 void
@@ -1746,13 +1763,16 @@ Editor::temporal_zoom_session ()
        ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_session)
 
        if (_session) {
-               framecnt_t const l = _session->current_end_frame() - _session->current_start_frame();
-               double s = _session->current_start_frame() - l * 0.01;
-               if (s < 0) {
-                       s = 0;
+               framecnt_t start = _session->current_start_frame();
+               framecnt_t end = _session->current_end_frame();
+
+               if ((start == 0 && end == 0) || end < start) {
+                       return;
                }
-               framecnt_t const e = _session->current_end_frame() + l * 0.01;
-               temporal_zoom_by_frame (framecnt_t (s), e);
+
+               calc_extra_zoom_edges(start, end);
+
+               temporal_zoom_by_frame (start, end);
        }
 }