Audacity 3.2.0
|
Piecewise linear or piecewise exponential function from double to double. More...
#include <Envelope.h>
Public Member Functions | |
Envelope (bool exponential, double minValue, double maxValue, double defaultValue) | |
Envelope (const Envelope &orig) | |
Envelope (const Envelope &orig, double t0, double t1) | |
virtual | ~Envelope () |
bool | IsTrivial () const |
bool | ConsistencyCheck () |
double | GetOffset () const |
double | GetTrackLen () const |
bool | GetExponential () const |
void | SetExponential (bool db) |
void | Flatten (double value) |
double | GetMinValue () const |
double | GetMaxValue () const |
void | SetRange (double minValue, double maxValue) |
double | ClampValue (double value) |
bool | HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override |
XMLTagHandler * | HandleXMLChild (const std::string_view &tag) override |
void | WriteXML (XMLWriter &xmlFile) const |
void | CollapseRegion (double t0, double t1, double sampleDur) noexcept |
void | PasteEnvelope (double t0, const Envelope *e, double sampleDur) |
void | InsertSpace (double t0, double tlen) |
void | SetOffset (double newOffset) |
void | SetTrackLen (double trackLen, double sampleDur=0.0) |
void | RescaleValues (double minValue, double maxValue) |
void | RescaleTimes (double newLength) |
void | RescaleTimesBy (double ratio) |
double | GetValue (double t, double sampleDur=0) const |
Get envelope value at time t. More... | |
void | GetValues (double *buffer, int len, double t0, double tstep) const |
Get many envelope points at once. More... | |
void | Cap (double sampleDur) |
double | Average (double t0, double t1) const |
double | AverageOfInverse (double t0, double t1) const |
double | Integral (double t0, double t1) const |
double | IntegralOfInverse (double t0, double t1) const |
double | SolveIntegralOfInverse (double t0, double area) const |
void | Clear () |
int | InsertOrReplace (double when, double value) |
Add a point at a particular absolute time coordinate. More... | |
int | Reassign (double when, double value) |
Move a point at when to value. More... | |
void | Delete (int point) |
DELETE a point by its position in array. More... | |
void | Insert (int point, const EnvPoint &p) noexcept |
insert a point More... | |
void | Insert (double when, double value) |
size_t | GetNumberOfPoints () const |
Return number of points. More... | |
const EnvPoint & | operator[] (int index) const |
Accessor for points. More... | |
double | GetDefaultValue () const |
size_t | GetVersion () const |
void | GetPoints (double *bufferWhen, double *bufferValue, int bufferLen) const |
Returns the sets of when and value pairs. More... | |
int | GetDragPoint () const |
void | SetDragPoint (int dragPoint) |
void | SetDragPointValid (bool valid) |
bool | GetDragPointValid () const |
void | MoveDragPoint (double newWhen, double value) |
void | ClearDragPoint () |
Public Member Functions inherited from XMLTagHandler | |
XMLTagHandler () | |
virtual | ~XMLTagHandler () |
virtual bool | HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0 |
virtual void | HandleXMLEndTag (const std::string_view &WXUNUSED(tag)) |
virtual void | HandleXMLContent (const std::string_view &WXUNUSED(content)) |
virtual XMLTagHandler * | HandleXMLChild (const std::string_view &tag)=0 |
void | ReadXMLEndTag (const char *tag) |
void | ReadXMLContent (const char *s, int len) |
XMLTagHandler * | ReadXMLChild (const char *tag) |
Private Member Functions | |
std::pair< int, int > | ExpandRegion (double t0, double tlen, double *pLeftVal, double *pRightVal) |
void | RemoveUnneededPoints (size_t startAt, bool rightward, bool testNeighbors=true) noexcept |
double | GetValueRelative (double t, bool leftLimit=false) const noexcept |
void | GetValuesRelative (double *buffer, int len, double t0, double tstep, bool leftLimit=false) const noexcept |
int | NumberOfPointsAfter (double t) const |
double | NextPointAfter (double t) const |
int | InsertOrReplaceRelative (double when, double value) noexcept |
Add a control point to the envelope. More... | |
std::pair< int, int > | EqualRange (double when, double sampleDur) const noexcept |
void | AddPointAtEnd (double t, double val) |
void | CopyRange (const Envelope &orig, size_t begin, size_t end) |
void | BinarySearchForTime (int &Lo, int &Hi, double t) const noexcept |
void | BinarySearchForTime_LeftLimit (int &Lo, int &Hi, double t) const noexcept |
double | GetInterpolationStartValueAtPoint (int iPoint) const noexcept |
Private Attributes | |
EnvArray | mEnv |
double | mOffset { 0.0 } |
The time at which the envelope starts, i.e. the start offset. More... | |
double | mTrackLen { 0.0 } |
The length of the envelope, which is the same as the length of the underlying track (normally) More... | |
double | mTrackEpsilon { 1.0 / 200000.0 } |
The shortest distance apart that points on an envelope can be before being considered the same point. More... | |
bool | mDB |
double | mMinValue |
double | mMaxValue |
double | mDefaultValue |
bool | mDragPointValid { false } |
int | mDragPoint { -1 } |
size_t | mVersion { 0 } |
int | mSearchGuess { -2 } |
Piecewise linear or piecewise exponential function from double to double.
This class manages an envelope - i.e. a function that the user can edit by dragging control points around. The envelope is most commonly used to control the amplitude of a waveform, but it is also used to shape the Equalization curve, and in TimeTrack to determine a time warp.
Definition at line 72 of file Envelope.h.
Envelope::Envelope | ( | bool | exponential, |
double | minValue, | ||
double | maxValue, | ||
double | defaultValue | ||
) |
Definition at line 44 of file Envelope.cpp.
Envelope::Envelope | ( | const Envelope & | orig | ) |
Definition at line 275 of file Envelope.cpp.
References CopyRange(), GetNumberOfPoints(), mOffset, and mTrackLen.
Envelope::Envelope | ( | const Envelope & | orig, |
double | t0, | ||
double | t1 | ||
) |
Definition at line 261 of file Envelope.cpp.
References CopyRange(), EqualRange(), mOffset, and mTrackLen.
|
virtual |
Definition at line 52 of file Envelope.cpp.
|
private |
Definition at line 242 of file Envelope.cpp.
References mEnv, and mVersion.
Referenced by CopyRange(), and SetTrackLen().
double Envelope::Average | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1125 of file Envelope.cpp.
References GetValue(), and Integral().
double Envelope::AverageOfInverse | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1133 of file Envelope.cpp.
References GetValue(), and IntegralOfInverse().
Referenced by anonymous_namespace{MixerSource.cpp}::ComputeWarpFactor().
|
privatenoexcept |
Lo | returns last index at or before this time, maybe -1 |
Hi | returns first index after this time, maybe past the end |
Definition at line 900 of file Envelope.cpp.
Referenced by Integral(), IntegralOfInverse(), NextPointAfter(), NumberOfPointsAfter(), and SolveIntegralOfInverse().
|
privatenoexcept |
Lo | returns last index before this time, maybe -1 |
Hi | returns first index at or after this time, maybe past the end |
Definition at line 947 of file Envelope.cpp.
void Envelope::Cap | ( | double | sampleDur | ) |
Definition at line 752 of file Envelope.cpp.
References EqualRange(), GetValueRelative(), InsertOrReplaceRelative(), and mTrackLen.
|
inline |
Definition at line 102 of file Envelope.h.
References min().
Referenced by Flatten(), RescaleValues(), SetRange(), EnvPoint::SetVal(), and EnvelopeEditor::ValueOfPixel().
|
inline |
Definition at line 166 of file Envelope.h.
void Envelope::ClearDragPoint | ( | ) |
Definition at line 221 of file Envelope.cpp.
References Delete(), mDragPoint, and mDragPointValid.
Referenced by EnvelopeEditor::HandleMouseButtonUp().
|
noexcept |
Definition at line 396 of file Envelope.cpp.
References details::begin(), details::end(), and min().
Referenced by WaveClip::ClearAndAddCutLine(), and WaveClip::ClearSequenceFinisher::~ClearSequenceFinisher().
bool Envelope::ConsistencyCheck | ( | ) |
Definition at line 61 of file Envelope.cpp.
References mEnv.
Referenced by PasteEnvelope().
|
private |
Definition at line 286 of file Envelope.cpp.
References AddPointAtEnd(), details::begin(), details::end(), EnvPoint::GetT(), EnvPoint::GetVal(), GetValue(), mEnv, mOffset, and mTrackLen.
Referenced by Envelope().
void Envelope::Delete | ( | int | point | ) |
DELETE a point by its position in array.
Definition at line 374 of file Envelope.cpp.
References mEnv, and mVersion.
Referenced by ClearDragPoint(), and BoundedEnvelope::Envelope().
|
privatenoexcept |
Definition at line 801 of file Envelope.cpp.
References details::begin(), details::end(), and EnvPoint::GetT().
Referenced by Cap(), Envelope(), ExpandRegion(), PasteEnvelope(), and SetTrackLen().
|
private |
Definition at line 640 of file Envelope.cpp.
References EqualRange(), GetValueRelative(), Insert(), mEnv, and mTrackLen.
Referenced by InsertSpace(), and PasteEnvelope().
void Envelope::Flatten | ( | double | value | ) |
Flatten removes all points from the envelope to make it horizontal at a chosen y-value. @value - the y-value for the flat envelope.
Definition at line 140 of file Envelope.cpp.
References ClampValue(), mDefaultValue, mEnv, and mVersion.
Referenced by EqualizationBandSliders::GraphicEQ(), EqualizationCurvesList::setCurve(), and TimeTrack::testMe().
double Envelope::GetDefaultValue | ( | ) | const |
Definition at line 728 of file Envelope.cpp.
References mDefaultValue.
|
inline |
Definition at line 214 of file Envelope.h.
Referenced by EnvelopeEditor::DrawPoints(), and EnvelopeEditor::MouseEvent().
|
inline |
Definition at line 219 of file Envelope.h.
Referenced by EnvelopeEditor::HandleDragging().
|
inline |
Definition at line 93 of file Envelope.h.
Referenced by CommonChannelView::GetEnvelopeValues().
|
privatenoexcept |
GetInterpolationStartValueAtPoint() is used to select either the envelope value or its log depending on whether we are doing linear or log interpolation.
iPoint | index in env array to look at. |
Definition at line 972 of file Envelope.cpp.
|
inline |
Definition at line 99 of file Envelope.h.
|
inline |
Definition at line 98 of file Envelope.h.
size_t Envelope::GetNumberOfPoints | ( | ) | const |
Return number of points.
Definition at line 723 of file Envelope.cpp.
References mEnv.
Referenced by EnvelopeEditor::DrawPoints(), Envelope(), EqualizationCurvesList::EnvelopeUpdated(), EqualizationBandSliders::EnvLinToLog(), EqualizationBandSliders::EnvLogToLin(), and EnvelopeEditor::HandleMouseButtonDown().
|
inline |
Definition at line 90 of file Envelope.h.
Referenced by EnvelopeEditor::DrawPoints(), EnvelopeEditor::HandleMouseButtonDown(), and EnvelopeEditor::MoveDragPoint().
void Envelope::GetPoints | ( | double * | bufferWhen, |
double * | bufferValue, | ||
int | bufferLen | ||
) | const |
Returns the sets of when and value pairs.
Definition at line 738 of file Envelope.cpp.
Referenced by EqualizationCurvesList::EnvelopeUpdated().
|
inline |
Definition at line 91 of file Envelope.h.
double Envelope::GetValue | ( | double | t, |
double | sampleDur = 0 |
||
) | const |
Get envelope value at time t.
Definition at line 880 of file Envelope.cpp.
References GetValues().
Referenced by Average(), AverageOfInverse(), EqualizationFilter::CalcFilter(), CopyRange(), anonymous_namespace{WaveformView.cpp}::DrawIndividualSamples(), EqualizationBandSliders::ErrMin(), CommonChannelView::GetEnvelopeValues(), EnvelopeEditor::HandleMouseButtonDown(), EnvelopeHandle::HitEnvelope(), and PasteEnvelope().
|
privatenoexcept |
Definition at line 889 of file Envelope.cpp.
Referenced by Cap(), ExpandRegion(), PasteEnvelope(), and SetTrackLen().
void Envelope::GetValues | ( | double * | buffer, |
int | len, | ||
double | t0, | ||
double | tstep | ||
) | const |
Get many envelope points at once.
This is much faster than calling GetValue() multiple times if you need more than one value in a row.
Definition at line 981 of file Envelope.cpp.
References GetValuesRelative(), and mOffset.
Referenced by GetValue(), and WaveBitmapCache::LookupHelper::PerformLookup().
|
privatenoexcept |
Definition at line 989 of file Envelope.cpp.
Referenced by GetValues().
size_t Envelope::GetVersion | ( | ) | const |
Definition at line 733 of file Envelope.cpp.
References mVersion.
Referenced by WaveBitmapCache::CheckCache(), and WaveBitmapCache::SetPaintParameters().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 346 of file Envelope.cpp.
References mEnv.
Referenced by AUPImportFileHandle::HandleControlPoint().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 321 of file Envelope.cpp.
References mEnv.
void Envelope::Insert | ( | double | when, |
double | value | ||
) |
|
noexcept |
insert a point
Definition at line 381 of file Envelope.cpp.
Referenced by ExpandRegion(), and EqualizationBandSliders::GraphicEQ().
|
inline |
Add a point at a particular absolute time coordinate.
Definition at line 169 of file Envelope.h.
Referenced by EnvelopeEditor::HandleMouseButtonDown(), and TimeTrack::testMe().
|
privatenoexcept |
Add a control point to the envelope.
when | the time in seconds when the envelope point should be created. |
value | the envelope value to use at the given point. |
Definition at line 767 of file Envelope.cpp.
Referenced by Cap().
void Envelope::InsertSpace | ( | double | t0, |
double | tlen | ||
) |
Definition at line 691 of file Envelope.cpp.
References ExpandRegion(), mOffset, and RemoveUnneededPoints().
double Envelope::Integral | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1224 of file Envelope.cpp.
References BinarySearchForTime(), Integral(), IntegrateInterpolated(), InterpolatePoints(), mDB, mDefaultValue, mEnv, and mOffset.
Referenced by Average(), Integral(), and TimeTrack::testMe().
double Envelope::IntegralOfInverse | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1287 of file Envelope.cpp.
References BinarySearchForTime(), IntegralOfInverse(), IntegrateInverseInterpolated(), InterpolatePoints(), mDB, mDefaultValue, mEnv, and mOffset.
Referenced by AverageOfInverse(), GeneratedUpdater::ComputeWarpedLength(), PlaybackSchedule::ComputeWarpedLength(), IntegralOfInverse(), and TimeTrack::testMe().
bool Envelope::IsTrivial | ( | ) | const |
Definition at line 56 of file Envelope.cpp.
References mDefaultValue, and mEnv.
void Envelope::MoveDragPoint | ( | double | newWhen, |
double | value | ||
) |
Definition at line 193 of file Envelope.cpp.
References mDragPoint, mDragPointValid, mEnv, min(), mTrackLen, mVersion, SetDragPointValid(), EnvPoint::SetT(), and EnvPoint::SetVal().
Referenced by EnvelopeEditor::MoveDragPoint().
|
private |
Definition at line 1115 of file Envelope.cpp.
References BinarySearchForTime(), and mEnv.
|
private |
Definition at line 1106 of file Envelope.cpp.
References BinarySearchForTime(), and mEnv.
|
inline |
void Envelope::PasteEnvelope | ( | double | t0, |
const Envelope * | e, | ||
double | sampleDur | ||
) |
Definition at line 486 of file Envelope.cpp.
References details::begin(), ConsistencyCheck(), details::end(), EqualRange(), ExpandRegion(), GetValue(), GetValueRelative(), mDefaultValue, mEnv, min(), mOffset, mTrackLen, mVersion, and RemoveUnneededPoints().
int Envelope::Reassign | ( | double | when, |
double | value | ||
) |
Move a point at when to value.
Returns 0 if point moved, -1 if not found.
Definition at line 700 of file Envelope.cpp.
References mEnv, mOffset, and mVersion.
Referenced by EqualizationBandSliders::GraphicEQ().
|
privatenoexcept |
Definition at line 571 of file Envelope.cpp.
References EnvPoint::GetT(), EnvPoint::GetVal(), and VALUE_TOLERANCE.
Referenced by InsertSpace(), and PasteEnvelope().
void Envelope::RescaleTimes | ( | double | newLength | ) |
Definition at line 855 of file Envelope.cpp.
void Envelope::RescaleTimesBy | ( | double | ratio | ) |
Definition at line 871 of file Envelope.cpp.
References mEnv, and mTrackLen.
Referenced by DEFINE_ATTACHED_VIRTUAL_OVERRIDE().
void Envelope::RescaleValues | ( | double | minValue, |
double | maxValue | ||
) |
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
Definition at line 117 of file Envelope.cpp.
References ClampValue(), mDefaultValue, mEnv, mMaxValue, mMinValue, and mVersion.
void Envelope::SetDragPoint | ( | int | dragPoint | ) |
Definition at line 148 of file Envelope.cpp.
References mDragPoint, mDragPointValid, mEnv, and min().
Referenced by EnvelopeEditor::HandleMouseButtonDown().
void Envelope::SetDragPointValid | ( | bool | valid | ) |
Definition at line 154 of file Envelope.cpp.
References mDefaultValue, mDragPoint, mDragPointValid, mEnv, mVersion, and size.
Referenced by EnvelopeEditor::HandleDragging(), and MoveDragPoint().
|
inline |
Definition at line 94 of file Envelope.h.
void Envelope::SetOffset | ( | double | newOffset | ) |
void Envelope::SetRange | ( | double | minValue, |
double | maxValue | ||
) |
Definition at line 230 of file Envelope.cpp.
References ClampValue(), mDefaultValue, mEnv, mMaxValue, mMinValue, and mVersion.
void Envelope::SetTrackLen | ( | double | trackLen, |
double | sampleDur = 0.0 |
||
) |
Definition at line 832 of file Envelope.cpp.
References AddPointAtEnd(), EqualRange(), GetValueRelative(), mEnv, min(), mTrackLen, and mVersion.
Referenced by EqualizationFilter::EqualizationFilter(), and EqualizationBandSliders::GraphicEQ().
double Envelope::SolveIntegralOfInverse | ( | double | t0, |
double | area | ||
) | const |
Definition at line 1350 of file Envelope.cpp.
References BinarySearchForTime(), IntegrateInverseInterpolated(), InterpolatePoints(), mDB, mDefaultValue, mEnv, mOffset, and SolveIntegrateInverseInterpolated().
Referenced by PlaybackSchedule::SolveWarpedLength().
void Envelope::WriteXML | ( | XMLWriter & | xmlFile | ) | const |
Definition at line 355 of file Envelope.cpp.
References EnvPoint::GetT(), EnvPoint::GetVal(), and wxT().
|
private |
Definition at line 249 of file Envelope.h.
Referenced by Integral(), IntegralOfInverse(), and SolveIntegralOfInverse().
|
private |
Definition at line 251 of file Envelope.h.
Referenced by Flatten(), GetDefaultValue(), Integral(), IntegralOfInverse(), IsTrivial(), PasteEnvelope(), RescaleValues(), SetDragPointValid(), SetRange(), and SolveIntegralOfInverse().
|
private |
Definition at line 255 of file Envelope.h.
Referenced by ClearDragPoint(), BoundedEnvelope::Envelope(), MoveDragPoint(), SetDragPoint(), and SetDragPointValid().
|
private |
Definition at line 254 of file Envelope.h.
Referenced by ClearDragPoint(), MoveDragPoint(), SetDragPoint(), and SetDragPointValid().
|
private |
Definition at line 236 of file Envelope.h.
Referenced by AddPointAtEnd(), ConsistencyCheck(), CopyRange(), Delete(), ExpandRegion(), Flatten(), GetNumberOfPoints(), GetPoints(), HandleXMLChild(), HandleXMLTag(), Insert(), Integral(), IntegralOfInverse(), IsTrivial(), MoveDragPoint(), NextPointAfter(), NumberOfPointsAfter(), PasteEnvelope(), Reassign(), RescaleTimes(), RescaleTimesBy(), RescaleValues(), SetDragPoint(), SetDragPointValid(), SetRange(), SetTrackLen(), and SolveIntegralOfInverse().
|
private |
Definition at line 250 of file Envelope.h.
Referenced by RescaleValues(), and SetRange().
|
private |
Definition at line 250 of file Envelope.h.
Referenced by RescaleValues(), and SetRange().
|
private |
The time at which the envelope starts, i.e. the start offset.
Definition at line 239 of file Envelope.h.
Referenced by CopyRange(), Envelope(), GetPoints(), GetValues(), InsertSpace(), Integral(), IntegralOfInverse(), PasteEnvelope(), Reassign(), SetOffset(), and SolveIntegralOfInverse().
|
mutableprivate |
Definition at line 258 of file Envelope.h.
|
private |
The shortest distance apart that points on an envelope can be before being considered the same point.
Definition at line 248 of file Envelope.h.
|
private |
The length of the envelope, which is the same as the length of the underlying track (normally)
Definition at line 242 of file Envelope.h.
Referenced by Cap(), CopyRange(), Envelope(), ExpandRegion(), MoveDragPoint(), PasteEnvelope(), RescaleTimes(), RescaleTimesBy(), and SetTrackLen().
|
private |
Definition at line 256 of file Envelope.h.
Referenced by AddPointAtEnd(), Delete(), Flatten(), GetVersion(), Insert(), MoveDragPoint(), PasteEnvelope(), Reassign(), RescaleTimes(), RescaleValues(), SetDragPointValid(), SetRange(), and SetTrackLen().