Skip to content

Commit

Permalink
client: use round rather than floor in (ms)timstr.
Browse files Browse the repository at this point in the history
When converting time to a string, round to the nearest elapsed second
or millisecond, rather than rounding down.

In particular, when we jump forward by "one second" by clicking the
forward button, the time display should advance by one second.
  • Loading branch information
Benjamin Moody committed Jun 21, 2022
1 parent e899b76 commit 5ccc3d9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/js/lightwave.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function set_trace(db, record, s) {
function timstr(t) {
var ss, mm, hh, tstring;

ss = Math.floor(t/tickfreq);
ss = Math.round(t/tickfreq);
mm = Math.floor(ss/60); ss %= 60;
hh = Math.floor(mm/60); mm %= 60;
if (ss < 10) { ss = '0' + ss; }
Expand All @@ -288,15 +288,21 @@ function timstr(t) {

// Convert argument (in samples) to a string in HH:MM:SS.mmm format
function mstimstr(t) {
var mmm, tstring;
var mmm, ss, mm, hh, tstring;

mmm = Math.floor(1000*t/tickfreq) % 1000;
mmm = Math.round(1000*t/tickfreq);
ss = Math.floor(mmm/1000); mmm %= 1000;
mm = Math.floor(ss/60); ss %= 60;
hh = Math.floor(mm/60); mm %= 60;
if (mmm < 100) {
if (mmm < 10) { mmm = '.00' + mmm; }
else { mmm = '.0' + mmm; }
}
else { mmm = '.' + mmm; }
tstring = timstr(t) + mmm;
if (ss < 10) { ss = '0' + ss; }
if (mm < 10) { mm = '0' + mm; }
if (hh < 10) { hh = '0' + hh; }
tstring = hh + ':' + mm + ':' + ss + mmm;
return tstring;
}

Expand Down

0 comments on commit 5ccc3d9

Please sign in to comment.