From: Ben Loftis Date: Wed, 23 Jul 2014 16:28:45 +0000 (-0500) Subject: Add some new zoom-to-selection actions, so zoom tool is less needed. X-Git-Tag: 4.0-rc1~1601^2~494 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=b22e1368877c0cc66a372f7891ff782b89a2f579;p=ardour.git Add some new zoom-to-selection actions, so zoom tool is less needed. 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. --- diff --git a/gtk2_ardour/ardour.menus.in b/gtk2_ardour/ardour.menus.in index 3eac103a8a..bdf8bbcf33 100644 --- a/gtk2_ardour/ardour.menus.in +++ b/gtk2_ardour/ardour.menus.in @@ -356,6 +356,8 @@ + + diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index f0e375114d..534ce86342 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -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))); } } diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 00fe0e04ea..d3d240611a 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -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 (); diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc index d977d27b86..01e9fd15f6 100644 --- a/gtk2_ardour/editor_actions.cc +++ b/gtk2_ardour/editor_actions.cc @@ -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)); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 88a76983bb..edf0570ec7 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -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); } }