mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-17 16:50:26 +02:00
Fix BUG 459: TimeText Control values skip a whole second. This was due to rounding error, rounding not being propagated, so 4.9995 showed as 4.0000.
This commit is contained in:
parent
a5c5af0d5a
commit
1f17e0bb45
@ -1327,12 +1327,13 @@ void TimeTextCtrl::ValueToControls()
|
|||||||
|
|
||||||
void TimeConverter::ValueToControls( double RawTime )
|
void TimeConverter::ValueToControls( double RawTime )
|
||||||
{
|
{
|
||||||
|
//RawTime = 4.9995f; Only for testing!
|
||||||
RawTime = (double)((sampleCount)floor(RawTime * mSampleRate + 0.5)) / mSampleRate; // put on a sample
|
RawTime = (double)((sampleCount)floor(RawTime * mSampleRate + 0.5)) / mSampleRate; // put on a sample
|
||||||
double theValue = RawTime * mScalingFactor + .000001; // what's this .000001 for?
|
double theValue = RawTime * mScalingFactor + .000001; // what's this .000001 for?
|
||||||
int t_int;
|
int t_int;
|
||||||
bool round = true;
|
bool round = true;
|
||||||
// If we have a fractional field further on then we will be using t_frac, and will round there.
|
// We round on the last field. If we have a fractional field we round using it.
|
||||||
// Otherwise round t_int to the nearest value
|
// Otherwise we round to nearest integer.
|
||||||
for(unsigned int i=0; i<mFields.GetCount(); i++) {
|
for(unsigned int i=0; i<mFields.GetCount(); i++) {
|
||||||
if (mFields[i].frac)
|
if (mFields[i].frac)
|
||||||
round = false;
|
round = false;
|
||||||
@ -1340,7 +1341,11 @@ void TimeConverter::ValueToControls( double RawTime )
|
|||||||
if(round)
|
if(round)
|
||||||
t_int = int(theValue + 0.5);
|
t_int = int(theValue + 0.5);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
wxASSERT( mFields[mFields.GetCount()-1].frac );
|
||||||
|
theValue += 0.5f / mFields[mFields.GetCount()-1].base;
|
||||||
t_int = int(theValue);
|
t_int = int(theValue);
|
||||||
|
}
|
||||||
double t_frac = (theValue - t_int);
|
double t_frac = (theValue - t_int);
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int tenMins;
|
int tenMins;
|
||||||
@ -1380,16 +1385,24 @@ void TimeConverter::ValueToControls( double RawTime )
|
|||||||
|
|
||||||
for(i=0; i<mFields.GetCount(); i++) {
|
for(i=0; i<mFields.GetCount(); i++) {
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
if (mFields[i].frac) {
|
if (mFields[i].frac) {
|
||||||
value = (int)(t_frac * mFields[i].base + 0.5); // +0.5 as rounding required
|
// JKC: This old code looks bogus to me.
|
||||||
if (mFields[i].range > 0)
|
// The rounding is not propogating to earlier fields in the frac case.
|
||||||
value = value % mFields[i].range;
|
//value = (int)(t_frac * mFields[i].base + 0.5); // +0.5 as rounding required
|
||||||
|
// I did the rounding earlier.
|
||||||
|
value = (int)(t_frac * mFields[i].base);
|
||||||
|
// JKC: TODO: Find out what the range is supposed to do.
|
||||||
|
// It looks bogus too.
|
||||||
|
//if (mFields[i].range > 0)
|
||||||
|
// value = value % mFields[i].range;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
value = (t_int / mFields[i].base);
|
value = (t_int / mFields[i].base);
|
||||||
if (mFields[i].range > 0)
|
if (mFields[i].range > 0)
|
||||||
value = value % mFields[i].range;
|
value = value % mFields[i].range;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString field = wxString::Format(mFields[i].formatStr, value);
|
wxString field = wxString::Format(mFields[i].formatStr, value);
|
||||||
mValueString += field;
|
mValueString += field;
|
||||||
mValueString += mFields[i].label;
|
mValueString += mFields[i].label;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user