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.
This commit is contained in:
Ben Loftis 2014-07-23 11:28:45 -05:00 committed by Paul Davis
parent db3e315513
commit 7d0bfeadd8
5 changed files with 86 additions and 56 deletions

View file

@ -355,6 +355,8 @@
<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'/>

View file

@ -1827,6 +1827,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)));
@ -3541,26 +3544,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)));
}
}

View file

@ -1224,7 +1224,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 ();

View 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));

View file

@ -1629,6 +1629,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)
{
@ -1655,36 +1687,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.
*/
@ -1727,18 +1734,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
@ -1747,13 +1764,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);
}
}