Unify clamping of frames-per-unit values during zoom; should help with #3514.

git-svn-id: svn://localhost/ardour2/branches/3.0@12796 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2012-06-20 14:14:27 +00:00
parent 0fba3e073c
commit 3c7f6a4a4c
3 changed files with 43 additions and 44 deletions

View File

@ -917,12 +917,9 @@ Editor::zoom_adjustment_changed ()
}
double fpu = zoom_range_clock->current_duration() / _canvas_width;
if (fpu < 1.0) {
fpu = 1.0;
zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
} else if (fpu > _session->current_end_frame() / _canvas_width) {
fpu = _session->current_end_frame() / _canvas_width;
bool clamped = clamp_frames_per_unit (fpu);
if (clamped) {
zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
}
@ -4064,6 +4061,12 @@ Editor::reset_y_origin (double y)
void
Editor::reset_zoom (double fpu)
{
clamp_frames_per_unit (fpu);
if (fpu == frames_per_unit) {
return;
}
pending_visual_change.add (VisualChange::ZoomLevel);
pending_visual_change.frames_per_unit = fpu;
ensure_visual_change_idle_handler ();
@ -4171,41 +4174,20 @@ Editor::use_visual_state (VisualState& vs)
_routes->resume_redisplay ();
}
/** This is the core function that controls the zoom level of the canvas. It is called
* whenever one or more calls are made to reset_zoom(). It executes in an idle handler.
* @param fpu New frames per unit; should already have been clamped so that it is sensible.
*/
void
Editor::set_frames_per_unit (double fpu)
{
/* this is the core function that controls the zoom level of the canvas. it is called
whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
*/
if (fpu == frames_per_unit) {
return;
}
if (fpu < 2.0) {
fpu = 2.0;
}
/* don't allow zooms that fit more than the maximum number
of frames into an 800 pixel wide space.
*/
if (max_framepos / fpu < 800.0) {
return;
}
if (tempo_lines)
if (tempo_lines) {
tempo_lines->tempo_map_changed();
}
frames_per_unit = fpu;
post_zoom ();
}
void
Editor::post_zoom ()
{
// convert fpu to frame count
/* convert fpu to frame count */
framepos_t frames = (framepos_t) floor (frames_per_unit * _canvas_width);

View File

@ -525,7 +525,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
Editing::ZoomFocus zoom_focus;
void set_frames_per_unit (double);
void post_zoom ();
bool clamp_frames_per_unit (double &) const;
Editing::MouseMode mouse_mode;
Editing::MouseMode pre_internal_mouse_mode;
@ -1209,7 +1209,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
void temporal_zoom_region (bool both_axes);
void zoom_to_region (bool both_axes);
void temporal_zoom_session ();
void temporal_zoom (gdouble scale);
void temporal_zoom (double scale);
void temporal_zoom_by_frame (framepos_t start, framepos_t end);
void temporal_zoom_to_frame (bool coarser, framepos_t frame);

View File

@ -1327,14 +1327,30 @@ Editor::tav_zoom_smooth (bool coarser, bool force_all)
_routes->resume_redisplay ();
}
bool
Editor::clamp_frames_per_unit (double& fpu) const
{
bool clamped = false;
if (fpu < 2.0) {
fpu = 2.0;
clamped = true;
}
if (max_framepos / fpu < 800) {
fpu = max_framepos / 800.0;
clamped = true;
}
return clamped;
}
void
Editor::temporal_zoom_step (bool coarser)
{
ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_step, coarser)
double nfpu;
nfpu = frames_per_unit;
double nfpu = frames_per_unit;
if (coarser) {
nfpu = min (9e6, nfpu * 1.61803399);
@ -1346,9 +1362,11 @@ Editor::temporal_zoom_step (bool coarser)
}
void
Editor::temporal_zoom (gdouble fpu)
Editor::temporal_zoom (double fpu)
{
if (!_session) return;
if (!_session) {
return;
}
framepos_t current_page = current_page_frames();
framepos_t current_leftmost = leftmost_frame;
@ -1362,9 +1380,8 @@ Editor::temporal_zoom (gdouble fpu)
double nfpu;
double l;
/* XXX this limit is also in ::set_frames_per_unit() */
if (frames_per_unit <= 1.0 && fpu <= frames_per_unit) {
clamp_frames_per_unit (fpu);
if (fpu == frames_per_unit) {
return;
}