![]() |
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) | |
void | Initialize (int numPoints) |
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) |
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) |
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 | print () const |
void | testMe () |
bool | IsDirty () 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) |
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... | |
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 () |
![]() | |
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) |
double | GetValueRelative (double t, bool leftLimit=false) const |
void | GetValuesRelative (double *buffer, int len, double t0, double tstep, bool leftLimit=false) const |
int | NumberOfPointsAfter (double t) const |
double | NextPointAfter (double t) const |
int | InsertOrReplaceRelative (double when, double value) |
Add a control point to the envelope. More... | |
std::pair< int, int > | EqualRange (double when, double sampleDur) const |
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 |
void | BinarySearchForTime_LeftLimit (int &Lo, int &Hi, double t) const |
double | GetInterpolationStartValueAtPoint (int iPoint) const |
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 } |
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 43 of file Envelope.cpp.
Envelope::Envelope | ( | const Envelope & | orig | ) |
Definition at line 262 of file Envelope.cpp.
References CopyRange(), GetNumberOfPoints(), mOffset, and mTrackLen.
Envelope::Envelope | ( | const Envelope & | orig, |
double | t0, | ||
double | t1 | ||
) |
Definition at line 248 of file Envelope.cpp.
References CopyRange(), EqualRange(), mOffset, and mTrackLen.
|
virtual |
Definition at line 51 of file Envelope.cpp.
|
private |
Definition at line 231 of file Envelope.cpp.
References mEnv.
Referenced by CopyRange(), and SetTrackLen().
double Envelope::Average | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1072 of file Envelope.cpp.
References GetValue(), and Integral().
double Envelope::AverageOfInverse | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1080 of file Envelope.cpp.
References GetValue(), and IntegralOfInverse().
Referenced by anonymous_namespace{MixerSource.cpp}::ComputeWarpFactor().
|
private |
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 848 of file Envelope.cpp.
References mEnv, and mSearchGuess.
Referenced by GetValuesRelative(), Integral(), IntegralOfInverse(), NextPointAfter(), NumberOfPointsAfter(), and SolveIntegralOfInverse().
|
private |
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 895 of file Envelope.cpp.
References mEnv, and mSearchGuess.
Referenced by GetValuesRelative().
void Envelope::Cap | ( | double | sampleDur | ) |
Definition at line 713 of file Envelope.cpp.
References EqualRange(), GetValueRelative(), InsertOrReplaceRelative(), and mTrackLen.
|
inline |
Definition at line 104 of file Envelope.h.
References min().
Referenced by SetEnvelopeCommand::ApplyInner(), Flatten(), RescaleValues(), SetRange(), EnvPoint::SetVal(), and EnvelopeEditor::ValueOfPixel().
|
inline |
Definition at line 172 of file Envelope.h.
Referenced by SetEnvelopeCommand::ApplyInner().
void Envelope::ClearDragPoint | ( | ) |
Definition at line 212 of file Envelope.cpp.
References Delete(), mDragPoint, and mDragPointValid.
Referenced by EnvelopeEditor::HandleMouseButtonUp().
void Envelope::CollapseRegion | ( | double | t0, |
double | t1, | ||
double | sampleDur | ||
) |
Definition at line 377 of file Envelope.cpp.
References PackedArray::begin(), PackedArray::end(), EqualRange(), GetValueRelative(), InsertOrReplaceRelative(), mEnv, min(), mOffset, mTrackLen, and RemoveUnneededPoints().
Referenced by WaveClip::ClearAndAddCutLine(), and WaveClip::ClearSequence().
bool Envelope::ConsistencyCheck | ( | ) |
Definition at line 60 of file Envelope.cpp.
References mEnv.
Referenced by PasteEnvelope().
|
private |
Definition at line 273 of file Envelope.cpp.
References AddPointAtEnd(), PackedArray::begin(), PackedArray::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 361 of file Envelope.cpp.
References mEnv.
Referenced by ClearDragPoint(), BoundedEnvelope::Envelope(), and RemoveUnneededPoints().
|
private |
Definition at line 762 of file Envelope.cpp.
References PackedArray::begin(), PackedArray::end(), EnvPoint::GetT(), and mEnv.
Referenced by Cap(), CollapseRegion(), Envelope(), ExpandRegion(), InsertOrReplaceRelative(), PasteEnvelope(), and SetTrackLen().
|
private |
Definition at line 614 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 137 of file Envelope.cpp.
References ClampValue(), mDefaultValue, and mEnv.
Referenced by EqualizationBandSliders::GraphicEQ(), TimeTrack::testMe(), and testMe().
|
inline |
Definition at line 215 of file Envelope.h.
Referenced by EnvelopeEditor::DrawPoints(), and EnvelopeEditor::MouseEvent().
|
inline |
Definition at line 220 of file Envelope.h.
Referenced by EnvelopeEditor::HandleDragging().
|
inline |
Definition at line 95 of file Envelope.h.
Referenced by CommonTrackView::GetEnvelopeValues().
|
private |
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 919 of file Envelope.cpp.
Referenced by GetValuesRelative().
|
inline |
Definition at line 101 of file Envelope.h.
|
inline |
Definition at line 100 of file Envelope.h.
size_t Envelope::GetNumberOfPoints | ( | ) | const |
Return number of points.
Definition at line 694 of file Envelope.cpp.
References mEnv.
Referenced by EnvelopeEditor::DrawPoints(), Envelope(), EqualizationCurvesList::EnvelopeUpdated(), EqualizationBandSliders::EnvLinToLog(), EqualizationBandSliders::EnvLogToLin(), EnvelopeEditor::HandleMouseButtonDown(), and GetInfoCommand::SendEnvelopes().
|
inline |
Definition at line 92 of file Envelope.h.
Referenced by EnvelopeEditor::DrawPoints(), EnvelopeEditor::HandleMouseButtonDown(), EnvelopeEditor::MoveDragPoint(), and GetInfoCommand::SendEnvelopes().
void Envelope::GetPoints | ( | double * | bufferWhen, |
double * | bufferValue, | ||
int | bufferLen | ||
) | const |
Returns the sets of when and value pairs.
Definition at line 699 of file Envelope.cpp.
Referenced by EqualizationCurvesList::EnvelopeUpdated().
|
inline |
Definition at line 93 of file Envelope.h.
double Envelope::GetValue | ( | double | t, |
double | sampleDur = 0 |
||
) | const |
Get envelope value at time t.
Definition at line 828 of file Envelope.cpp.
References GetValues().
Referenced by Average(), AverageOfInverse(), EqualizationFilter::CalcFilter(), CopyRange(), anonymous_namespace{WaveformView.cpp}::DrawIndividualSamples(), EqualizationBandSliders::ErrMin(), SampleHandle::FindSampleEditingLevel(), CommonTrackView::GetEnvelopeValues(), EnvelopeEditor::HandleMouseButtonDown(), EnvelopeHandle::HitEnvelope(), SampleHandle::HitTest(), and PasteEnvelope().
|
private |
Definition at line 837 of file Envelope.cpp.
References GetValuesRelative().
Referenced by Cap(), CollapseRegion(), ExpandRegion(), PasteEnvelope(), RemoveUnneededPoints(), 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 928 of file Envelope.cpp.
References GetValuesRelative(), and mOffset.
Referenced by GetValue().
|
private |
Definition at line 936 of file Envelope.cpp.
References BinarySearchForTime(), BinarySearchForTime_LeftLimit(), GetInterpolationStartValueAtPoint(), mDB, mDefaultValue, and mEnv.
Referenced by GetValueRelative(), and GetValues().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 333 of file Envelope.cpp.
References mEnv.
Referenced by AUPImportFileHandle::HandleControlPoint().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 308 of file Envelope.cpp.
References mEnv.
void Envelope::Initialize | ( | int | numPoints | ) |
void Envelope::Insert | ( | double | when, |
double | value | ||
) |
Definition at line 371 of file Envelope.cpp.
References mEnv.
void Envelope::Insert | ( | int | point, |
const EnvPoint & | p | ||
) |
insert a point
Definition at line 366 of file Envelope.cpp.
References mEnv.
Referenced by ExpandRegion(), EqualizationBandSliders::GraphicEQ(), InsertOrReplaceRelative(), and RemoveUnneededPoints().
|
inline |
Add a point at a particular absolute time coordinate.
Definition at line 175 of file Envelope.h.
Referenced by SetEnvelopeCommand::ApplyInner(), EnvelopeEditor::HandleMouseButtonDown(), and TimeTrack::testMe().
|
private |
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 728 of file Envelope.cpp.
References EqualRange(), Insert(), mEnv, min(), mTrackLen, and wxT().
Referenced by Cap(), CollapseRegion(), and testMe().
void Envelope::InsertSpace | ( | double | t0, |
double | tlen | ||
) |
Definition at line 665 of file Envelope.cpp.
References ExpandRegion(), mOffset, and RemoveUnneededPoints().
double Envelope::Integral | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1171 of file Envelope.cpp.
References BinarySearchForTime(), Integral(), IntegrateInterpolated(), InterpolatePoints(), mDB, mDefaultValue, mEnv, and mOffset.
Referenced by Average(), Integral(), TimeTrack::testMe(), and testMe().
double Envelope::IntegralOfInverse | ( | double | t0, |
double | t1 | ||
) | const |
Definition at line 1234 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::IsDirty | ( | ) | const |
bool Envelope::IsTrivial | ( | ) | const |
Definition at line 55 of file Envelope.cpp.
References mDefaultValue, and mEnv.
void Envelope::MoveDragPoint | ( | double | newWhen, |
double | value | ||
) |
Definition at line 186 of file Envelope.cpp.
References mDragPoint, mDragPointValid, mEnv, min(), mTrackLen, SetDragPointValid(), EnvPoint::SetT(), and EnvPoint::SetVal().
Referenced by EnvelopeEditor::MoveDragPoint().
|
private |
Definition at line 1062 of file Envelope.cpp.
References BinarySearchForTime(), and mEnv.
Referenced by testMe().
|
private |
Definition at line 1053 of file Envelope.cpp.
References BinarySearchForTime(), and mEnv.
Referenced by testMe().
|
inline |
void Envelope::PasteEnvelope | ( | double | t0, |
const Envelope * | e, | ||
double | sampleDur | ||
) |
Definition at line 465 of file Envelope.cpp.
References PackedArray::begin(), ConsistencyCheck(), PackedArray::end(), EqualRange(), ExpandRegion(), GetValue(), GetValueRelative(), mDefaultValue, mEnv, min(), mOffset, mTrackLen, and RemoveUnneededPoints().
void Envelope::print | ( | ) | const |
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 674 of file Envelope.cpp.
Referenced by EqualizationBandSliders::GraphicEQ().
|
private |
Definition at line 548 of file Envelope.cpp.
References Delete(), EnvPoint::GetT(), EnvPoint::GetVal(), GetValueRelative(), Insert(), mEnv, and VALUE_TOLERANCE.
Referenced by CollapseRegion(), InsertSpace(), and PasteEnvelope().
void Envelope::RescaleTimes | ( | double | newLength | ) |
Definition at line 813 of file Envelope.cpp.
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 115 of file Envelope.cpp.
References ClampValue(), mDefaultValue, mEnv, mMaxValue, and mMinValue.
void Envelope::SetDragPoint | ( | int | dragPoint | ) |
Definition at line 143 of file Envelope.cpp.
References mDragPoint, mDragPointValid, mEnv, and min().
Referenced by EnvelopeEditor::HandleMouseButtonDown().
void Envelope::SetDragPointValid | ( | bool | valid | ) |
Definition at line 149 of file Envelope.cpp.
References mDefaultValue, mDragPoint, mDragPointValid, mEnv, and size.
Referenced by EnvelopeEditor::HandleDragging(), and MoveDragPoint().
|
inline |
Definition at line 96 of file Envelope.h.
Referenced by testMe().
void Envelope::SetOffset | ( | double | newOffset | ) |
void Envelope::SetRange | ( | double | minValue, |
double | maxValue | ||
) |
Definition at line 221 of file Envelope.cpp.
References ClampValue(), mDefaultValue, mEnv, mMaxValue, and mMinValue.
void Envelope::SetTrackLen | ( | double | trackLen, |
double | sampleDur = 0.0 |
||
) |
Definition at line 792 of file Envelope.cpp.
References AddPointAtEnd(), EqualRange(), GetValueRelative(), mEnv, min(), and mTrackLen.
Referenced by EqualizationFilter::EqualizationFilter(), and EqualizationBandSliders::GraphicEQ().
double Envelope::SolveIntegralOfInverse | ( | double | t0, |
double | area | ||
) | const |
Definition at line 1297 of file Envelope.cpp.
References BinarySearchForTime(), IntegrateInverseInterpolated(), InterpolatePoints(), mDB, mDefaultValue, mEnv, mOffset, and SolveIntegrateInverseInterpolated().
Referenced by PlaybackSchedule::SolveWarpedLength().
void Envelope::testMe | ( | ) |
Definition at line 1415 of file Envelope.cpp.
References checkResult(), Flatten(), InsertOrReplaceRelative(), Integral(), mEnv, NextPointAfter(), NumberOfPointsAfter(), and SetExponential().
void Envelope::WriteXML | ( | XMLWriter & | xmlFile | ) | const |
Definition at line 342 of file Envelope.cpp.
References EnvPoint::GetT(), EnvPoint::GetVal(), and wxT().
|
private |
Definition at line 249 of file Envelope.h.
Referenced by GetInterpolationStartValueAtPoint(), GetValuesRelative(), Integral(), IntegralOfInverse(), and SolveIntegralOfInverse().
|
private |
Definition at line 251 of file Envelope.h.
Referenced by Flatten(), GetValuesRelative(), 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(), BinarySearchForTime(), BinarySearchForTime_LeftLimit(), CollapseRegion(), ConsistencyCheck(), CopyRange(), Delete(), EqualRange(), ExpandRegion(), Flatten(), GetInterpolationStartValueAtPoint(), GetNumberOfPoints(), GetPoints(), GetValuesRelative(), HandleXMLChild(), HandleXMLTag(), Insert(), InsertOrReplaceRelative(), Integral(), IntegralOfInverse(), IsTrivial(), MoveDragPoint(), NextPointAfter(), NumberOfPointsAfter(), PasteEnvelope(), print(), Reassign(), RemoveUnneededPoints(), RescaleTimes(), RescaleValues(), SetDragPoint(), SetDragPointValid(), SetRange(), SetTrackLen(), SolveIntegralOfInverse(), and testMe().
|
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 CollapseRegion(), CopyRange(), Envelope(), GetPoints(), GetValues(), InsertSpace(), Integral(), IntegralOfInverse(), PasteEnvelope(), Reassign(), SetOffset(), and SolveIntegralOfInverse().
|
mutableprivate |
Definition at line 257 of file Envelope.h.
Referenced by BinarySearchForTime(), and BinarySearchForTime_LeftLimit().
|
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(), CollapseRegion(), CopyRange(), Envelope(), ExpandRegion(), InsertOrReplaceRelative(), MoveDragPoint(), PasteEnvelope(), RescaleTimes(), and SetTrackLen().