2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
WaveTrack.h
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_WAVETRACK__
|
|
|
|
#define __AUDACITY_WAVETRACK__
|
|
|
|
|
|
|
|
#include "Track.h"
|
|
|
|
|
2016-02-01 21:01:14 +00:00
|
|
|
#include <vector>
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/longlong.h>
|
|
|
|
|
2015-07-03 04:20:21 +00:00
|
|
|
#include "WaveTrackLocation.h"
|
|
|
|
|
2019-03-31 20:12:07 +00:00
|
|
|
class ProgressDialog;
|
|
|
|
|
2015-06-13 16:13:55 +00:00
|
|
|
class SpectrogramSettings;
|
2015-06-21 14:41:28 +00:00
|
|
|
class WaveformSettings;
|
2010-01-23 19:44:49 +00:00
|
|
|
class TimeWarper;
|
|
|
|
|
2018-12-05 02:54:40 +00:00
|
|
|
class Sequence;
|
|
|
|
class WaveClip;
|
|
|
|
|
|
|
|
// Array of pointers that assume ownership
|
|
|
|
using WaveClipHolder = std::shared_ptr< WaveClip >;
|
|
|
|
using WaveClipHolders = std::vector < WaveClipHolder >;
|
|
|
|
using WaveClipConstHolders = std::vector < std::shared_ptr< const WaveClip > >;
|
|
|
|
|
|
|
|
// Temporary arrays of mere pointers
|
|
|
|
using WaveClipPointers = std::vector < WaveClip* >;
|
|
|
|
using WaveClipConstPointers = std::vector < const WaveClip* >;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// Tolerance for merging wave tracks (in seconds)
|
|
|
|
//
|
|
|
|
#define WAVETRACK_MERGE_POINT_TOLERANCE 0.01
|
|
|
|
|
|
|
|
/// \brief Structure to hold region of a wavetrack and a comparison function
|
|
|
|
/// for sortability.
|
2016-02-01 21:01:14 +00:00
|
|
|
struct Region
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2016-02-01 21:01:14 +00:00
|
|
|
Region() : start(0), end(0) {}
|
|
|
|
Region(double start_, double end_) : start(start_), end(end_) {}
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
double start, end;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//used for sorting
|
2016-02-01 21:01:14 +00:00
|
|
|
bool operator < (const Region &b) const
|
2014-06-03 20:30:19 +00:00
|
|
|
{
|
2016-02-01 21:01:14 +00:00
|
|
|
return this->start < b.start;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
2016-02-01 21:01:14 +00:00
|
|
|
};
|
|
|
|
|
2018-10-27 23:21:54 +00:00
|
|
|
using Regions = std::vector < Region >;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
class Envelope;
|
|
|
|
|
2017-01-08 08:36:12 +00:00
|
|
|
class AUDACITY_DLL_API WaveTrack final : public PlayableTrack {
|
2018-11-19 04:07:05 +00:00
|
|
|
public:
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Constructor / Destructor / Duplicator
|
|
|
|
//
|
|
|
|
|
2016-08-13 04:38:31 +00:00
|
|
|
WaveTrack(const std::shared_ptr<DirManager> &projDirManager,
|
2020-01-07 21:00:36 +00:00
|
|
|
sampleFormat format, double rate);
|
2016-02-08 20:59:50 +00:00
|
|
|
WaveTrack(const WaveTrack &orig);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-01-10 18:20:31 +00:00
|
|
|
// overwrite data excluding the sample sequence but including display
|
|
|
|
// settings
|
|
|
|
void Reinit(const WaveTrack &orig);
|
|
|
|
|
|
|
|
private:
|
2018-11-19 04:07:05 +00:00
|
|
|
void Init(const WaveTrack &orig);
|
|
|
|
|
2018-11-19 01:15:26 +00:00
|
|
|
Track::Holder Clone() const override;
|
2016-03-02 19:37:47 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
friend class TrackFactory;
|
|
|
|
|
|
|
|
public:
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2015-07-03 04:20:21 +00:00
|
|
|
typedef WaveTrackLocation Location;
|
2018-11-19 04:07:05 +00:00
|
|
|
using Holder = std::shared_ptr<WaveTrack>;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
virtual ~WaveTrack();
|
2015-07-07 03:12:16 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
double GetOffset() const override;
|
|
|
|
void SetOffset(double o) override;
|
2018-09-20 16:39:05 +00:00
|
|
|
virtual ChannelType GetChannelIgnoringPan() const;
|
|
|
|
ChannelType GetChannel() const override;
|
2017-04-02 22:07:13 +00:00
|
|
|
virtual void SetPanFromChannelType() override;
|
|
|
|
|
2011-08-28 19:42:17 +00:00
|
|
|
/** @brief Get the time at which the first clip in the track starts
|
2013-02-20 23:42:58 +00:00
|
|
|
*
|
|
|
|
* @return time in seconds, or zero if there are no clips in the track
|
|
|
|
*/
|
2018-04-07 19:28:27 +00:00
|
|
|
double GetStartTime() const override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2011-08-28 19:42:17 +00:00
|
|
|
/** @brief Get the time at which the last clip in the track ends, plus
|
|
|
|
* recorded stuff
|
2013-02-20 23:42:58 +00:00
|
|
|
*
|
|
|
|
* @return time in seconds, or zero if there are no clips in the track.
|
2011-08-28 19:42:17 +00:00
|
|
|
*/
|
2018-04-07 19:28:27 +00:00
|
|
|
double GetEndTime() const override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Identifying the type of track
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// WaveTrack parameters
|
|
|
|
//
|
|
|
|
|
|
|
|
double GetRate() const;
|
|
|
|
void SetRate(double newRate);
|
|
|
|
|
|
|
|
// Multiplicative factor. Only converted to dB for display.
|
|
|
|
float GetGain() const;
|
|
|
|
void SetGain(float newGain);
|
|
|
|
|
|
|
|
// -1.0 (left) -> 1.0 (right)
|
|
|
|
float GetPan() const;
|
2017-04-02 22:07:13 +00:00
|
|
|
void SetPan(float newPan) override;
|
2018-01-12 17:08:09 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Takes gain and pan into account
|
2015-03-28 18:46:40 +00:00
|
|
|
float GetChannelGain(int channel) const;
|
2017-11-04 17:46:31 +00:00
|
|
|
|
2018-08-24 21:19:49 +00:00
|
|
|
// Old gain is used in playback in linearly interpolating
|
|
|
|
// the gain.
|
|
|
|
float GetOldChannelGain(int channel) const;
|
|
|
|
void SetOldChannelGain(int channel, float gain);
|
|
|
|
|
2017-11-04 17:46:31 +00:00
|
|
|
int GetWaveColorIndex() const { return mWaveColorIndex; };
|
|
|
|
void SetWaveColorIndex(int colorIndex);
|
|
|
|
|
2017-02-22 19:23:35 +00:00
|
|
|
sampleFormat GetSampleFormat() const { return mFormat; }
|
2017-03-22 17:25:55 +00:00
|
|
|
void ConvertToSampleFormat(sampleFormat format);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-06-13 16:13:55 +00:00
|
|
|
const SpectrogramSettings &GetSpectrogramSettings() const;
|
|
|
|
SpectrogramSettings &GetSpectrogramSettings();
|
|
|
|
SpectrogramSettings &GetIndependentSpectrogramSettings();
|
2016-04-08 05:56:06 +00:00
|
|
|
void SetSpectrogramSettings(std::unique_ptr<SpectrogramSettings> &&pSettings);
|
2015-06-13 16:13:55 +00:00
|
|
|
|
2015-06-21 14:41:28 +00:00
|
|
|
const WaveformSettings &GetWaveformSettings() const;
|
|
|
|
WaveformSettings &GetWaveformSettings();
|
|
|
|
WaveformSettings &GetIndependentWaveformSettings();
|
2016-04-08 05:56:06 +00:00
|
|
|
void SetWaveformSettings(std::unique_ptr<WaveformSettings> &&pSettings);
|
2018-02-18 16:55:26 +00:00
|
|
|
void UseSpectralPrefs( bool bUse=true );
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// High-level editing
|
|
|
|
//
|
|
|
|
|
2016-03-02 20:36:44 +00:00
|
|
|
Track::Holder Cut(double t0, double t1) override;
|
2016-11-26 13:48:08 +00:00
|
|
|
|
Bug2346: Complete fix...
... without making undesirable dependency cycles.
Eliminate calls to NewWaveTrack in effects, but in Edit>Copy too, which was
not mentioned in the bug report. (Copying a track, deselecting all, and pasting
preserved CLIP colors, but not the TRACK color setting which applies to newly
generated clips.)
Instead, always use the new function WaveTrack::EmptyCopy from the track to be
later replaced, getting color information.
NewWaveTrack is still used in benchmark test, import, the Track menu
commands that make new tracks, recording to new tracks, and generators without
a selection, where there is no track to copy from.
Also when deserializing tracks from the .aup file, in which case the saved
color is later retrieved from the file.
Also, in mix-and-render, where other logic decides whether to copy colors
afterward.
See commit a9658e6ef7f7eaefce4dc37a93d389cca7705f41
2020-03-11 01:40:14 +00:00
|
|
|
// Make another track copying format, rate, color, etc. but containing no
|
|
|
|
// clips
|
2020-05-18 17:09:06 +00:00
|
|
|
// It is important to pass the correct DirManager (that for the project
|
|
|
|
// which will own the copy) in the unusual case that a track is copied from
|
|
|
|
// another project or the clipboard. For copies within one project, the
|
|
|
|
// default will do.
|
2020-05-18 11:53:01 +00:00
|
|
|
Holder EmptyCopy(
|
|
|
|
const std::shared_ptr<DirManager> &pDirManager = {} ) const;
|
Bug2346: Complete fix...
... without making undesirable dependency cycles.
Eliminate calls to NewWaveTrack in effects, but in Edit>Copy too, which was
not mentioned in the bug report. (Copying a track, deselecting all, and pasting
preserved CLIP colors, but not the TRACK color setting which applies to newly
generated clips.)
Instead, always use the new function WaveTrack::EmptyCopy from the track to be
later replaced, getting color information.
NewWaveTrack is still used in benchmark test, import, the Track menu
commands that make new tracks, recording to new tracks, and generators without
a selection, where there is no track to copy from.
Also when deserializing tracks from the .aup file, in which case the saved
color is later retrieved from the file.
Also, in mix-and-render, where other logic decides whether to copy colors
afterward.
See commit a9658e6ef7f7eaefce4dc37a93d389cca7705f41
2020-03-11 01:40:14 +00:00
|
|
|
|
2016-11-26 13:48:08 +00:00
|
|
|
// If forClipboard is true,
|
|
|
|
// and there is no clip at the end time of the selection, then the result
|
|
|
|
// will contain a "placeholder" clip whose only purpose is to make
|
|
|
|
// GetEndTime() correct. This clip is not re-copied when pasting.
|
|
|
|
Track::Holder Copy(double t0, double t1, bool forClipboard = true) const override;
|
2016-03-02 20:36:44 +00:00
|
|
|
Track::Holder CopyNonconst(double t0, double t1) /* not override */;
|
2016-11-26 13:48:08 +00:00
|
|
|
|
2017-03-23 15:10:14 +00:00
|
|
|
void Clear(double t0, double t1) override;
|
|
|
|
void Paste(double t0, const Track *src) override;
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void ClearAndPaste(double t0, double t1,
|
2016-03-02 17:47:52 +00:00
|
|
|
const Track *src,
|
2010-01-23 19:44:49 +00:00
|
|
|
bool preserve = true,
|
|
|
|
bool merge = true,
|
2016-12-16 17:37:15 +00:00
|
|
|
const TimeWarper *effectWarper = NULL) /* not override */;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-03-23 15:10:14 +00:00
|
|
|
void Silence(double t0, double t1) override;
|
|
|
|
void InsertSilence(double t, double len) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-03-22 17:25:55 +00:00
|
|
|
void SplitAt(double t) /* not override */;
|
|
|
|
void Split(double t0, double t1) /* not override */;
|
2016-03-02 20:36:44 +00:00
|
|
|
// Track::Holder CutAndAddCutLine(double t0, double t1) /* not override */;
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void ClearAndAddCutLine(double t0, double t1) /* not override */;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-03-02 20:36:44 +00:00
|
|
|
Track::Holder SplitCut(double t0, double t1) /* not override */;
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void SplitDelete(double t0, double t1) /* not override */;
|
|
|
|
void Join(double t0, double t1) /* not override */;
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void Disjoin(double t0, double t1) /* not override */;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void Trim(double t0, double t1) /* not override */;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2017-03-22 17:25:55 +00:00
|
|
|
void HandleClear(double t0, double t1, bool addCutLines, bool split);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-03-23 15:10:14 +00:00
|
|
|
void SyncLockAdjust(double oldT1, double newT1) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2011-08-28 19:42:17 +00:00
|
|
|
/** @brief Returns true if there are no WaveClips in the specified region
|
|
|
|
*
|
|
|
|
* @return true if no clips in the track overlap the specified time range,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
2017-02-22 19:23:35 +00:00
|
|
|
bool IsEmpty(double t0, double t1) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2011-08-28 19:42:17 +00:00
|
|
|
/** @brief Append the sample data to the WaveTrack. You must call Flush()
|
|
|
|
* after the last Append.
|
|
|
|
*
|
|
|
|
* If there is an existing WaveClip in the WaveTrack then the data is
|
2016-02-13 15:43:16 +00:00
|
|
|
* appended to that clip. If there are no WaveClips in the track, then a NEW
|
2011-08-28 19:42:17 +00:00
|
|
|
* one is created.
|
|
|
|
*/
|
2017-03-22 17:25:55 +00:00
|
|
|
void Append(samplePtr buffer, sampleFormat format,
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t len, unsigned int stride=1,
|
2010-01-23 19:44:49 +00:00
|
|
|
XMLWriter* blockFileLog=NULL);
|
|
|
|
/// Flush must be called after last Append
|
2017-03-22 17:25:55 +00:00
|
|
|
void Flush();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-04-08 05:56:06 +00:00
|
|
|
///Invalidates all clips' wavecaches. Careful, This may not be threadsafe.
|
|
|
|
void ClearWaveCaches();
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
///
|
|
|
|
/// MM: Now that each wave track can contain multiple clips, we don't
|
2020-04-11 07:08:33 +00:00
|
|
|
/// have a continuous space of samples anymore, but we simulate it,
|
2010-01-23 19:44:49 +00:00
|
|
|
/// because there are alot of places (e.g. effects) using this interface.
|
|
|
|
/// This interface makes much sense for modifying samples, but note that
|
|
|
|
/// it is not time-accurate, because the "offset" is a double value and
|
|
|
|
/// therefore can lie inbetween samples. But as long as you use the
|
|
|
|
/// same value for "start" in both calls to "Set" and "Get" it is
|
|
|
|
/// guaranteed that the same samples are affected.
|
|
|
|
///
|
|
|
|
bool Get(samplePtr buffer, sampleFormat format,
|
2020-03-21 19:45:50 +00:00
|
|
|
sampleCount start, size_t len,
|
|
|
|
fillFormat fill = fillZero,
|
|
|
|
bool mayThrow = true,
|
|
|
|
// Report how many samples were copied from within clips, rather than
|
|
|
|
// filled according to fillFormat; but these were not necessarily one
|
|
|
|
// contiguous range.
|
|
|
|
sampleCount * pNumWithinClips = nullptr) const;
|
2017-03-22 17:25:55 +00:00
|
|
|
void Set(samplePtr buffer, sampleFormat format,
|
2016-09-06 13:19:27 +00:00
|
|
|
sampleCount start, size_t len);
|
2017-05-26 18:08:27 +00:00
|
|
|
|
|
|
|
// Fetch envelope values corresponding to uniformly separated sample times
|
|
|
|
// starting at the given time.
|
2016-08-20 21:56:41 +00:00
|
|
|
void GetEnvelopeValues(double *buffer, size_t bufferLen,
|
|
|
|
double t0) const;
|
2017-05-26 18:08:27 +00:00
|
|
|
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2016-12-25 13:40:15 +00:00
|
|
|
std::pair<float, float> GetMinMax(
|
|
|
|
double t0, double t1, bool mayThrow = true) const;
|
2017-11-19 03:18:49 +00:00
|
|
|
// May assume precondition: t0 <= t1
|
2016-12-25 13:40:15 +00:00
|
|
|
float GetRMS(double t0, double t1, bool mayThrow = true) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// MM: We now have more than one sequence and envelope per track, so
|
|
|
|
// instead of GetSequence() and GetEnvelope() we have the following
|
|
|
|
// function which give the sequence and envelope which is under the
|
|
|
|
// given X coordinate of the mouse pointer.
|
|
|
|
//
|
|
|
|
WaveClip* GetClipAtX(int xcoord);
|
|
|
|
Sequence* GetSequenceAtX(int xcoord);
|
|
|
|
Envelope* GetEnvelopeAtX(int xcoord);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2011-04-25 18:10:32 +00:00
|
|
|
WaveClip* GetClipAtSample(sampleCount sample);
|
2017-03-04 12:12:17 +00:00
|
|
|
WaveClip* GetClipAtTime(double time);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Getting information about the track's internal block sizes
|
2015-03-28 18:46:40 +00:00
|
|
|
// and alignment for efficiency
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
2016-09-06 13:19:27 +00:00
|
|
|
|
|
|
|
// This returns a possibly large or negative value
|
2015-03-28 18:46:40 +00:00
|
|
|
sampleCount GetBlockStart(sampleCount t) const;
|
2016-09-06 13:19:27 +00:00
|
|
|
|
|
|
|
// These return a nonnegative number of samples meant to size a memory buffer
|
|
|
|
size_t GetBestBlockSize(sampleCount t) const;
|
|
|
|
size_t GetMaxBlockSize() const;
|
|
|
|
size_t GetIdealBlockSize();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// XMLTagHandler callback methods for loading and saving
|
|
|
|
//
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
|
|
|
|
void HandleXMLEndTag(const wxChar *tag) override;
|
|
|
|
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
|
2017-02-22 19:23:35 +00:00
|
|
|
void WriteXML(XMLWriter &xmlFile) const override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns true if an error occurred while reading from XML
|
2016-02-24 06:06:47 +00:00
|
|
|
bool GetErrorOpening() override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Lock and unlock the track: you must lock the track before
|
|
|
|
// doing a copy and paste between projects.
|
|
|
|
//
|
|
|
|
|
2016-04-12 04:31:25 +00:00
|
|
|
bool Lock() const;
|
|
|
|
bool Unlock() const;
|
|
|
|
|
|
|
|
struct WaveTrackLockDeleter {
|
|
|
|
inline void operator () (const WaveTrack *pTrack) { pTrack->Unlock(); }
|
|
|
|
};
|
|
|
|
using LockerBase = std::unique_ptr<
|
|
|
|
const WaveTrack, WaveTrackLockDeleter
|
|
|
|
>;
|
|
|
|
|
|
|
|
// RAII object for locking.
|
|
|
|
struct Locker : private LockerBase
|
|
|
|
{
|
|
|
|
friend LockerBase;
|
|
|
|
Locker (const WaveTrack *pTrack)
|
|
|
|
: LockerBase{ pTrack }
|
|
|
|
{ pTrack->Lock(); }
|
2016-04-13 22:11:45 +00:00
|
|
|
Locker(Locker &&that) : LockerBase{std::move(that)} {}
|
|
|
|
Locker &operator= (Locker &&that) {
|
|
|
|
(LockerBase&)(*this) = std::move(that);
|
|
|
|
return *this;
|
|
|
|
}
|
2016-04-12 04:31:25 +00:00
|
|
|
};
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-04-12 03:38:33 +00:00
|
|
|
bool CloseLock(); //similar to Lock but should be called when the project closes.
|
|
|
|
// not balanced by unlocking calls.
|
|
|
|
|
2013-01-01 18:28:01 +00:00
|
|
|
/** @brief Convert correctly between an (absolute) time in seconds and a number of samples.
|
|
|
|
*
|
2014-06-03 20:30:19 +00:00
|
|
|
* This method will not give the correct results if used on a relative time (difference of two
|
2013-01-01 18:28:01 +00:00
|
|
|
* times). Each absolute time must be converted and the numbers of samples differenced:
|
|
|
|
* sampleCount start = track->TimeToLongSamples(t0);
|
|
|
|
* sampleCount end = track->TimeToLongSamples(t1);
|
|
|
|
* sampleCount len = (sampleCount)(end - start);
|
|
|
|
* NOT the likes of:
|
|
|
|
* sampleCount len = track->TimeToLongSamples(t1 - t0);
|
|
|
|
* See also WaveTrack::TimeToLongSamples().
|
|
|
|
* @param t0 The time (floating point seconds) to convert
|
|
|
|
* @return The number of samples from the start of the track which lie before the given time.
|
|
|
|
*/
|
2010-01-23 19:44:49 +00:00
|
|
|
sampleCount TimeToLongSamples(double t0) const;
|
2013-01-01 18:28:01 +00:00
|
|
|
/** @brief Convert correctly between an number of samples and an (absolute) time in seconds.
|
|
|
|
*
|
|
|
|
* @param pos The time number of samples from the start of the track to convert.
|
|
|
|
* @return The time in seconds.
|
|
|
|
*/
|
2015-04-19 11:27:33 +00:00
|
|
|
double LongSamplesToTime(sampleCount pos) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-08-13 20:06:00 +00:00
|
|
|
// Get access to the (visible) clips in the tracks, in unspecified order
|
2020-04-11 07:08:33 +00:00
|
|
|
// (not necessarily sequenced in time).
|
2016-08-11 17:06:24 +00:00
|
|
|
WaveClipHolders &GetClips() { return mClips; }
|
|
|
|
const WaveClipConstHolders &GetClips() const
|
|
|
|
{ return reinterpret_cast< const WaveClipConstHolders& >( mClips ); }
|
2016-02-20 00:58:30 +00:00
|
|
|
|
2019-04-25 20:23:51 +00:00
|
|
|
// Get mutative access to all clips (in some unspecified sequence),
|
2016-08-13 20:06:00 +00:00
|
|
|
// including those hidden in cutlines.
|
|
|
|
class AllClipsIterator
|
2018-12-22 14:35:22 +00:00
|
|
|
: public ValueIterator< WaveClip * >
|
2016-08-13 20:06:00 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructs an "end" iterator
|
|
|
|
AllClipsIterator () {}
|
|
|
|
|
|
|
|
// Construct a "begin" iterator
|
|
|
|
explicit AllClipsIterator( WaveTrack &track )
|
|
|
|
{
|
|
|
|
push( track.mClips );
|
|
|
|
}
|
|
|
|
|
|
|
|
WaveClip *operator * () const
|
|
|
|
{
|
|
|
|
if (mStack.empty())
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return mStack.back().first->get();
|
|
|
|
}
|
|
|
|
|
2018-12-05 02:54:40 +00:00
|
|
|
AllClipsIterator &operator ++ ();
|
2016-08-13 20:06:00 +00:00
|
|
|
|
|
|
|
// Define == well enough to serve for loop termination test
|
2019-04-25 20:23:51 +00:00
|
|
|
friend bool operator == (
|
|
|
|
const AllClipsIterator &a, const AllClipsIterator &b)
|
2016-08-13 20:06:00 +00:00
|
|
|
{ return a.mStack.empty() == b.mStack.empty(); }
|
|
|
|
|
2019-04-25 20:23:51 +00:00
|
|
|
friend bool operator != (
|
|
|
|
const AllClipsIterator &a, const AllClipsIterator &b)
|
2016-08-13 20:06:00 +00:00
|
|
|
{ return !( a == b ); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-12-05 02:54:40 +00:00
|
|
|
void push( WaveClipHolders &clips );
|
2016-08-13 20:06:00 +00:00
|
|
|
|
|
|
|
using Iterator = WaveClipHolders::iterator;
|
|
|
|
using Pair = std::pair< Iterator, Iterator >;
|
|
|
|
using Stack = std::vector< Pair >;
|
|
|
|
|
|
|
|
Stack mStack;
|
|
|
|
};
|
|
|
|
|
2019-04-25 20:23:51 +00:00
|
|
|
// Get const access to all clips (in some unspecified sequence),
|
|
|
|
// including those hidden in cutlines.
|
|
|
|
class AllClipsConstIterator
|
|
|
|
: public ValueIterator< const WaveClip * >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructs an "end" iterator
|
|
|
|
AllClipsConstIterator () {}
|
|
|
|
|
|
|
|
// Construct a "begin" iterator
|
|
|
|
explicit AllClipsConstIterator( const WaveTrack &track )
|
|
|
|
: mIter{ const_cast< WaveTrack& >( track ) }
|
|
|
|
{}
|
|
|
|
|
|
|
|
const WaveClip *operator * () const
|
|
|
|
{ return *mIter; }
|
|
|
|
|
|
|
|
AllClipsConstIterator &operator ++ ()
|
|
|
|
{ ++mIter; return *this; }
|
|
|
|
|
|
|
|
// Define == well enough to serve for loop termination test
|
|
|
|
friend bool operator == (
|
|
|
|
const AllClipsConstIterator &a, const AllClipsConstIterator &b)
|
|
|
|
{ return a.mIter == b.mIter; }
|
|
|
|
|
|
|
|
friend bool operator != (
|
|
|
|
const AllClipsConstIterator &a, const AllClipsConstIterator &b)
|
|
|
|
{ return !( a == b ); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
AllClipsIterator mIter;
|
|
|
|
};
|
|
|
|
|
2016-08-13 20:06:00 +00:00
|
|
|
IteratorRange< AllClipsIterator > GetAllClips()
|
|
|
|
{
|
|
|
|
return { AllClipsIterator{ *this }, AllClipsIterator{ } };
|
|
|
|
}
|
2019-04-25 20:23:51 +00:00
|
|
|
|
|
|
|
IteratorRange< AllClipsConstIterator > GetAllClips() const
|
|
|
|
{
|
|
|
|
return { AllClipsConstIterator{ *this }, AllClipsConstIterator{ } };
|
|
|
|
}
|
|
|
|
|
2016-02-13 15:43:16 +00:00
|
|
|
// Create NEW clip and add it to this track. Returns a pointer
|
2010-01-23 19:44:49 +00:00
|
|
|
// to the newly created clip.
|
|
|
|
WaveClip* CreateClip();
|
|
|
|
|
2015-01-04 19:44:54 +00:00
|
|
|
/** @brief Get access to the most recently added clip, or create a clip,
|
|
|
|
* if there is not already one. THIS IS NOT NECESSARILY RIGHTMOST.
|
|
|
|
*
|
|
|
|
* @return a pointer to the most recently added WaveClip
|
|
|
|
*/
|
|
|
|
WaveClip* NewestOrNewClip();
|
|
|
|
|
|
|
|
/** @brief Get access to the last (rightmost) clip, or create a clip,
|
|
|
|
* if there is not already one.
|
|
|
|
*
|
|
|
|
* @return a pointer to a WaveClip at the end of the track
|
|
|
|
*/
|
|
|
|
WaveClip* RightmostOrNewClip();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Get the linear index of a given clip (-1 if the clip is not found)
|
2016-08-11 17:06:24 +00:00
|
|
|
int GetClipIndex(const WaveClip* clip) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Get the nth clip in this WaveTrack (will return NULL if not found).
|
|
|
|
// Use this only in special cases (like getting the linked clip), because
|
|
|
|
// it is much slower than GetClipIterator().
|
2016-08-11 17:06:24 +00:00
|
|
|
WaveClip *GetClipByIndex(int index);
|
|
|
|
const WaveClip* GetClipByIndex(int index) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Get number of clips in this WaveTrack
|
|
|
|
int GetNumClips() const;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Add all wave clips to the given array 'clips' and sort the array by
|
|
|
|
// clip start time. The array is emptied prior to adding the clips.
|
2016-08-11 17:06:24 +00:00
|
|
|
WaveClipPointers SortedClipArray();
|
|
|
|
WaveClipConstPointers SortedClipArray() const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Before calling 'Offset' on a clip, use this function to see if the
|
|
|
|
// offsetting is allowed with respect to the other clips in this track.
|
|
|
|
// This function can optionally return the amount that is allowed for offsetting
|
|
|
|
// in this direction maximally.
|
|
|
|
bool CanOffsetClip(WaveClip* clip, double amount, double *allowedAmount=NULL);
|
|
|
|
|
2014-06-03 20:30:19 +00:00
|
|
|
// Before moving a clip into a track (or inserting a clip), use this
|
2010-01-23 19:44:49 +00:00
|
|
|
// function to see if the times are valid (i.e. don't overlap with
|
|
|
|
// existing clips).
|
2017-08-19 21:46:33 +00:00
|
|
|
bool CanInsertClip(WaveClip* clip, double &slideBy, double &tolerance);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-20 23:43:08 +00:00
|
|
|
// Remove the clip from the track and return a SMART pointer to it.
|
|
|
|
// You assume responsibility for its memory!
|
2017-07-09 18:09:33 +00:00
|
|
|
std::shared_ptr<WaveClip> RemoveAndReturnClip(WaveClip* clip);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Append a clip to the track
|
2017-07-09 18:09:33 +00:00
|
|
|
void AddClip(std::shared_ptr<WaveClip> &&clip); // Call using std::move
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Merge two clips, that is append data from clip2 to clip1,
|
|
|
|
// then remove clip2 from track.
|
|
|
|
// clipidx1 and clipidx2 are indices into the clip list.
|
2017-03-22 17:25:55 +00:00
|
|
|
void MergeClips(int clipidx1, int clipidx2);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Cache special locations (e.g. cut lines) for later speedy access
|
2016-02-27 17:12:40 +00:00
|
|
|
void UpdateLocationsCache() const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-20 00:09:36 +00:00
|
|
|
// Get cached locations
|
|
|
|
const std::vector<Location> &GetCachedLocations() const { return mDisplayLocationsCache; }
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-14 23:50:45 +00:00
|
|
|
// Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line)
|
2017-03-22 17:25:55 +00:00
|
|
|
void ExpandCutLine(double cutLinePosition, double* cutlineStart = NULL, double* cutlineEnd = NULL);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Remove cut line, without expanding the audio in it
|
|
|
|
bool RemoveCutLine(double cutLinePosition);
|
|
|
|
|
|
|
|
// This track has been merged into a stereo track. Copy shared parameters
|
2016-02-13 15:43:16 +00:00
|
|
|
// from the NEW partner.
|
2016-02-24 06:06:47 +00:00
|
|
|
void Merge(const Track &orig) override;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
// Resample track (i.e. all clips in the track)
|
2017-03-22 17:25:55 +00:00
|
|
|
void Resample(int rate, ProgressDialog *progress = NULL);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 21:42:30 +00:00
|
|
|
//
|
|
|
|
// AutoSave related
|
|
|
|
//
|
|
|
|
// Retrieve the unique autosave ID
|
2019-06-06 13:27:35 +00:00
|
|
|
int GetAutoSaveIdent() const;
|
2015-04-17 21:42:30 +00:00
|
|
|
// Set the unique autosave ID
|
|
|
|
void SetAutoSaveIdent(int id);
|
|
|
|
|
2016-02-27 18:04:34 +00:00
|
|
|
int GetLastScaleType() const { return mLastScaleType; }
|
|
|
|
void SetLastScaleType() const;
|
2015-06-22 00:03:15 +00:00
|
|
|
|
2016-02-27 18:04:34 +00:00
|
|
|
int GetLastdBRange() const { return mLastdBRange; }
|
|
|
|
void SetLastdBRange() const;
|
2015-08-27 20:06:13 +00:00
|
|
|
|
2015-09-06 22:09:16 +00:00
|
|
|
void GetDisplayBounds(float *min, float *max) const;
|
2016-02-27 18:04:34 +00:00
|
|
|
void SetDisplayBounds(float min, float max) const;
|
2015-09-06 22:09:16 +00:00
|
|
|
void GetSpectrumBounds(float *min, float *max) const;
|
2016-02-27 18:04:34 +00:00
|
|
|
void SetSpectrumBounds(float min, float max) const;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2016-10-28 15:56:15 +00:00
|
|
|
// For display purposes, calculate the y coordinate where the midline of
|
|
|
|
// the wave should be drawn, if display minimum and maximum map to the
|
|
|
|
// bottom and top. Maybe that is out of bounds.
|
|
|
|
int ZeroLevelYCoordinate(wxRect rect) const;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
//
|
|
|
|
// Protected variables
|
|
|
|
//
|
|
|
|
|
2016-08-11 17:06:24 +00:00
|
|
|
WaveClipHolders mClips;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
sampleFormat mFormat;
|
|
|
|
int mRate;
|
|
|
|
float mGain;
|
|
|
|
float mPan;
|
2017-11-04 17:46:31 +00:00
|
|
|
int mWaveColorIndex;
|
2018-08-24 21:19:49 +00:00
|
|
|
float mOldGain[2];
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Data that should be part of GUIWaveTrack
|
|
|
|
// and will be taken out of the WaveTrack class:
|
|
|
|
//
|
2016-02-27 18:04:34 +00:00
|
|
|
mutable float mDisplayMin;
|
|
|
|
mutable float mDisplayMax;
|
|
|
|
mutable float mSpectrumMin;
|
|
|
|
mutable float mSpectrumMax;
|
2015-09-06 22:09:16 +00:00
|
|
|
|
2016-02-27 18:04:34 +00:00
|
|
|
mutable int mLastScaleType; // last scale type choice
|
|
|
|
mutable int mLastdBRange;
|
2016-02-20 00:09:36 +00:00
|
|
|
mutable std::vector <Location> mDisplayLocationsCache;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Protected methods
|
|
|
|
//
|
|
|
|
|
2017-01-06 18:55:57 +00:00
|
|
|
private:
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2017-01-06 06:59:17 +00:00
|
|
|
TrackKind GetKind() const override { return TrackKind::Wave; }
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// Private variables
|
|
|
|
//
|
|
|
|
|
|
|
|
wxCriticalSection mFlushCriticalSection;
|
|
|
|
wxCriticalSection mAppendCriticalSection;
|
|
|
|
double mLegacyProjectFileOffset;
|
2015-04-17 21:42:30 +00:00
|
|
|
int mAutoSaveIdent;
|
2015-06-13 16:13:55 +00:00
|
|
|
|
2016-04-08 05:56:06 +00:00
|
|
|
std::unique_ptr<SpectrogramSettings> mpSpectrumSettings;
|
|
|
|
std::unique_ptr<WaveformSettings> mpWaveformSettings;
|
2010-01-23 19:44:49 +00:00
|
|
|
};
|
|
|
|
|
2015-03-28 18:46:40 +00:00
|
|
|
// This is meant to be a short-lived object, during whose lifetime,
|
|
|
|
// the contents of the WaveTrack are known not to change. It can replace
|
|
|
|
// repeated calls to WaveTrack::Get() (each of which opens and closes at least
|
|
|
|
// one block file).
|
|
|
|
class WaveTrackCache {
|
|
|
|
public:
|
2016-04-14 15:54:59 +00:00
|
|
|
WaveTrackCache()
|
2017-08-24 15:44:36 +00:00
|
|
|
: mBufferSize(0)
|
2016-04-14 15:54:59 +00:00
|
|
|
, mOverlapBuffer()
|
|
|
|
, mNValidBuffers(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:44:36 +00:00
|
|
|
explicit WaveTrackCache(const std::shared_ptr<const WaveTrack> &pTrack)
|
|
|
|
: mBufferSize(0)
|
2015-03-28 18:46:40 +00:00
|
|
|
, mOverlapBuffer()
|
|
|
|
, mNValidBuffers(0)
|
|
|
|
{
|
|
|
|
SetTrack(pTrack);
|
|
|
|
}
|
|
|
|
~WaveTrackCache();
|
|
|
|
|
2018-01-30 19:13:57 +00:00
|
|
|
const std::shared_ptr<const WaveTrack>& GetTrack() const { return mPTrack; }
|
2017-08-24 15:44:36 +00:00
|
|
|
void SetTrack(const std::shared_ptr<const WaveTrack> &pTrack);
|
2015-03-28 18:46:40 +00:00
|
|
|
|
|
|
|
// Uses fillZero always
|
|
|
|
// Returns null on failure
|
|
|
|
// Returned pointer may be invalidated if Get is called again
|
2016-02-14 23:50:45 +00:00
|
|
|
// Do not DELETE[] the pointer
|
2016-12-22 22:08:29 +00:00
|
|
|
constSamplePtr Get(
|
|
|
|
sampleFormat format, sampleCount start, size_t len, bool mayThrow);
|
2015-03-28 18:46:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Free();
|
|
|
|
|
|
|
|
struct Buffer {
|
2016-04-14 16:17:59 +00:00
|
|
|
Floats data;
|
2015-03-28 18:46:40 +00:00
|
|
|
sampleCount start;
|
|
|
|
sampleCount len;
|
|
|
|
|
2016-04-14 16:17:59 +00:00
|
|
|
Buffer() : start(0), len(0) {}
|
|
|
|
void Free() { data.reset(); start = 0; len = 0; }
|
2015-03-28 18:46:40 +00:00
|
|
|
sampleCount end() const { return start + len; }
|
2017-02-21 14:07:25 +00:00
|
|
|
|
|
|
|
void swap ( Buffer &other )
|
|
|
|
{
|
2016-04-14 16:17:59 +00:00
|
|
|
data .swap ( other.data );
|
2017-02-21 14:07:25 +00:00
|
|
|
std::swap( start, other.start );
|
|
|
|
std::swap( len, other.len );
|
|
|
|
}
|
2015-03-28 18:46:40 +00:00
|
|
|
};
|
|
|
|
|
2017-08-24 15:44:36 +00:00
|
|
|
std::shared_ptr<const WaveTrack> mPTrack;
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t mBufferSize;
|
2015-03-28 18:46:40 +00:00
|
|
|
Buffer mBuffers[2];
|
2016-02-01 15:16:00 +00:00
|
|
|
GrowableSampleBuffer mOverlapBuffer;
|
2015-03-28 18:46:40 +00:00
|
|
|
int mNValidBuffers;
|
|
|
|
};
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif // __AUDACITY_WAVETRACK__
|