13
0

fix rounding error in the min:sec ruler

When zoomed in to the millisecond level, the framerate was being divided
by 1000 as an integer to generate a ruler tick interval, which doesn't
work so well at things like 44100 or 88200.  Instead, just count this
value in milliseconds, dividing by 1000 when we are done.

This was purely a display issue - the grid was in the correct place.
This commit is contained in:
Devin J. Pohly 2014-05-14 01:40:30 -04:00 committed by Paul Davis
parent db48bee3c7
commit e7b3020294

View File

@ -1854,13 +1854,13 @@ sample_to_clock_parts ( framepos_t sample,
long millisecs;
left = sample;
hrs = left / (sample_rate * 60 * 60);
left -= hrs * sample_rate * 60 * 60;
mins = left / (sample_rate * 60);
left -= mins * sample_rate * 60;
secs = left / sample_rate;
left -= secs * sample_rate;
millisecs = left * 1000 / sample_rate;
hrs = left / (sample_rate * 60 * 60 * 1000);
left -= hrs * sample_rate * 60 * 60 * 1000;
mins = left / (sample_rate * 60 * 1000);
left -= mins * sample_rate * 60 * 1000;
secs = left / (sample_rate * 1000);
left -= secs * sample_rate * 1000;
millisecs = left / sample_rate;
*millisecs_p = millisecs;
*secs_p = secs;
@ -1880,7 +1880,7 @@ Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
return;
}
fr = _session->frame_rate();
fr = _session->frame_rate() * 1000;
/* to prevent 'flashing' */
if (lower > (spacer = (framepos_t)(128 * Editor::get_current_zoom ()))) {
@ -1889,7 +1889,7 @@ Editor::set_minsec_ruler_scale (framepos_t lower, framepos_t upper)
lower = 0;
}
upper += spacer;
framecnt_t const range = upper - lower;
framecnt_t const range = (upper - lower) * 1000;
if (range < (fr / 50)) {
minsec_mark_interval = fr / 1000; /* show 1/1000 seconds */
@ -1989,7 +1989,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*
}
*marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * minsec_nmarks);
pos = ((((framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
pos = (((1000 * (framepos_t) floor(lower)) + (minsec_mark_interval/2))/minsec_mark_interval) * minsec_mark_interval;
switch (minsec_ruler_scale) {
case minsec_show_seconds:
for (n = 0; n < minsec_nmarks; pos += minsec_mark_interval, ++n) {
@ -2006,7 +2006,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*
(*marks)[n].style = GtkCustomRulerMarkMicro;
}
(*marks)[n].label = g_strdup (buf);
(*marks)[n].position = pos;
(*marks)[n].position = pos/1000.0;
}
break;
case minsec_show_minutes:
@ -2024,7 +2024,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*
(*marks)[n].style = GtkCustomRulerMarkMicro;
}
(*marks)[n].label = g_strdup (buf);
(*marks)[n].position = pos;
(*marks)[n].position = pos/1000.0;
}
break;
case minsec_show_hours:
@ -2038,7 +2038,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*
(*marks)[n].style = GtkCustomRulerMarkMicro;
}
(*marks)[n].label = g_strdup (buf);
(*marks)[n].position = pos;
(*marks)[n].position = pos/1000.0;
}
break;
case minsec_show_frames:
@ -2056,7 +2056,7 @@ Editor::metric_get_minsec (GtkCustomRulerMark **marks, gdouble lower, gdouble /*
(*marks)[n].style = GtkCustomRulerMarkMicro;
}
(*marks)[n].label = g_strdup (buf);
(*marks)[n].position = pos;
(*marks)[n].position = pos/1000.0;
}
break;
}