Audacity  2.2.2
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
WaveClip Class Referencefinal

This allows multiple clips to be a part of one WaveTrack. More...

#include <WaveClip.h>

Inheritance diagram for WaveClip:
XMLTagHandler

Public Member Functions

 WaveClip (const std::shared_ptr< DirManager > &projDirManager, sampleFormat format, int rate, int colourIndex)
 
 WaveClip (const WaveClip &orig, const std::shared_ptr< DirManager > &projDirManager, bool copyCutlines)
 
 WaveClip (const WaveClip &orig, const std::shared_ptr< DirManager > &projDirManager, bool copyCutlines, double t0, double t1)
 
virtual ~WaveClip ()
 
void ConvertToSampleFormat (sampleFormat format)
 
void TimeToSamplesClip (double t0, sampleCount *s0) const
 
int GetRate () const
 
void SetRate (int rate)
 
void Resample (int rate, ProgressDialog *progress=NULL)
 
void SetColourIndex (int index)
 
int GetColourIndex () const
 
void SetOffset (double offset)
 
double GetOffset () const
 
void Offset (double delta)
 
double GetStartTime () const
 
double GetEndTime () const
 
sampleCount GetStartSample () const
 
sampleCount GetEndSample () const
 
sampleCount GetNumSamples () const
 
bool WithinClip (double t) const
 
bool BeforeClip (double t) const
 
bool AfterClip (double t) const
 
