mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 16:40:07 +02:00
Patch by Maarten Baert for compatibility with project files from previous versions of Audacity, by re-scaling on load. Opening newer project files in older builds works but the time track gets messed up. This needs to be release noted.
This commit is contained in:
parent
f39454594b
commit
8d8e008b45
@ -78,6 +78,31 @@ void Envelope::Mirror(bool mirror)
|
|||||||
mMirror = mirror;
|
mMirror = mirror;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rescale function for time tracks (could also be used for other tracks though).
|
||||||
|
/// This is used to load old time track project files where the envelope used a 0 to 1
|
||||||
|
/// range instead of storing the actual time track values. This function will change the range of the envelope
|
||||||
|
/// and rescale all envelope points accordingly (unlike SetRange, which clamps the envelope points to the new range).
|
||||||
|
/// @minValue - the new minimum value
|
||||||
|
/// @maxValue - the new maximum value
|
||||||
|
void Envelope::Rescale(double minValue, double maxValue)
|
||||||
|
{
|
||||||
|
double oldMinValue = mMinValue;
|
||||||
|
double oldMaxValue = mMaxValue;
|
||||||
|
mMinValue = minValue;
|
||||||
|
mMaxValue = maxValue;
|
||||||
|
|
||||||
|
// rescale the default value
|
||||||
|
double factor = (mDefaultValue - oldMinValue) / (oldMaxValue - oldMinValue);
|
||||||
|
mDefaultValue = ClampValue(mMinValue + (mMaxValue - mMinValue) * factor);
|
||||||
|
|
||||||
|
// rescale all points
|
||||||
|
for( unsigned int i = 0; i < mEnv.Count(); i++ ) {
|
||||||
|
factor = (mEnv[i]->GetVal() - oldMinValue) / (oldMaxValue - oldMinValue);
|
||||||
|
mEnv[i]->SetVal(mMinValue + (mMaxValue - mMinValue) * factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Flatten removes all points from the envelope to
|
/// Flatten removes all points from the envelope to
|
||||||
/// make it horizontal at a chosen y-value.
|
/// make it horizontal at a chosen y-value.
|
||||||
/// @value - the y-value for the flat envelope.
|
/// @value - the y-value for the flat envelope.
|
||||||
|
@ -94,6 +94,7 @@ class Envelope : public XMLTagHandler {
|
|||||||
bool GetInterpolateDB() { return mDB; }
|
bool GetInterpolateDB() { return mDB; }
|
||||||
void SetInterpolateDB(bool db) { mDB = db; }
|
void SetInterpolateDB(bool db) { mDB = db; }
|
||||||
void Mirror(bool mirror);
|
void Mirror(bool mirror);
|
||||||
|
void Rescale(double minValue, double maxValue);
|
||||||
|
|
||||||
void Flatten(double value);
|
void Flatten(double value);
|
||||||
int GetDragPoint(void) {return mDragPoint;}
|
int GetDragPoint(void) {return mDragPoint;}
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
#include "Internat.h"
|
#include "Internat.h"
|
||||||
#include "Resample.h"
|
#include "Resample.h"
|
||||||
|
|
||||||
|
//TODO-MB: are these sensible values?
|
||||||
|
#define TIMETRACK_MIN 0.1
|
||||||
|
#define TIMETRACK_MAX 10.0
|
||||||
|
|
||||||
TimeTrack *TrackFactory::NewTimeTrack()
|
TimeTrack *TrackFactory::NewTimeTrack()
|
||||||
{
|
{
|
||||||
return new TimeTrack(mDirManager);
|
return new TimeTrack(mDirManager);
|
||||||
@ -43,7 +47,7 @@ TimeTrack::TimeTrack(DirManager *projDirManager):
|
|||||||
mEnvelope->Flatten(1.0);
|
mEnvelope->Flatten(1.0);
|
||||||
mEnvelope->Mirror(false);
|
mEnvelope->Mirror(false);
|
||||||
mEnvelope->SetOffset(0);
|
mEnvelope->SetOffset(0);
|
||||||
mEnvelope->SetRange(0.1, 10.0); //TODO-MB: are these sensible values?
|
mEnvelope->SetRange(TIMETRACK_MIN, TIMETRACK_MAX);
|
||||||
|
|
||||||
SetDefaultName(_("Time Track"));
|
SetDefaultName(_("Time Track"));
|
||||||
SetName(GetDefaultName());
|
SetName(GetDefaultName());
|
||||||
@ -158,7 +162,7 @@ bool TimeTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
else if (!wxStrcmp(attr, wxT("rangeupper")))
|
else if (!wxStrcmp(attr, wxT("rangeupper")))
|
||||||
{
|
{
|
||||||
mRangeUpper = Internat::CompatibleToDouble(value);
|
mRangeUpper = Internat::CompatibleToDouble(value);
|
||||||
mRescaleXMLValues = false; //TODO-MB: figure out how to rescale after loading
|
mRescaleXMLValues = false;
|
||||||
}
|
}
|
||||||
else if (!wxStrcmp(attr, wxT("displaylog")) &&
|
else if (!wxStrcmp(attr, wxT("displaylog")) &&
|
||||||
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
|
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
|
||||||
@ -174,12 +178,24 @@ bool TimeTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // while
|
} // while
|
||||||
|
if(mRescaleXMLValues)
|
||||||
|
mEnvelope->SetRange(0.0, 1.0); // this will be restored to the actual range later
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimeTrack::HandleXMLEndTag(const wxChar *tag)
|
||||||
|
{
|
||||||
|
if(mRescaleXMLValues)
|
||||||
|
{
|
||||||
|
mRescaleXMLValues = false;
|
||||||
|
mEnvelope->Rescale(mRangeLower, mRangeUpper);
|
||||||
|
mEnvelope->SetRange(TIMETRACK_MIN, TIMETRACK_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XMLTagHandler *TimeTrack::HandleXMLChild(const wxChar *tag)
|
XMLTagHandler *TimeTrack::HandleXMLChild(const wxChar *tag)
|
||||||
{
|
{
|
||||||
if (!wxStrcmp(tag, wxT("envelope")))
|
if (!wxStrcmp(tag, wxT("envelope")))
|
||||||
|
@ -54,6 +54,7 @@ class TimeTrack: public Track {
|
|||||||
// XMLTagHandler callback methods for loading and saving
|
// XMLTagHandler callback methods for loading and saving
|
||||||
|
|
||||||
virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs);
|
virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs);
|
||||||
|
virtual void HandleXMLEndTag(const wxChar *tag);
|
||||||
virtual XMLTagHandler *HandleXMLChild(const wxChar *tag);
|
virtual XMLTagHandler *HandleXMLChild(const wxChar *tag);
|
||||||
virtual void WriteXML(XMLWriter &xmlFile);
|
virtual void WriteXML(XMLWriter &xmlFile);
|
||||||
|
|
||||||
@ -101,9 +102,6 @@ class TimeTrack: public Track {
|
|||||||
|
|
||||||
// Get/Set the speed-warping range, as percentage of original speed (e.g. 90%-110%)
|
// Get/Set the speed-warping range, as percentage of original speed (e.g. 90%-110%)
|
||||||
|
|
||||||
//TODO-MB: What's a sensible minimum value? Also, TrackPanel already forces a much
|
|
||||||
// higher minimum value (13%), so what's the point of adding another one here?
|
|
||||||
// Besides, Envelope should probably handle this, not TimeTrack (or TrackPanel).
|
|
||||||
double GetRangeLower() const { return mRangeLower; }
|
double GetRangeLower() const { return mRangeLower; }
|
||||||
double GetRangeUpper() const { return mRangeUpper; }
|
double GetRangeUpper() const { return mRangeUpper; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user