bool GetSamples (samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
 
void SetSamples (samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
 
EnvelopeGetEnvelope ()
 
const EnvelopeGetEnvelope () const
 
BlockArrayGetSequenceBlockArray ()
 
SequenceGetSequence ()
 
void MarkChanged ()
 
bool GetWaveDisplay (WaveDisplay &display, double t0, double pixelsPerSecond, bool &isLoadingOD) const
 
bool GetSpectrogram (WaveTrackCache &cache, const float *&spectrogram, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond) const
 
std::pair< float, float > GetMinMax (double t0, double t1, bool mayThrow=true) const
 
float GetRMS (double t0, double t1, bool mayThrow=true) const
 
void ClearDisplayRect () const
 
void SetDisplayRect (const wxRect &r) const
 
void GetDisplayRect (wxRect *r)
 
void UpdateEnvelopeTrackLen ()
 
void Append (samplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1, XMLWriter *blockFileLog=NULL)
 You must call Flush after the last Append. More...
 
void Flush ()
 Flush must be called after last Append. More...
 
void AppendAlias (const wxString &fName, sampleCount start, size_t len, int channel, bool useOD)
 
void AppendCoded (const wxString &fName, sampleCount start, size_t len, int channel, int decodeType)
 
void Clear (double t0, double t1)
 
void ClearAndAddCutLine (double t0, double t1)
 Clear, and add cut line that starts at t0 and contains everything until t1. More...
 
void Paste (double t0, const WaveClip *other)
 Paste data from other clip, resampling it if not equal rate. More...
 
void InsertSilence (double t, double len, double *pEnvelopeValue=nullptr)
 
void AppendSilence (double len, double envelopeValue)
 
WaveClipHoldersGetCutLines ()
 Get access to cut lines list. More...
 
const WaveClipConstHoldersGetCutLines () const
 
size_t NumCutLines () const
 
bool FindCutLine (double cutLinePosition, double *cutLineStart=NULL, double *cutLineEnd=NULL) const
 
void ExpandCutLine (double cutLinePosition)
 
bool RemoveCutLine (double cutLinePosition)
 Remove cut line, without expanding the audio in it. More...
 
void OffsetCutLines (double t0, double len)
 Offset cutlines right to time 't0' by time amount 'len'. More...
 
void Lock ()
 Lock all blockfiles. More...
 
void Unlock ()
 Unlock all blockfiles. More...
 
void CloseLock ()
 
void ClearWaveCache ()
 Delete the wave cache - force redraw. Thread-safe. More...
 
void AddInvalidRegion (sampleCount startSample, sampleCount endSample)
 Adds an invalid region to the wavecache so it redraws that portion only. More...
 
bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
void HandleXMLEndTag (const wxChar *tag) override
 
XMLTagHandlerHandleXMLChild (const wxChar *tag) override
 
void WriteXML (XMLWriter &xmlFile) const
 
bool GetIsPlaceholder () const
 
void SetIsPlaceholder (bool val)
 
bool SharesBoundaryWithNextClip (const WaveClip *next) const
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Public Attributes

std::unique_ptr< SpecPxCachemSpecPxCache
 

Protected Attributes

wxRect mDisplayRect {}
 
double mOffset { 0 }
 
int mRate
 
int mDirty { 0 }
 
int mColourIndex
 
std::unique_ptr< SequencemSequence
 
std::unique_ptr< EnvelopemEnvelope
 
std::unique_ptr< WaveCachemWaveCache
 
ODLock mWaveCacheMutex {}
 
std::unique_ptr< SpecCachemSpecCache
 
SampleBuffer mAppendBuffer {}
 
size_t mAppendBufferLen { 0 }
 
WaveClipHolders mCutLines {}
 
bool mIsPlaceholder { false }
 

Private Member Functions

 WaveClip (const WaveClip &) PROHIBITED
 
WaveClipoperator= (const WaveClip &) PROHIBITED
 

Detailed Description

This allows multiple clips to be a part of one WaveTrack.

Definition at line 176 of file WaveClip.h.

Constructor & Destructor Documentation

WaveClip::WaveClip ( const WaveClip )
private
WaveClip::WaveClip ( const std::shared_ptr< DirManager > &  projDirManager,
sampleFormat  format,
int  rate,
int  colourIndex 
)

Definition at line 300 of file WaveClip.cpp.

References format, and WaveCache::rate.

302 {
303  mRate = rate;
304  mColourIndex = colourIndex;
305  mSequence = std::make_unique<Sequence>(projDirManager, format);
306 
307  mEnvelope = std::make_unique<Envelope>(true, 1e-7, 2.0, 1.0);
308 
309  mWaveCache = std::make_unique<WaveCache>();
310  mSpecCache = std::make_unique<SpecCache>();
311  mSpecPxCache = std::make_unique<SpecPxCache>(1);
312 }
std::unique_ptr< SpecPxCache > mSpecPxCache
Definition: WaveClip.h:369
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
int format
Definition: ExportPCM.cpp:56
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
std::unique_ptr< SpecCache > mSpecCache
Definition: WaveClip.h:384
int mColourIndex
Definition: WaveClip.h:377
WaveClip::WaveClip ( const WaveClip orig,
const std::shared_ptr< DirManager > &  projDirManager,
bool  copyCutlines 
)

Definition at line 314 of file WaveClip.cpp.

References GetIsPlaceholder(), mColourIndex, mCutLines, mEnvelope, mOffset, mRate, and mSequence.

317 {
318  // essentially a copy constructor - but you must pass in the
319  // current project's DirManager, because we might be copying
320  // from one project to another
321 
322  mOffset = orig.mOffset;
323  mRate = orig.mRate;
324  mColourIndex = orig.mColourIndex;
325  mSequence = std::make_unique<Sequence>(*orig.mSequence, projDirManager);
326 
327  mEnvelope = std::make_unique<Envelope>(*orig.mEnvelope);
328 
329  mWaveCache = std::make_unique<WaveCache>();
330  mSpecCache = std::make_unique<SpecCache>();
331  mSpecPxCache = std::make_unique<SpecPxCache>(1);
332 
333  if ( copyCutlines )
334  for (const auto &clip: orig.mCutLines)
335  mCutLines.push_back
336  ( std::make_unique<WaveClip>( *clip, projDirManager, true ) );
337 
339 }
double mOffset
Definition: WaveClip.h:374
std::unique_ptr< SpecPxCache > mSpecPxCache
Definition: WaveClip.h:369
WaveClipHolders mCutLines
Definition: WaveClip.h:390
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
std::unique_ptr< SpecCache > mSpecCache
Definition: WaveClip.h:384
int mColourIndex
Definition: WaveClip.h:377
bool GetIsPlaceholder() const
Definition: WaveClip.h:361
bool mIsPlaceholder
Definition: WaveClip.h:393
WaveClip::WaveClip ( const WaveClip orig,
const std::shared_ptr< DirManager > &  projDirManager,
bool  copyCutlines,
double  t0,
double  t1 
)

Definition at line 341 of file WaveClip.cpp.

References sampleCount::as_double(), GetIsPlaceholder(), GetOffset(), mColourIndex, mCutLines, mEnvelope, mOffset, mRate, mSequence, and TimeToSamplesClip().

345 {
346  // Copy only a range of the other WaveClip
347 
348  mOffset = orig.mOffset;
349  mRate = orig.mRate;
350  mColourIndex = orig.mColourIndex;
351 
352  mWaveCache = std::make_unique<WaveCache>();
353  mSpecCache = std::make_unique<SpecCache>();
354  mSpecPxCache = std::make_unique<SpecPxCache>(1);
355 
357 
358  sampleCount s0, s1;
359 
360  orig.TimeToSamplesClip(t0, &s0);
361  orig.TimeToSamplesClip(t1, &s1);
362 
363  mSequence = orig.mSequence->Copy(s0, s1);
364 
365  mEnvelope = std::make_unique<Envelope>(
366  *orig.mEnvelope,
367  mOffset + s0.as_double()/mRate,
368  mOffset + s1.as_double()/mRate
369  );
370 
371  if ( copyCutlines )
372  // Copy cutline clips that fall in the range
373  for (const auto &ppClip : orig.mCutLines)
374  {
375  const WaveClip* clip = ppClip.get();
376  double cutlinePosition = orig.mOffset + clip->GetOffset();
377  if (cutlinePosition >= t0 && cutlinePosition <= t1)
378  {
379  auto newCutLine =
380  std::make_unique< WaveClip >( *clip, projDirManager, true );
381  newCutLine->SetOffset( cutlinePosition - t0 );
382  mCutLines.push_back(std::move(newCutLine));
383  }
384  }
385 }
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
double mOffset
Definition: WaveClip.h:374
std::unique_ptr< SpecPxCache > mSpecPxCache
Definition: WaveClip.h:369
WaveClipHolders mCutLines
Definition: WaveClip.h:390
int mRate
Definition: WaveClip.h:375
double as_double() const
Definition: Types.h:88
double GetOffset() const
Definition: WaveClip.h:222
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
std::unique_ptr< SpecCache > mSpecCache
Definition: WaveClip.h:384
int mColourIndex
Definition: WaveClip.h:377
bool GetIsPlaceholder() const
Definition: WaveClip.h:361
bool mIsPlaceholder
Definition: WaveClip.h:393
WaveClip::~WaveClip ( )
virtual

Definition at line 388 of file WaveClip.cpp.

389 {
390 }

Member Function Documentation

void WaveClip::AddInvalidRegion ( sampleCount  startSample,
sampleCount  endSample 
)

Adds an invalid region to the wavecache so it redraws that portion only.

Definition at line 479 of file WaveClip.cpp.

Referenced by WaveTrack::AddInvalidRegion().

480 {
481  ODLocker locker(&mWaveCacheMutex);
482  if(mWaveCache!=NULL)
483  mWaveCache->AddInvalidRegion(startSample,endSample);
484 }
ODLock mWaveCacheMutex
Definition: WaveClip.h:383
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
bool WaveClip::AfterClip ( double  t) const

Definition at line 465 of file WaveClip.cpp.

Referenced by WaveTrack::HandleClear().

466 {
467  auto ts = (sampleCount)floor(t * mRate + 0.5);
468  return ts >= GetEndSample() + mAppendBufferLen;
469 }
int mRate
Definition: WaveClip.h:375
sampleCount GetEndSample() const
Definition: WaveClip.cpp:443
size_t mAppendBufferLen
Definition: WaveClip.h:386
void WaveClip::Append ( samplePtr  buffer,
sampleFormat  format,
size_t  len,
unsigned int  stride = 1,
XMLWriter blockFileLog = NULL 
)

You must call Flush after the last Append.

Definition at line 1393 of file WaveClip.cpp.

References CopySamples(), min(), and SAMPLE_SIZE.

Referenced by WaveTrack::Append().

1399 {
1400  //wxLogDebug(wxT("Append: len=%lli"), (long long) len);
1401 
1402  auto maxBlockSize = mSequence->GetMaxBlockSize();
1403  auto blockSize = mSequence->GetIdealAppendLen();
1404  sampleFormat seqFormat = mSequence->GetSampleFormat();
1405 
1406  if (!mAppendBuffer.ptr())
1407  mAppendBuffer.Allocate(maxBlockSize, seqFormat);
1408 
1409  auto cleanup = finally( [&] {
1410  // use NOFAIL-GUARANTEE
1412  MarkChanged();
1413  } );
1414 
1415  for(;;) {
1416  if (mAppendBufferLen >= blockSize) {
1417  // flush some previously appended contents
1418  // use STRONG-GUARANTEE
1419  mSequence->Append(mAppendBuffer.ptr(), seqFormat, blockSize,
1420  blockFileLog);
1421 
1422  // use NOFAIL-GUARANTEE for rest of this "if"
1423  memmove(mAppendBuffer.ptr(),
1424  mAppendBuffer.ptr() + blockSize * SAMPLE_SIZE(seqFormat),
1425  (mAppendBufferLen - blockSize) * SAMPLE_SIZE(seqFormat));
1426  mAppendBufferLen -= blockSize;
1427  blockSize = mSequence->GetIdealAppendLen();
1428  }
1429 
1430  if (len == 0)
1431  break;
1432 
1433  // use NOFAIL-GUARANTEE for rest of this "for"
1434  wxASSERT(mAppendBufferLen <= maxBlockSize);
1435  auto toCopy = std::min(len, maxBlockSize - mAppendBufferLen);
1436 
1437  CopySamples(buffer, format,
1438  mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
1439  seqFormat,
1440  toCopy,
1441  true, // high quality
1442  stride);
1443 
1444  mAppendBufferLen += toCopy;
1445  buffer += toCopy * SAMPLE_SIZE(format) * stride;
1446  len -= toCopy;
1447  }
1448 }
void MarkChanged()
Definition: WaveClip.h:255
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
SampleBuffer & Allocate(size_t count, sampleFormat format)
Definition: SampleFormat.h:67
SampleBuffer mAppendBuffer
Definition: WaveClip.h:385
int format
Definition: ExportPCM.cpp:56
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
sampleFormat
Definition: Types.h:188
size_t mAppendBufferLen
Definition: WaveClip.h:386
int min(int a, int b)
samplePtr ptr() const
Definition: SampleFormat.h:81
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:1360
void WaveClip::AppendAlias ( const wxString &  fName,
sampleCount  start,
size_t  len,
int  channel,
bool  useOD 
)

Definition at line 1450 of file WaveClip.cpp.

Referenced by WaveTrack::AppendAlias().

1453 {
1454  // use STRONG-GUARANTEE
1455  mSequence->AppendAlias(fName, start, len, channel,useOD);
1456 
1457  // use NOFAIL-GUARANTEE
1459  MarkChanged();
1460 }
void MarkChanged()
Definition: WaveClip.h:255
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:1360
void WaveClip::AppendCoded ( const wxString &  fName,
sampleCount  start,
size_t  len,
int  channel,
int  decodeType 
)

Definition at line 1462 of file WaveClip.cpp.

Referenced by WaveTrack::AppendCoded().

1465 {
1466  // use STRONG-GUARANTEE
1467  mSequence->AppendCoded(fName, start, len, channel, decodeType);
1468 
1469  // use NOFAIL-GUARANTEE
1471  MarkChanged();
1472 }
void MarkChanged()
Definition: WaveClip.h:255
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:1360
void WaveClip::AppendSilence ( double  len,
double  envelopeValue 
)

Insert silence at the end, and causes the envelope to ramp linearly to the given value

Definition at line 1669 of file WaveClip.cpp.

Referenced by WaveTrack::Join().

1671 {
1672  auto t = GetEndTime();
1673  InsertSilence( t, len, &envelopeValue );
1674 }
void InsertSilence(double t, double len, double *pEnvelopeValue=nullptr)
Definition: WaveClip.cpp:1636
double GetEndTime() const
Definition: WaveClip.cpp:427
bool WaveClip::BeforeClip ( double  t) const

Definition at line 459 of file WaveClip.cpp.

Referenced by WaveTrack::HandleClear(), and WaveTrack::InsertSilence().

460 {
461  auto ts = (sampleCount)floor(t * mRate + 0.5);
462  return ts <= GetStartSample();
463 }
int mRate
Definition: WaveClip.h:375
sampleCount GetStartSample() const
Definition: WaveClip.cpp:438
void WaveClip::Clear ( double  t0,
double  t1 
)

This name is consistent with WaveTrack::Clear. It performs a "Cut" operation (but without putting the cutted audio to the clipboard)

Definition at line 1676 of file WaveClip.cpp.

References GetOffset(), and Offset().

Referenced by WaveTrack::HandleClear().

1678 {
1679  sampleCount s0, s1;
1680 
1681  TimeToSamplesClip(t0, &s0);
1682  TimeToSamplesClip(t1, &s1);
1683 
1684  // use STRONG-GUARANTEE
1685  GetSequence()->Delete(s0, s1-s0);
1686 
1687  // use NOFAIL-GUARANTEE in the remaining
1688 
1689  // msmeyer
1690  //
1691  // Delete all cutlines that are within the given area, if any.
1692  //
1693  // Note that when cutlines are active, two functions are used:
1694  // Clear() and ClearAndAddCutLine(). ClearAndAddCutLine() is called
1695  // whenever the user directly calls a command that removes some audio, e.g.
1696  // "Cut" or "Clear" from the menu. This command takes care about recursive
1697  // preserving of cutlines within clips. Clear() is called when internal
1698  // operations want to remove audio. In the latter case, it is the right
1699  // thing to just remove all cutlines within the area.
1700  //
1701  double clip_t0 = t0;
1702  double clip_t1 = t1;
1703  if (clip_t0 < GetStartTime())
1704  clip_t0 = GetStartTime();
1705  if (clip_t1 > GetEndTime())
1706  clip_t1 = GetEndTime();
1707 
1708  // May DELETE as we iterate, so don't use range-for
1709  for (auto it = mCutLines.begin(); it != mCutLines.end();)
1710  {
1711  WaveClip* clip = it->get();
1712  double cutlinePosition = mOffset + clip->GetOffset();
1713  if (cutlinePosition >= t0 && cutlinePosition <= t1)
1714  {
1715  // This cutline is within the area, DELETE it
1716  it = mCutLines.erase(it);
1717  }
1718  else
1719  {
1720  if (cutlinePosition >= t1)
1721  {
1722  clip->Offset(clip_t0 - clip_t1);
1723  }
1724  ++it;
1725  }
1726  }
1727 
1728  // Collapse envelope
1729  auto sampleTime = 1.0 / GetRate();
1730  GetEnvelope()->CollapseRegion( t0, t1, sampleTime );
1731  if (t0 < GetStartTime())
1732  Offset(-(GetStartTime() - t0));
1733 
1734  MarkChanged();
1735 }
void Delete(sampleCount start, sampleCount len)
Definition: Sequence.cpp:1684
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
Sequence * GetSequence()
Definition: WaveClip.h:250
double mOffset
Definition: WaveClip.h:374
double GetStartTime() const
Definition: WaveClip.cpp:421
void Offset(double delta)
Definition: WaveClip.h:223
void MarkChanged()
Definition: WaveClip.h:255
WaveClipHolders mCutLines
Definition: WaveClip.h:390
double GetOffset() const
Definition: WaveClip.h:222
Envelope * GetEnvelope()
Definition: WaveClip.h:243
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
int GetRate() const
Definition: WaveClip.h:210
double GetEndTime() const
Definition: WaveClip.cpp:427
void CollapseRegion(double t0, double t1, double sampleDur)
Definition: Envelope.cpp:674
void WaveClip::ClearAndAddCutLine ( double  t0,
double  t1 
)

Clear, and add cut line that starts at t0 and contains everything until t1.

Definition at line 1737 of file WaveClip.cpp.

References GetOffset(), min(), and Offset().

1741 {
1742  if (t0 > GetEndTime() || t1 < GetStartTime())
1743  return; // time out of bounds
1744 
1745  const double clip_t0 = std::max( t0, GetStartTime() );
1746  const double clip_t1 = std::min( t1, GetEndTime() );
1747 
1748  auto newClip = std::make_unique< WaveClip >
1749  (*this, mSequence->GetDirManager(), true, clip_t0, clip_t1);
1750 
1751  newClip->SetOffset( clip_t0 - mOffset );
1752 
1753  // Remove cutlines from this clip that were in the selection, shift
1754  // left those that were after the selection
1755  // May DELETE as we iterate, so don't use range-for
1756  for (auto it = mCutLines.begin(); it != mCutLines.end();)
1757  {
1758  WaveClip* clip = it->get();
1759  double cutlinePosition = mOffset + clip->GetOffset();
1760  if (cutlinePosition >= t0 && cutlinePosition <= t1)
1761  it = mCutLines.erase(it);
1762  else
1763  {
1764  if (cutlinePosition >= t1)
1765  {
1766  clip->Offset(clip_t0 - clip_t1);
1767  }
1768  ++it;
1769  }
1770  }
1771 
1772  // Clear actual audio data
1773  sampleCount s0, s1;
1774 
1775  TimeToSamplesClip(t0, &s0);
1776  TimeToSamplesClip(t1, &s1);
1777 
1778  // use WEAK-GUARANTEE
1779  GetSequence()->Delete(s0, s1-s0);
1780 
1781  // Collapse envelope
1782  auto sampleTime = 1.0 / GetRate();
1783  GetEnvelope()->CollapseRegion( t0, t1, sampleTime );
1784  if (t0 < GetStartTime())
1785  Offset(-(GetStartTime() - t0));
1786 
1787  MarkChanged();
1788 
1789  mCutLines.push_back(std::move(newClip));
1790 }
void Delete(sampleCount start, sampleCount len)
Definition: Sequence.cpp:1684
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
Sequence * GetSequence()
Definition: WaveClip.h:250
double mOffset
Definition: WaveClip.h:374
double GetStartTime() const
Definition: WaveClip.cpp:421
void Offset(double delta)
Definition: WaveClip.h:223
void MarkChanged()
Definition: WaveClip.h:255
WaveClipHolders mCutLines
Definition: WaveClip.h:390
double GetOffset() const
Definition: WaveClip.h:222
Envelope * GetEnvelope()
Definition: WaveClip.h:243
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
int min(int a, int b)
int GetRate() const
Definition: WaveClip.h:210
double GetEndTime() const
Definition: WaveClip.cpp:427
void CollapseRegion(double t0, double t1, double sampleDur)
Definition: Envelope.cpp:674
void WaveClip::ClearDisplayRect ( ) const

Definition at line 1377 of file WaveClip.cpp.

1378 {
1379  mDisplayRect.x = mDisplayRect.y = -1;
1380  mDisplayRect.width = mDisplayRect.height = -1;
1381 }
wxRect mDisplayRect
Definition: WaveClip.h:372
void WaveClip::ClearWaveCache ( )

Delete the wave cache - force redraw. Thread-safe.

Definition at line 472 of file WaveClip.cpp.

Referenced by WaveTrack::ClearWaveCaches().

473 {
474  ODLocker locker(&mWaveCacheMutex);
475  mWaveCache = std::make_unique<WaveCache>();
476 }
ODLock mWaveCacheMutex
Definition: WaveClip.h:383
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
void WaveClip::CloseLock ( )

Definition at line 1876 of file WaveClip.cpp.

Referenced by WaveTrack::CloseLock().

1877 {
1878  GetSequence()->CloseLock();
1879  for (const auto &cutline: mCutLines)
1880  cutline->CloseLock();
1881 }
Sequence * GetSequence()
Definition: WaveClip.h:250
WaveClipHolders mCutLines
Definition: WaveClip.h:390
bool CloseLock()
Definition: Sequence.cpp:101
void WaveClip::ConvertToSampleFormat ( sampleFormat  format)

Definition at line 1350 of file WaveClip.cpp.

Referenced by Paste().

1351 {
1352  // Note: it is not necessary to do this recursively to cutlines.
1353  // They get converted as needed when they are expanded.
1354 
1355  auto bChanged = mSequence->ConvertToSampleFormat(format);
1356  if (bChanged)
1357  MarkChanged();
1358 }
void MarkChanged()
Definition: WaveClip.h:255
int format
Definition: ExportPCM.cpp:56
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void WaveClip::ExpandCutLine ( double  cutLinePosition)

Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line). Returns true if a cut line could be found and sucessfully expanded, false otherwise

Definition at line 1811 of file WaveClip.cpp.

Referenced by WaveTrack::ExpandCutLine().

1813 {
1814  auto end = mCutLines.end();
1815  auto it = std::find_if( mCutLines.begin(), end,
1816  [&](const WaveClipHolder &cutline) {
1817  return fabs(mOffset + cutline->GetOffset() - cutLinePosition) < 0.0001;
1818  } );
1819 
1820  if ( it != end ) {
1821  auto cutline = it->get();
1822  // assume STRONG-GUARANTEE from Paste
1823 
1824  // Envelope::Paste takes offset into account, WaveClip::Paste doesn't!
1825  // Do this to get the right result:
1826  cutline->mEnvelope->SetOffset(0);
1827 
1828  Paste(mOffset+cutline->GetOffset(), cutline);
1829  // Now erase the cutline,
1830  // but be careful to find it again, because Paste above may
1831  // have modified the array of cutlines (if our cutline contained
1832  // another cutline!), invalidating the iterator we had.
1833  end = mCutLines.end();
1834  it = std::find_if(mCutLines.begin(), end,
1835  [=](const WaveClipHolder &p) { return p.get() == cutline; });
1836  if (it != end)
1837  mCutLines.erase(it); // deletes cutline!
1838  else {
1839  wxASSERT(false);
1840  }
1841  }
1842 }
double mOffset
Definition: WaveClip.h:374
WaveClipHolders mCutLines
Definition: WaveClip.h:390
std::shared_ptr< WaveClip > WaveClipHolder
Definition: WaveClip.h:121
void Paste(double t0, const WaveClip *other)
Paste data from other clip, resampling it if not equal rate.
Definition: WaveClip.cpp:1579
bool WaveClip::FindCutLine ( double  cutLinePosition,
double *  cutLineStart = NULL,
double *  cutLineEnd = NULL 
) const

Find cut line at (approximately) this position. Returns true and fills in cutLineStart and cutLineEnd (if specified) if a cut line at this position could be found. Return false otherwise.

Definition at line 1792 of file WaveClip.cpp.

Referenced by WaveTrack::ExpandCutLine().

1795 {
1796  for (const auto &cutline: mCutLines)
1797  {
1798  if (fabs(mOffset + cutline->GetOffset() - cutLinePosition) < 0.0001)
1799  {
1800  if (cutlineStart)
1801  *cutlineStart = mOffset+cutline->GetStartTime();
1802  if (cutlineEnd)
1803  *cutlineEnd = mOffset+cutline->GetEndTime();
1804  return true;
1805  }
1806  }
1807 
1808  return false;
1809 }
double mOffset
Definition: WaveClip.h:374
WaveClipHolders mCutLines
Definition: WaveClip.h:390
void WaveClip::Flush ( )

Flush must be called after last Append.

Definition at line 1474 of file WaveClip.cpp.

Referenced by WaveTrack::Flush().

1479 {
1480  //wxLogDebug(wxT("WaveClip::Flush"));
1481  //wxLogDebug(wxT(" mAppendBufferLen=%lli"), (long long) mAppendBufferLen);
1482  //wxLogDebug(wxT(" previous sample count %lli"), (long long) mSequence->GetNumSamples());
1483 
1484  if (mAppendBufferLen > 0) {
1485 
1486  auto cleanup = finally( [&] {
1487  // Blow away the append buffer even in case of failure. May lose some
1488  // data but don't leave the track in an un-flushed state.
1489 
1490  // Use NOFAIL-GUARANTEE of these steps.
1491  mAppendBufferLen = 0;
1493  MarkChanged();
1494  } );
1495 
1496  mSequence->Append(mAppendBuffer.ptr(), mSequence->GetSampleFormat(),
1498  }
1499 
1500  //wxLogDebug(wxT("now sample count %lli"), (long long) mSequence->GetNumSamples());
1501 }
void MarkChanged()
Definition: WaveClip.h:255
SampleBuffer mAppendBuffer
Definition: WaveClip.h:385
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
size_t mAppendBufferLen
Definition: WaveClip.h:386
samplePtr ptr() const
Definition: SampleFormat.h:81
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:1360
int WaveClip::GetColourIndex ( ) const
inline

Definition at line 220 of file WaveClip.h.

Referenced by TrackArtist::DrawClipWaveform().

220 { return mColourIndex;};
int mColourIndex
Definition: WaveClip.h:377
WaveClipHolders& WaveClip::GetCutLines ( )
inline

Get access to cut lines list.

Definition at line 314 of file WaveClip.h.

Referenced by WaveTrack::UpdateLocationsCache().

314 { return mCutLines; }
WaveClipHolders mCutLines
Definition: WaveClip.h:390
const WaveClipConstHolders& WaveClip::GetCutLines ( ) const
inline

Definition at line 315 of file WaveClip.h.

316  { return reinterpret_cast< const WaveClipConstHolders& >( mCutLines ); }
WaveClipHolders mCutLines
Definition: WaveClip.h:390
std::vector< std::shared_ptr< const WaveClip > > WaveClipConstHolders
Definition: WaveClip.h:123
void WaveClip::GetDisplayRect ( wxRect *  r)

Definition at line 1388 of file WaveClip.cpp.

Referenced by WaveTrack::GetClipAtX().

1389 {
1390  *r = mDisplayRect;
1391 }
wxRect mDisplayRect
Definition: WaveClip.h:372
sampleCount WaveClip::GetEndSample ( ) const

Definition at line 443 of file WaveClip.cpp.

Referenced by WaveTrack::Get(), WaveTrack::GetEnvelopeValues(), EffectReverse::ProcessOneWave(), WaveTrack::Set(), and WaveTrack::Silence().

444 {
445  return GetStartSample() + mSequence->GetNumSamples();
446 }
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
sampleCount GetStartSample() const
Definition: WaveClip.cpp:438
double WaveClip::GetEndTime ( ) const

Definition at line 427 of file WaveClip.cpp.

Referenced by SetClipCommand::ApplyInner(), SetEnvelopeCommand::ApplyInner(), WaveTrack::CanInsertClip(), WaveTrack::CanOffsetClip(), SelectHandle::Click(), WaveTrack::Disjoin(), WaveTrack::ExpandCutLine(), WaveTrack::GetClipAtTime(), WaveTrack::GetEndTime(), WaveTrack::GetEnvelopeValues(), WaveTrack::GetMinMax(), WaveTrack::GetRMS(), WaveTrack::HandleClear(), WaveTrack::Join(), WaveTrack::MergeClips(), AudacityProject::OnClipMove(), WaveTrack::Paste(), Paste(), and WaveTrack::UpdateLocationsCache().

428 {
429  auto numSamples = mSequence->GetNumSamples();
430 
431  double maxLen = mOffset + (numSamples+mAppendBufferLen).as_double()/mRate;
432  // JS: calculated value is not the length;
433  // it is a maximum value and can be negative; no clipping to 0
434 
435  return maxLen;
436 }
double mOffset
Definition: WaveClip.h:374
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
size_t mAppendBufferLen
Definition: WaveClip.h:386
Envelope* WaveClip::GetEnvelope ( )
inline
const Envelope* WaveClip::GetEnvelope ( ) const
inline

Definition at line 244 of file WaveClip.h.

244 { return mEnvelope.get(); }
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
bool WaveClip::GetIsPlaceholder ( ) const
inline

Definition at line 361 of file WaveClip.h.

Referenced by WaveTrack::Paste(), and WaveClip().

361 { return mIsPlaceholder; }
bool mIsPlaceholder
Definition: WaveClip.h:393
std::pair< float, float > WaveClip::GetMinMax ( double  t0,
double  t1,
bool  mayThrow = true 
) const

Definition at line 1308 of file WaveClip.cpp.

References THROW_INCONSISTENCY_EXCEPTION.

Referenced by WaveTrack::GetMinMax().

1310 {
1311  if (t0 > t1) {
1312  if (mayThrow)
1314  return {
1315  0.f, // harmless, but unused since Sequence::GetMinMax does not use these values
1316  0.f // harmless, but unused since Sequence::GetMinMax does not use these values
1317  };
1318  }
1319 
1320  if (t0 == t1)
1321  return{ 0.f, 0.f };
1322 
1323  sampleCount s0, s1;
1324 
1325  TimeToSamplesClip(t0, &s0);
1326  TimeToSamplesClip(t1, &s1);
1327 
1328  return mSequence->GetMinMax(s0, s1-s0, mayThrow);
1329 }
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
#define THROW_INCONSISTENCY_EXCEPTION
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
sampleCount WaveClip::GetNumSamples ( ) const
double WaveClip::GetOffset ( ) const
inline
int WaveClip::GetRate ( ) const
inline

Definition at line 210 of file WaveClip.h.

Referenced by TrackArtist::DrawIndividualSamples(), and SharesBoundaryWithNextClip().

210 { return mRate; }
int mRate
Definition: WaveClip.h:375
float WaveClip::GetRMS ( double  t0,
double  t1,
bool  mayThrow = true 
) const

Definition at line 1331 of file WaveClip.cpp.

References THROW_INCONSISTENCY_EXCEPTION.

Referenced by WaveTrack::GetRMS().

1332 {
1333  if (t0 > t1) {
1334  if (mayThrow)
1336  return 0.f;
1337  }
1338 
1339  if (t0 == t1)
1340  return 0.f;
1341 
1342  sampleCount s0, s1;
1343 
1344  TimeToSamplesClip(t0, &s0);
1345  TimeToSamplesClip(t1, &s1);
1346 
1347  return mSequence->GetRMS(s0, s1-s0, mayThrow);
1348 }
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
#define THROW_INCONSISTENCY_EXCEPTION
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
bool WaveClip::GetSamples ( samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len,
bool  mayThrow = true 
) const

Definition at line 399 of file WaveClip.cpp.

Referenced by WaveTrack::Disjoin(), TrackArtist::DrawIndividualSamples(), and WaveTrack::Get().

401 {
402  return mSequence->Get(buffer, format, start, len, mayThrow);
403 }
int format
Definition: ExportPCM.cpp:56
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
Sequence* WaveClip::GetSequence ( )
inline
BlockArray * WaveClip::GetSequenceBlockArray ( )

Definition at line 416 of file WaveClip.cpp.

417 {
418  return &mSequence->GetBlockArray();
419 }
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
bool WaveClip::GetSpectrogram ( WaveTrackCache cache,
const float *&  spectrogram,
const sampleCount *&  where,
size_t  numPixels,
double  t0,
double  pixelsPerSecond 
) const

Definition at line 1197 of file WaveClip.cpp.

References SpectrogramSettings::algorithm, SpectrogramSettings::algReassignment, WaveTrack::GetSpectrogramSettings(), WaveTrackCache::GetTrack(), min(), SpectrogramSettings::NBins(), SpectrogramSettings::WindowSize(), and SpectrogramSettings::ZeroPaddingFactor().

Referenced by TrackArtist::DrawClipSpectrum().

1202 {
1203  const WaveTrack *const track = waveTrackCache.GetTrack();
1204  const SpectrogramSettings &settings = track->GetSpectrogramSettings();
1205 
1206  bool match =
1207  mSpecCache &&
1208  mSpecCache->len > 0 &&
1209  mSpecCache->Matches
1210  (mDirty, pixelsPerSecond, settings, mRate);
1211 
1212  if (match &&
1213  mSpecCache->start == t0 &&
1214  mSpecCache->len >= numPixels) {
1215  spectrogram = &mSpecCache->freq[0];
1216  where = &mSpecCache->where[0];
1217 
1218  return false; //hit cache completely
1219  }
1220 
1221  // Caching is not implemented for reassignment, unless for
1222  // a complete hit, because of the complications of time reassignment
1224  match = false;
1225 
1226  // Free the cache when it won't cause a major stutter.
1227  // If the window size changed, we know there is nothing to be copied
1228  // If we zoomed out, or resized, we can give up memory. But not too much -
1229  // up to 2x extra is needed at the end of the clip to prevent stutter.
1230  if (mSpecCache->freq.capacity() > 2.1 * mSpecCache->freq.size() ||
1231  mSpecCache->windowSize*mSpecCache->zeroPaddingFactor <
1232  settings.WindowSize()*settings.ZeroPaddingFactor())
1233  {
1234  match = false;
1235  mSpecCache = std::make_unique<SpecCache>();
1236  }
1237 
1238  const double tstep = 1.0 / pixelsPerSecond;
1239  const double samplesPerPixel = mRate * tstep;
1240 
1241  int oldX0 = 0;
1242  double correction = 0.0;
1243 
1244  int copyBegin = 0, copyEnd = 0;
1245  if (match) {
1246  findCorrection(mSpecCache->where, mSpecCache->len, numPixels,
1247  t0, mRate, samplesPerPixel,
1248  oldX0, correction);
1249  // Remember our first pixel maps to oldX0 in the old cache,
1250  // possibly out of bounds.
1251  // For what range of pixels can data be copied?
1252  copyBegin = std::min((int)numPixels, std::max(0, -oldX0));
1253  copyEnd = std::min((int)numPixels, std::max(0,
1254  (int)mSpecCache->len - oldX0
1255  ));
1256  }
1257 
1258  // Resize the cache, keep the contents unchanged.
1259  mSpecCache->Grow(numPixels, settings, pixelsPerSecond, t0);
1260  auto nBins = settings.NBins();
1261 
1262  // Optimization: if the old cache is good and overlaps
1263  // with the current one, re-use as much of the cache as
1264  // possible
1265  if (copyEnd > copyBegin)
1266  {
1267  // memmove is required since dst/src overlap
1268  memmove(&mSpecCache->freq[nBins * copyBegin],
1269  &mSpecCache->freq[nBins * (copyBegin + oldX0)],
1270  nBins * (copyEnd - copyBegin) * sizeof(float));
1271  }
1272 
1273  // Reassignment accumulates, so it needs a zeroed buffer
1275  {
1276  // The cache could theoretically copy from the middle, resulting
1277  // in two regions to update. This won't happen in zoom, since
1278  // old cache doesn't match. It won't happen in resize, since the
1279  // spectrum view is pinned to left side of window.
1280  wxASSERT(
1281  (copyBegin >= 0 && copyEnd == (int)numPixels) || // copied the end
1282  (copyBegin == 0 && copyEnd <= (int)numPixels) // copied the beginning
1283  );
1284 
1285  int zeroBegin = copyBegin > 0 ? 0 : copyEnd-copyBegin;
1286  int zeroEnd = copyBegin > 0 ? copyBegin : numPixels;
1287 
1288  memset(&mSpecCache->freq[nBins*zeroBegin], 0, nBins*(zeroEnd-zeroBegin)*sizeof(float));
1289  }
1290 
1291  // purposely offset the display 1/2 sample to the left (as compared
1292  // to waveform display) to properly center response of the FFT
1293  fillWhere(mSpecCache->where, numPixels, 0.5, correction,
1294  t0, mRate, samplesPerPixel);
1295 
1296  mSpecCache->Populate
1297  (settings, waveTrackCache, copyBegin, copyEnd, numPixels,
1298  mSequence->GetNumSamples(),
1299  mOffset, mRate, pixelsPerSecond);
1300 
1301  mSpecCache->dirty = mDirty;
1302  spectrogram = &mSpecCache->freq[0];
1303  where = &mSpecCache->where[0];
1304 
1305  return true;
1306 }
Spectrogram settings, either for one track or as defaults.
double mOffset
Definition: WaveClip.h:374
int mRate
Definition: WaveClip.h:375
const SpectrogramSettings & GetSpectrogramSettings() const
Definition: WaveTrack.cpp:690
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
size_t WindowSize() const
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
int min(int a, int b)
std::unique_ptr< SpecCache > mSpecCache
Definition: WaveClip.h:384
size_t ZeroPaddingFactor() const
int mDirty
Definition: WaveClip.h:376
sampleCount WaveClip::GetStartSample ( ) const
double WaveClip::GetStartTime ( ) const
bool WaveClip::GetWaveDisplay ( WaveDisplay display,
double  t0,
double  pixelsPerSecond,
bool &  isLoadingOD 
) const

Getting high-level data for screen display and clipping calculations and Contrast

Definition at line 550 of file WaveClip.cpp.

References WaveCache::bl, WaveDisplay::bl, WaveCache::ClearInvalidRegions(), CopySamples(), floatSample, if(), WaveCache::len, WaveCache::LoadInvalidRegions(), WaveCache::max, WaveDisplay::max, WaveCache::min, min(), WaveDisplay::min, WaveDisplay::ownBl, WaveDisplay::ownWhere, ArrayOf< X >::reinit(), WaveCache::rms, WaveDisplay::rms, SAMPLE_SIZE, WaveCache::where, WaveDisplay::where, and WaveDisplay::width.

Referenced by TrackArtist::DrawClipWaveform().

552 {
553  const bool allocated = (display.where != 0);
554 
555  const size_t numPixels = (int)display.width;
556 
557  size_t p0 = 0; // least column requiring computation
558  size_t p1 = numPixels; // greatest column requiring computation, plus one
559 
560  float *min;
561  float *max;
562  float *rms;
563  int *bl;
564  std::vector<sampleCount> *pWhere;
565 
566  if (allocated) {
567  // assume ownWhere is filled.
568  min = &display.min[0];
569  max = &display.max[0];
570  rms = &display.rms[0];
571  bl = &display.bl[0];
572  pWhere = &display.ownWhere;
573  }
574  else {
575  // Lock the list of invalid regions
576  ODLocker locker(&mWaveCacheMutex);
577 
578  const double tstep = 1.0 / pixelsPerSecond;
579  const double samplesPerPixel = mRate * tstep;
580 
581  // Make a tolerant comparison of the pps values in this wise:
582  // accumulated difference of times over the number of pixels is less than
583  // a sample period.
584  const bool ppsMatch = mWaveCache &&
585  (fabs(tstep - 1.0 / mWaveCache->pps) * numPixels < (1.0 / mRate));
586 
587  const bool match =
588  mWaveCache &&
589  ppsMatch &&
590  mWaveCache->len > 0 &&
591  mWaveCache->dirty == mDirty;
592 
593  if (match &&
594  mWaveCache->start == t0 &&
595  mWaveCache->len >= numPixels) {
596  mWaveCache->LoadInvalidRegions(mSequence.get(), true);
597  mWaveCache->ClearInvalidRegions();
598 
599  // Satisfy the request completely from the cache
600  display.min = &mWaveCache->min[0];
601  display.max = &mWaveCache->max[0];
602  display.rms = &mWaveCache->rms[0];
603  display.bl = &mWaveCache->bl[0];
604  display.where = &mWaveCache->where[0];
605  isLoadingOD = mWaveCache->numODPixels > 0;
606  return true;
607  }
608 
609  std::unique_ptr<WaveCache> oldCache(std::move(mWaveCache));
610 
611  int oldX0 = 0;
612  double correction = 0.0;
613  size_t copyBegin = 0, copyEnd = 0;
614  if (match) {
615  findCorrection(oldCache->where, oldCache->len, numPixels,
616  t0, mRate, samplesPerPixel,
617  oldX0, correction);
618  // Remember our first pixel maps to oldX0 in the old cache,
619  // possibly out of bounds.
620  // For what range of pixels can data be copied?
621  copyBegin = std::min<size_t>(numPixels, std::max(0, -oldX0));
622  copyEnd = std::min<size_t>(numPixels, std::max(0,
623  (int)oldCache->len - oldX0
624  ));
625  }
626  if (!(copyEnd > copyBegin))
627  oldCache.reset(0);
628 
629  mWaveCache = std::make_unique<WaveCache>(numPixels, pixelsPerSecond, mRate, t0, mDirty);
630  min = &mWaveCache->min[0];
631  max = &mWaveCache->max[0];
632  rms = &mWaveCache->rms[0];
633  bl = &mWaveCache->bl[0];
634  pWhere = &mWaveCache->where;
635 
636  fillWhere(*pWhere, numPixels, 0.0, correction,
637  t0, mRate, samplesPerPixel);
638 
639  // The range of pixels we must fetch from the Sequence:
640  p0 = (copyBegin > 0) ? 0 : copyEnd;
641  p1 = (copyEnd >= numPixels) ? copyBegin : numPixels;
642 
643  // Optimization: if the old cache is good and overlaps
644  // with the current one, re-use as much of the cache as
645  // possible
646 
647  if (oldCache) {
648 
649  //TODO: only load inval regions if
650  //necessary. (usually is the case, so no rush.)
651  //also, we should be updating the NEW cache, but here we are patching the old one up.
652  oldCache->LoadInvalidRegions(mSequence.get(), false);
653  oldCache->ClearInvalidRegions();
654 
655  // Copy what we can from the old cache.
656  const int length = copyEnd - copyBegin;
657  const size_t sizeFloats = length * sizeof(float);
658  const int srcIdx = (int)copyBegin + oldX0;
659  memcpy(&min[copyBegin], &oldCache->min[srcIdx], sizeFloats);
660  memcpy(&max[copyBegin], &oldCache->max[srcIdx], sizeFloats);
661  memcpy(&rms[copyBegin], &oldCache->rms[srcIdx], sizeFloats);
662  memcpy(&bl[copyBegin], &oldCache->bl[srcIdx], length * sizeof(int));
663  }
664  }
665 
666  if (p1 > p0) {
667  // Cache was not used or did not satisfy the whole request
668  std::vector<sampleCount> &where = *pWhere;
669 
670  /* handle values in the append buffer */
671 
672  auto numSamples = mSequence->GetNumSamples();
673  auto a = p0;
674 
675  // Not all of the required columns might be in the sequence.
676  // Some might be in the append buffer.
677  for (; a < p1; ++a) {
678  if (where[a + 1] > numSamples)
679  break;
680  }
681 
682  // Handle the columns that land in the append buffer.
683  //compute the values that are outside the overlap from scratch.
684  if (a < p1) {
685  sampleFormat seqFormat = mSequence->GetSampleFormat();
686  bool didUpdate = false;
687  for(auto i = a; i < p1; i++) {
688  auto left = std::max(sampleCount{ 0 },
689  where[i] - numSamples);
690  auto right = std::min(sampleCount{ mAppendBufferLen },
691  where[i + 1] - numSamples);
692 
693  //wxCriticalSectionLocker locker(mAppendCriticalSection);
694 
695  if (right > left) {
696  Floats b;
697  float *pb{};
698  // left is nonnegative and at most mAppendBufferLen:
699  auto sLeft = left.as_size_t();
700  // The difference is at most mAppendBufferLen:
701  size_t len = ( right - left ).as_size_t();
702 
703  if (seqFormat == floatSample)
704  pb = &((float *)mAppendBuffer.ptr())[sLeft];
705  else {
706  b.reinit(len);
707  pb = b.get();
708  CopySamples(mAppendBuffer.ptr() + sLeft * SAMPLE_SIZE(seqFormat),
709  seqFormat,
710  (samplePtr)pb, floatSample, len);
711  }
712 
713  float theMax, theMin, sumsq;
714  {
715  const float val = pb[0];
716  theMax = theMin = val;
717  sumsq = val * val;
718  }
719  for(decltype(len) j = 1; j < len; j++) {
720  const float val = pb[j];
721  theMax = std::max(theMax, val);
722  theMin = std::min(theMin, val);
723  sumsq += val * val;
724  }
725 
726  min[i] = theMin;
727  max[i] = theMax;
728  rms[i] = (float)sqrt(sumsq / len);
729  bl[i] = 1; //for now just fake it.
730 
731  didUpdate=true;
732  }
733  }
734 
735  // Shrink the right end of the range to fetch from Sequence
736  if(didUpdate)
737  p1 = a;
738  }
739 
740  // Done with append buffer, now fetch the rest of the cache miss
741  // from the sequence
742  if (p1 > p0) {
743  if (!mSequence->GetWaveDisplay(&min[p0],
744  &max[p0],
745  &rms[p0],
746  &bl[p0],
747  p1-p0,
748  &where[p0]))
749  {
750  isLoadingOD=false;
751  return false;
752  }
753  }
754  }
755 
756  //find the number of OD pixels - the only way to do this is by recounting
757  if (!allocated) {
758  // Now report the results
759  display.min = min;
760  display.max = max;
761  display.rms = rms;
762  display.bl = bl;
763  display.where = &(*pWhere)[0];
764  isLoadingOD = mWaveCache->numODPixels > 0;
765  }
766  else {
767  using namespace std;
768  isLoadingOD =
769  count_if(display.ownBl.begin(), display.ownBl.end(),
770  bind2nd(less<int>(), 0)) > 0;
771  }
772 
773  return true;
774 }
sampleCount * where
Definition: WaveClip.h:135
float * max
Definition: WaveClip.h:136
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
float * min
Definition: WaveClip.h:136
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
int mRate
Definition: WaveClip.h:375
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
std::vector< sampleCount > ownWhere
Definition: WaveClip.h:139
ODLock mWaveCacheMutex
Definition: WaveClip.h:383
SampleBuffer mAppendBuffer
Definition: WaveClip.h:385
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
sampleFormat
Definition: Types.h:188
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
char * samplePtr
Definition: Types.h:203
size_t mAppendBufferLen
Definition: WaveClip.h:386
if(pTrack &&pTrack->GetDisplay()!=WaveTrack::Spectrum)
int min(int a, int b)
samplePtr ptr() const
Definition: SampleFormat.h:81
int * bl
Definition: WaveClip.h:137
std::vector< int > ownBl
Definition: WaveClip.h:141
float * rms
Definition: WaveClip.h:136
int mDirty
Definition: WaveClip.h:376
XMLTagHandler * WaveClip::HandleXMLChild ( const wxChar *  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 1545 of file WaveClip.cpp.

1546 {
1547  if (!wxStrcmp(tag, wxT("sequence")))
1548  return mSequence.get();
1549  else if (!wxStrcmp(tag, wxT("envelope")))
1550  return mEnvelope.get();
1551  else if (!wxStrcmp(tag, wxT("waveclip")))
1552  {
1553  // Nested wave clips are cut lines
1554  mCutLines.push_back(
1555  std::make_unique<WaveClip>(mSequence->GetDirManager(),
1556  mSequence->GetSampleFormat(), mRate, 0 /*colourindex*/));
1557  return mCutLines.back().get();
1558  }
1559  else
1560  return NULL;
1561 }
WaveClipHolders mCutLines
Definition: WaveClip.h:390
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void WaveClip::HandleXMLEndTag ( const wxChar *  tag)
override

Definition at line 1539 of file WaveClip.cpp.

Referenced by WaveTrack::HandleXMLEndTag().

1540 {
1541  if (!wxStrcmp(tag, wxT("waveclip")))
1543 }
void UpdateEnvelopeTrackLen()
Definition: WaveClip.cpp:1360
bool WaveClip::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 1503 of file WaveClip.cpp.

References Internat::CompatibleToDouble(), and XMLValueChecker::IsGoodString().

1504 {
1505  if (!wxStrcmp(tag, wxT("waveclip")))
1506  {
1507  double dblValue;
1508  long longValue;
1509  while (*attrs)
1510  {
1511  const wxChar *attr = *attrs++;
1512  const wxChar *value = *attrs++;
1513 
1514  if (!value)
1515  break;
1516 
1517  const wxString strValue = value;
1518  if (!wxStrcmp(attr, wxT("offset")))
1519  {
1520  if (!XMLValueChecker::IsGoodString(strValue) ||
1521  !Internat::CompatibleToDouble(strValue, &dblValue))
1522  return false;
1523  SetOffset(dblValue);
1524  }
1525  if (!wxStrcmp(attr, wxT("colorindex")))
1526  {
1527  if (!XMLValueChecker::IsGoodString(strValue) ||
1528  !strValue.ToLong( &longValue))
1529  return false;
1530  SetColourIndex(longValue);
1531  }
1532  }
1533  return true;
1534  }
1535 
1536  return false;
1537 }
void SetOffset(double offset)
Definition: WaveClip.cpp:392
static bool IsGoodString(const wxString &str)
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
void SetColourIndex(int index)
Definition: WaveClip.h:219
void WaveClip::InsertSilence ( double  t,
double  len,
double *  pEnvelopeValue = nullptr 
)

Insert silence - note that this is an efficient operation for large amounts of silence

Definition at line 1636 of file WaveClip.cpp.

References WaveCache::len.

Referenced by WaveTrack::InsertSilence().

1638 {
1639  sampleCount s0;
1640  TimeToSamplesClip(t, &s0);
1641  auto slen = (sampleCount)floor(len * mRate + 0.5);
1642 
1643  // use STRONG-GUARANTEE
1644  GetSequence()->InsertSilence(s0, slen);
1645 
1646  // use NOFAIL-GUARANTEE
1647  OffsetCutLines(t, len);
1648 
1649  const auto sampleTime = 1.0 / GetRate();
1650  auto pEnvelope = GetEnvelope();
1651  if ( pEnvelopeValue ) {
1652 
1653  // Preserve limit value at the end
1654  auto oldLen = pEnvelope->GetTrackLen();
1655  auto newLen = oldLen + len;
1656  pEnvelope->Cap( sampleTime );
1657 
1658  // Ramp across the silence to the given value
1659  pEnvelope->SetTrackLen( newLen, sampleTime );
1660  pEnvelope->InsertOrReplace
1661  ( pEnvelope->GetOffset() + newLen, *pEnvelopeValue );
1662  }
1663  else
1664  pEnvelope->InsertSpace( t, len );
1665 
1666  MarkChanged();
1667 }
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
void InsertSilence(sampleCount s0, sampleCount len)
Definition: Sequence.cpp:668
Sequence * GetSequence()
Definition: WaveClip.h:250
void MarkChanged()
Definition: WaveClip.h:255
int mRate
Definition: WaveClip.h:375
void OffsetCutLines(double t0, double len)
Offset cutlines right to time 't0' by time amount 'len'.
Definition: WaveClip.cpp:1859
Envelope * GetEnvelope()
Definition: WaveClip.h:243
int GetRate() const
Definition: WaveClip.h:210
void WaveClip::Lock ( )

Lock all blockfiles.

Definition at line 1869 of file WaveClip.cpp.

Referenced by WaveTrack::Lock().

1870 {
1871  GetSequence()->Lock();
1872  for (const auto &cutline: mCutLines)
1873  cutline->Lock();
1874 }
Sequence * GetSequence()
Definition: WaveClip.h:250
WaveClipHolders mCutLines
Definition: WaveClip.h:390
bool Lock()
Definition: Sequence.cpp:93
void WaveClip::MarkChanged ( )
inline

WaveTrack calls this whenever data in the wave clip changes. It is called automatically when WaveClip has a chance to know that something has changed, like when member functions SetSamples() etc. are called.

Definition at line 255 of file WaveClip.h.

Referenced by TimeShiftHandle::Release(), WaveTrack::Set(), and WaveTrack::Silence().

256  { mDirty++; }
int mDirty
Definition: WaveClip.h:376
size_t WaveClip::NumCutLines ( ) const
inline

Definition at line 317 of file WaveClip.h.

Referenced by WaveTrack::UpdateLocationsCache().

317 { return mCutLines.size(); }
WaveClipHolders mCutLines
Definition: WaveClip.h:390
void WaveClip::Offset ( double  delta)
inline
void WaveClip::OffsetCutLines ( double  t0,
double  len 
)

Offset cutlines right to time 't0' by time amount 'len'.

Definition at line 1859 of file WaveClip.cpp.

1861 {
1862  for (const auto &cutLine : mCutLines)
1863  {
1864  if (mOffset + cutLine->GetOffset() >= t0)
1865  cutLine->Offset(len);
1866  }
1867 }
double mOffset
Definition: WaveClip.h:374
WaveClipHolders mCutLines
Definition: WaveClip.h:390
WaveClip& WaveClip::operator= ( const WaveClip )
private
void WaveClip::Paste ( double  t0,
const WaveClip other 
)

Paste data from other clip, resampling it if not equal rate.

Definition at line 1579 of file WaveClip.cpp.

References sampleCount::as_double(), ConvertToSampleFormat(), GetEndTime(), GetStartTime(), mCutLines, mEnvelope, mRate, mSequence, Offset(), and Resample().

Referenced by WaveTrack::Join(), WaveTrack::MergeClips(), and WaveTrack::Paste().

1581 {
1582  const bool clipNeedsResampling = other->mRate != mRate;
1583  const bool clipNeedsNewFormat =
1584  other->mSequence->GetSampleFormat() != mSequence->GetSampleFormat();
1585  std::unique_ptr<WaveClip> newClip;
1586  const WaveClip* pastedClip;
1587 
1588  if (clipNeedsResampling || clipNeedsNewFormat)
1589  {
1590  newClip =
1591  std::make_unique<WaveClip>(*other, mSequence->GetDirManager(), true);
1592  if (clipNeedsResampling)
1593  // The other clip's rate is different from ours, so resample
1594  newClip->Resample(mRate);
1595  if (clipNeedsNewFormat)
1596  // Force sample formats to match.
1597  newClip->ConvertToSampleFormat(mSequence->GetSampleFormat());
1598  pastedClip = newClip.get();
1599  }
1600  else
1601  {
1602  // No resampling or format change needed, just use original clip without making a copy
1603  pastedClip = other;
1604  }
1605 
1606  // Paste cut lines contained in pasted clip
1607  WaveClipHolders newCutlines;
1608  for (const auto &cutline: pastedClip->mCutLines)
1609  {
1610  newCutlines.push_back(
1611  std::make_unique<WaveClip>
1612  ( *cutline, mSequence->GetDirManager(),
1613  // Recursively copy cutlines of cutlines. They don't need
1614  // their offsets adjusted.
1615  true));
1616  newCutlines.back()->Offset(t0 - mOffset);
1617  }
1618 
1619  sampleCount s0;
1620  TimeToSamplesClip(t0, &s0);
1621 
1622  // Assume STRONG-GUARANTEE from Sequence::Paste
1623  mSequence->Paste(s0, pastedClip->mSequence.get());
1624 
1625  // Assume NOFAIL-GUARANTEE in the remaining
1626  MarkChanged();
1627  auto sampleTime = 1.0 / GetRate();
1628  mEnvelope->Paste
1629  (s0.as_double()/mRate + mOffset, pastedClip->mEnvelope.get(), sampleTime);
1630  OffsetCutLines(t0, pastedClip->GetEndTime() - pastedClip->GetStartTime());
1631 
1632  for (auto &holder : newCutlines)
1633  mCutLines.push_back(std::move(holder));
1634 }
void TimeToSamplesClip(double t0, sampleCount *s0) const
Definition: WaveClip.cpp:1367
double mOffset
Definition: WaveClip.h:374
double GetStartTime() const
Definition: WaveClip.cpp:421
void Offset(double delta)
Definition: WaveClip.h:223
void MarkChanged()
Definition: WaveClip.h:255
WaveClipHolders mCutLines
Definition: WaveClip.h:390
int mRate
Definition: WaveClip.h:375
double as_double() const
Definition: Types.h:88
void Resample(int rate, ProgressDialog *progress=NULL)
Definition: WaveClip.cpp:1898
std::vector< WaveClipHolder > WaveClipHolders
Definition: WaveClip.h:122
void OffsetCutLines(double t0, double len)
Offset cutlines right to time 't0' by time amount 'len'.
Definition: WaveClip.cpp:1859
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
void ConvertToSampleFormat(sampleFormat format)
Definition: WaveClip.cpp:1350
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:176
int GetRate() const
Definition: WaveClip.h:210
double GetEndTime() const
Definition: WaveClip.cpp:427
bool WaveClip::RemoveCutLine ( double  cutLinePosition)

Remove cut line, without expanding the audio in it.

Definition at line 1844 of file WaveClip.cpp.

Referenced by WaveTrack::RemoveCutLine().

1845 {
1846  for (auto it = mCutLines.begin(); it != mCutLines.end(); ++it)
1847  {
1848  const auto &cutline = *it;
1849  if (fabs(mOffset + cutline->GetOffset() - cutLinePosition) < 0.0001)
1850  {
1851  mCutLines.erase(it); // deletes cutline!
1852  return true;
1853  }
1854  }
1855 
1856  return false;
1857 }
double mOffset
Definition: WaveClip.h:374
WaveClipHolders mCutLines
Definition: WaveClip.h:390
void WaveClip::Resample ( int  rate,
ProgressDialog progress = NULL 
)

We want to keep going as long as we have something to feed the resampler with OR as long as the resampler spews out samples (which could continue for a few iterations after we stop feeding it)

Definition at line 1898 of file WaveClip.cpp.

References _(), sampleCount::as_long_long(), floatSample, limitSampleBufferSize(), Resample::Process(), WaveCache::rate, Success, and ProgressDialog::Update().

Referenced by Paste(), TimeShiftHandle::Release(), and WaveTrack::Resample().

1900 {
1901  // Note: it is not necessary to do this recursively to cutlines.
1902  // They get resampled as needed when they are expanded.
1903 
1904  if (rate == mRate)
1905  return; // Nothing to do
1906 
1907  double factor = (double)rate / (double)mRate;
1908  ::Resample resample(true, factor, factor); // constant rate resampling
1909 
1910  const size_t bufsize = 65536;
1911  Floats inBuffer{ bufsize };
1912  Floats outBuffer{ bufsize };
1913  sampleCount pos = 0;
1914  bool error = false;
1915  int outGenerated = 0;
1916  auto numSamples = mSequence->GetNumSamples();
1917 
1918  auto newSequence =
1919  std::make_unique<Sequence>(mSequence->GetDirManager(), mSequence->GetSampleFormat());
1920 
1926  while (pos < numSamples || outGenerated > 0)
1927  {
1928  const auto inLen = limitSampleBufferSize( bufsize, numSamples - pos );
1929 
1930  bool isLast = ((pos + inLen) == numSamples);
1931 
1932  if (!mSequence->Get((samplePtr)inBuffer.get(), floatSample, pos, inLen, true))
1933  {
1934  error = true;
1935  break;
1936  }
1937 
1938  const auto results = resample.Process(factor, inBuffer.get(), inLen, isLast,
1939  outBuffer.get(), bufsize);
1940  outGenerated = results.second;
1941 
1942  pos += results.first;
1943 
1944  if (outGenerated < 0)
1945  {
1946  error = true;
1947  break;
1948  }
1949 
1950  newSequence->Append((samplePtr)outBuffer.get(), floatSample,
1951  outGenerated);
1952 
1953  if (progress)
1954  {
1955  auto updateResult = progress->Update(
1956  pos.as_long_long(),
1957  numSamples.as_long_long()
1958  );
1959  error = (updateResult != ProgressResult::Success);
1960  if (error)
1961  throw UserException{};
1962  }
1963  }
1964 
1965  if (error)
1967  _("Resampling failed.")
1968  };
1969  else
1970  {
1971  // Use NOFAIL-GUARANTEE in these steps
1972 
1973  // Invalidate wave display cache
1974  mWaveCache = std::make_unique<WaveCache>();
1975  // Invalidate the spectrum display cache
1976  mSpecCache = std::make_unique<SpecCache>();
1977 
1978  mSequence = std::move(newSequence);
1979  mRate = rate;
1980  }
1981 }
int mRate
Definition: WaveClip.h:375
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
std::unique_ptr< WaveCache > mWaveCache
Definition: WaveClip.h:382
char * samplePtr
Definition: Types.h:203
ProgressResult Update(int value, const wxString &message=wxEmptyString)
std::unique_ptr< SpecCache > mSpecCache
Definition: WaveClip.h:384
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Interface to libsoxr.
Definition: Resample.h:32
void WaveClip::SetColourIndex ( int  index)
inline

Definition at line 219 of file WaveClip.h.

Referenced by SetClipCommand::ApplyInner().

219 { mColourIndex = index;};
int mColourIndex
Definition: WaveClip.h:377
void WaveClip::SetDisplayRect ( const wxRect &  r) const

Definition at line 1383 of file WaveClip.cpp.

Referenced by TrackArtist::DrawClipSpectrum(), and TrackArtist::DrawClipWaveform().

1384 {
1385  mDisplayRect = r;
1386 }
wxRect mDisplayRect
Definition: WaveClip.h:372
void WaveClip::SetIsPlaceholder ( bool  val)
inline

Definition at line 362 of file WaveClip.h.

362 { mIsPlaceholder = val; }
bool mIsPlaceholder
Definition: WaveClip.h:393
void WaveClip::SetOffset ( double  offset)

Definition at line 392 of file WaveClip.cpp.

Referenced by SetClipCommand::ApplyInner(), WaveTrack::ClearAndPaste(), WaveTrack::HandleXMLChild(), WaveTrack::Join(), WaveTrack::NewestOrNewClip(), and WaveTrack::RightmostOrNewClip().

394 {
395  mOffset = offset;
396  mEnvelope->SetOffset(mOffset);
397 }
double mOffset
Definition: WaveClip.h:374
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
void WaveClip::SetRate ( int  rate)

Definition at line 1890 of file WaveClip.cpp.

References WaveCache::rate.

1891 {
1892  mRate = rate;
1893  auto newLength = mSequence->GetNumSamples().as_double() / mRate;
1894  mEnvelope->RescaleTimes( newLength );
1895  MarkChanged();
1896 }
void MarkChanged()
Definition: WaveClip.h:255
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void WaveClip::SetSamples ( samplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len 
)

Definition at line 405 of file WaveClip.cpp.

Referenced by WaveTrack::Set().

408 {
409  // use STRONG-GUARANTEE
410  mSequence->SetSamples(buffer, format, start, len);
411 
412  // use NOFAIL-GUARANTEE
413  MarkChanged();
414 }
void MarkChanged()
Definition: WaveClip.h:255
int format
Definition: ExportPCM.cpp:56
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
bool WaveClip::SharesBoundaryWithNextClip ( const WaveClip next) const

Definition at line 1987 of file WaveClip.cpp.

References GetOffset(), and GetRate().

1988 {
1989  double endThis = GetRate() * GetOffset() + GetNumSamples().as_double();
1990  double startNext = next->GetRate() * next->GetOffset();
1991 
1992  // given that a double has about 15 significant digits, using a criterion
1993  // of half a sample should be safe in all normal usage.
1994  return fabs(startNext - endThis) < 0.5;
1995 }
sampleCount GetNumSamples() const
Definition: WaveClip.cpp:448
double as_double() const
Definition: Types.h:88
double GetOffset() const
Definition: WaveClip.h:222
int GetRate() const
Definition: WaveClip.h:210
void WaveClip::TimeToSamplesClip ( double  t0,
sampleCount s0 
) const

Definition at line 1367 of file WaveClip.cpp.

Referenced by WaveTrack::Disjoin(), WaveTrack::GetRMS(), and WaveClip().

1368 {
1369  if (t0 < mOffset)
1370  *s0 = 0;
1371  else if (t0 > mOffset + mSequence->GetNumSamples().as_double()/mRate)
1372  *s0 = mSequence->GetNumSamples();
1373  else
1374  *s0 = sampleCount( floor(((t0 - mOffset) * mRate) + 0.5) );
1375 }
double mOffset
Definition: WaveClip.h:374
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
void WaveClip::Unlock ( )

Unlock all blockfiles.

Definition at line 1883 of file WaveClip.cpp.

Referenced by WaveTrack::Unlock().

1884 {
1885  GetSequence()->Unlock();
1886  for (const auto &cutline: mCutLines)
1887  cutline->Unlock();
1888 }
bool Unlock()
Definition: Sequence.cpp:109
Sequence * GetSequence()
Definition: WaveClip.h:250
WaveClipHolders mCutLines
Definition: WaveClip.h:390
void WaveClip::UpdateEnvelopeTrackLen ( )

Whenever you do an operation to the sequence that will change the number of samples (that is, the length of the clip), you will want to call this function to tell the envelope about it.

Definition at line 1360 of file WaveClip.cpp.

Referenced by RecordingRecoveryHandler::HandleXMLTag().

1362 {
1363  mEnvelope->SetTrackLen
1364  ((mSequence->GetNumSamples().as_double()) / mRate, 1.0 / GetRate());
1365 }
int mRate
Definition: WaveClip.h:375
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
int GetRate() const
Definition: WaveClip.h:210
bool WaveClip::WithinClip ( double  t) const

Definition at line 453 of file WaveClip.cpp.

Referenced by WaveTrack::InsertSilence(), and WaveTrack::Paste().

454 {
455  auto ts = (sampleCount)floor(t * mRate + 0.5);
456  return ts > GetStartSample() && ts < GetEndSample() + mAppendBufferLen;
457 }
int mRate
Definition: WaveClip.h:375
sampleCount GetEndSample() const
Definition: WaveClip.cpp:443
size_t mAppendBufferLen
Definition: WaveClip.h:386
sampleCount GetStartSample() const
Definition: WaveClip.cpp:438
void WaveClip::WriteXML ( XMLWriter xmlFile) const

Definition at line 1563 of file WaveClip.cpp.

Referenced by WaveTrack::WriteXML().

1565 {
1566  xmlFile.StartTag(wxT("waveclip"));
1567  xmlFile.WriteAttr(wxT("offset"), mOffset, 8);
1568  xmlFile.WriteAttr(wxT("colorindex"), mColourIndex );
1569 
1570  mSequence->WriteXML(xmlFile);
1571  mEnvelope->WriteXML(xmlFile);
1572 
1573  for (const auto &clip: mCutLines)
1574  clip->WriteXML(xmlFile);
1575 
1576  xmlFile.EndTag(wxT("waveclip"));
1577 }
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:78
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:101
double mOffset
Definition: WaveClip.h:374
WaveClipHolders mCutLines
Definition: WaveClip.h:390
std::unique_ptr< Envelope > mEnvelope
Definition: WaveClip.h:380
std::unique_ptr< Sequence > mSequence
Definition: WaveClip.h:379
int mColourIndex
Definition: WaveClip.h:377

Member Data Documentation

SampleBuffer WaveClip::mAppendBuffer {}
protected

Definition at line 385 of file WaveClip.h.

size_t WaveClip::mAppendBufferLen { 0 }
protected

Definition at line 386 of file WaveClip.h.

int WaveClip::mColourIndex
protected

Definition at line 377 of file WaveClip.h.

Referenced by WaveClip().

WaveClipHolders WaveClip::mCutLines {}
protected

Definition at line 390 of file WaveClip.h.

Referenced by Paste(), and WaveClip().

int WaveClip::mDirty { 0 }
protected

Definition at line 376 of file WaveClip.h.

wxRect WaveClip::mDisplayRect {}
mutableprotected

Definition at line 372 of file WaveClip.h.

std::unique_ptr<Envelope> WaveClip::mEnvelope
protected

Definition at line 380 of file WaveClip.h.

Referenced by Paste(), and WaveClip().

bool WaveClip::mIsPlaceholder { false }
protected

Definition at line 393 of file WaveClip.h.

double WaveClip::mOffset { 0 }
protected

Definition at line 374 of file WaveClip.h.

Referenced by WaveClip().

int WaveClip::mRate
protected

Definition at line 375 of file WaveClip.h.

Referenced by Paste(), and WaveClip().

std::unique_ptr<Sequence> WaveClip::mSequence
protected

Definition at line 379 of file WaveClip.h.

Referenced by Paste(), and WaveClip().

std::unique_ptr<SpecCache> WaveClip::mSpecCache
mutableprotected

Definition at line 384 of file WaveClip.h.

std::unique_ptr<SpecPxCache> WaveClip::mSpecPxCache
mutable

Definition at line 369 of file WaveClip.h.

Referenced by TrackArtist::DrawClipSpectrum().

std::unique_ptr<WaveCache> WaveClip::mWaveCache
mutableprotected

Definition at line 382 of file WaveClip.h.

ODLock WaveClip::mWaveCacheMutex {}
mutableprotected

Definition at line 383 of file WaveClip.h.


The documentation for this class was generated from the following files: