49 mEnvelope = std::make_unique<Envelope>(
true, 1e-7, 2.0, 1.0);
74 ( std::make_unique<WaveClip>( *clip,
factory,
true ) );
115 for (
const auto &cutline : orig.
mCutLines)
125 sampleCount start,
size_t len,
bool mayThrow)
const
168 double t0,
double t1,
bool mayThrow)
const
187 return mSequence->GetMinMax(s0, s1-s0, mayThrow);
204 return mSequence->GetRMS(s0, s1-s0, mayThrow);
208 const std::function<
void(
size_t)> & progressReport)
213 auto bChanged =
mSequence->ConvertToSampleFormat(
format, progressReport);
243 size_t len,
unsigned int stride,
sampleFormat effectiveFormat)
246 auto cleanup =
finally( [&] {
252 return mSequence->Append(buffer,
format, len, stride, effectiveFormat);
268 auto cleanup =
finally( [&] {
281 if (tag ==
"waveclip")
285 for (
auto pair : attrs)
287 auto attr = pair.first;
288 auto value = pair.second;
290 if (attr ==
"offset")
292 if (!value.TryGet(dblValue))
296 else if (attr ==
"trimLeft")
298 if (!value.TryGet(dblValue))
302 else if (attr ==
"trimRight")
304 if (!value.TryGet(dblValue))
308 else if (attr ==
"name")
310 if(value.IsStringView())
313 else if (attr ==
"colorindex")
315 if (!value.TryGet(longValue))
328 if (tag ==
"waveclip")
334 if (tag ==
"sequence")
336 else if (tag ==
"envelope")
338 else if (tag ==
"waveclip")
346 std::make_unique<WaveClip>(
mSequence->GetFactory(),
357 xmlFile.StartTag(
wxT(
"waveclip"));
358 xmlFile.WriteAttr(
wxT(
"offset"), mSequenceOffset, 8);
359 xmlFile.WriteAttr(
wxT(
"trimLeft"), mTrimLeft, 8);
360 xmlFile.WriteAttr(
wxT(
"trimRight"), mTrimRight, 8);
361 xmlFile.WriteAttr(
wxT(
"name"), mName);
362 xmlFile.WriteAttr(
wxT(
"colorindex"), mColourIndex );
364 mSequence->WriteXML(xmlFile);
365 mEnvelope->WriteXML(xmlFile);
367 for (
const auto &clip: mCutLines)
368 clip->WriteXML(xmlFile);
370 xmlFile.EndTag(
wxT(
"waveclip"));
376 const bool clipNeedsResampling = other->
mRate !=
mRate;
377 const bool clipNeedsNewFormat =
378 other->
mSequence->GetSampleFormats().Stored()
379 !=
mSequence->GetSampleFormats().Stored();
380 std::unique_ptr<WaveClip> newClip;
390 auto copy = std::make_unique<WaveClip>(*other,
mSequence->GetFactory(),
true);
391 copy->ClearSequence(copy->GetPlayEndTime(), copy->GetSequenceEndTime());
392 newClip = std::move(copy);
399 auto copy = std::make_unique<WaveClip>(*other,
mSequence->GetFactory(),
true);
400 copy->ClearSequence(copy->GetSequenceStartTime(), copy->GetPlayStartTime());
401 newClip = std::move(copy);
405 newClip = std::make_unique<WaveClip>(*other,
mSequence->GetFactory(),
true);
406 newClip->ClearSequence(newClip->GetPlayEndTime(), newClip->GetSequenceEndTime());
407 newClip->ClearSequence(newClip->GetSequenceStartTime(), newClip->GetPlayStartTime());
408 newClip->SetTrimLeft(0);
409 newClip->SetTrimRight(0);
412 if (clipNeedsResampling || clipNeedsNewFormat)
414 auto copy = std::make_unique<WaveClip>(*newClip.get(),
mSequence->GetFactory(),
true);
415 if (clipNeedsResampling)
417 copy->Resample(
mRate);
418 if (clipNeedsNewFormat)
420 copy->ConvertToSampleFormat(
mSequence->GetSampleFormats().Stored());
421 newClip = std::move(copy);
426 for (
const auto &cutline: newClip->mCutLines)
428 auto cutlineCopy = std::make_unique<WaveClip>(*cutline,
mSequence->GetFactory(),
433 newCutlines.push_back(std::move(cutlineCopy));
439 mSequence->Paste(s0, newClip->mSequence.get());
443 auto sampleTime = 1.0 /
GetRate();
446 OffsetCutLines(t0, newClip->GetPlayEndTime() - newClip->GetPlayStartTime());
448 for (
auto &holder : newCutlines)
471 const auto sampleTime = 1.0 /
GetRate();
473 if ( pEnvelopeValue ) {
476 auto oldLen = pEnvelope->GetTrackLen();
477 auto newLen = oldLen + len;
478 pEnvelope->Cap( sampleTime );
481 pEnvelope->SetTrackLen( newLen, sampleTime );
482 pEnvelope->InsertOrReplace
483 ( pEnvelope->GetOffset() + newLen, *pEnvelopeValue );
486 pEnvelope->InsertSpace( t, len );
574 if (cutlinePosition >= t0 && cutlinePosition <= t1)
581 if (cutlinePosition >= t1)
583 clip->
Offset(clip_t0 - clip_t1);
590 auto sampleTime = 1.0 /
GetRate();
609 auto newClip = std::make_unique< WaveClip >
610 (*
this,
mSequence->GetFactory(),
true, clip_t0, clip_t1);
621 if (cutlinePosition >= t0 && cutlinePosition <= t1)
625 if (cutlinePosition >= t1)
627 clip->
Offset(clip_t0 - clip_t1);
641 auto sampleTime = 1.0 /
GetRate();
650 double* cutlineStart ,
651 double* cutlineEnd )
const
659 *cutlineStart = startTime;
661 *cutlineEnd = startTime + cutline->SamplesToTime(cutline->GetPlaySamplesCount());
675 return fabs(GetSequenceStartTime() + cutline->GetSequenceStartTime() - cutLinePosition) < 0.0001;
679 auto cutline = it->get();
684 cutline->mEnvelope->SetOffset(0);
706 const auto &cutline = *it;
724 cutLine->Offset(len);
732 cutline->CloseLock();
756 double factor = (double)rate / (
double)
mRate;
759 const size_t bufsize = 65536;
760 Floats inBuffer{ bufsize };
761 Floats outBuffer{ bufsize };
764 int outGenerated = 0;
765 auto numSamples =
mSequence->GetNumSamples();
768 auto newSequence = std::make_unique<Sequence>(
776 while (pos < numSamples || outGenerated > 0)
780 bool isLast = ((pos + inLen) == numSamples);
788 const auto results = resample.
Process(factor, inBuffer.get(), inLen, isLast,
789 outBuffer.get(), bufsize);
790 outGenerated = results.second;
792 pos += results.first;
794 if (outGenerated < 0)
807 auto updateResult = progress->
Poll(
809 numSamples.as_long_long()
820 XO(
"Resampling failed."),
844 return fabs(startNext - endThis) < 0.5;
864 return s.as_double() / mRate;
890 auto numSamples =
mSequence->GetNumSamples();
970 auto numSamples =
mSequence->GetNumSamples();
991 SetSequenceStartTime(GetSequenceStartTime() + delta);
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
const TranslatableString name
MessageBoxException for violation of preconditions or assertions.
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
An AudacityException with no visible message.
std::shared_ptr< WaveClip > WaveClipHolder
std::vector< WaveClipHolder > WaveClipHolders
std::vector< Attribute > AttributesList
Abstraction of a progress dialog with well defined time-to-completion estimate.
virtual ProgressResult Poll(unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
Update the bar and poll for clicks. Call only on the main thread.
void CollapseRegion(double t0, double t1, double sampleDur)
std::pair< size_t, size_t > Process(double factor, float *inBuffer, size_t inBufferLen, bool lastFlag, float *outBuffer, size_t outBufferLen)
Main processing function. Resamples from the input buffer to the output buffer.
size_t GetAppendBufferLen() const
void Delete(sampleCount start, sampleCount len)
void InsertSilence(sampleCount s0, sampleCount len)
void SetSilence(sampleCount s0, sampleCount len)
constSamplePtr GetAppendBuffer() const
A MessageBoxException that shows a given, unvarying string.
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
This allows multiple clips to be a part of one WaveTrack.
bool WithinPlayRegion(double t) const
sampleCount GetSequenceEndSample() const
Returns the index of the sample next after the last sample of the underlying sequence.
constSamplePtr GetAppendBuffer() const
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
void ClearRight(double t)
bool BeforePlayStartTime(double t) const
double GetSequenceStartTime() const noexcept
void SetPlayStartTime(double time)
void Resample(int rate, BasicUI::ProgressDialog *progress=NULL)
void SetSequenceStartTime(double startTime)
BlockArray * GetSequenceBlockArray()
void SetName(const wxString &name)
bool RemoveCutLine(double cutLinePosition)
Remove cut line, without expanding the audio in it.
sampleCount TimeToSequenceSamples(double t) const
std::unique_ptr< Sequence > mSequence
bool Append(constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride, sampleFormat effectiveFormat)
double GetPlayStartTime() const noexcept
std::unique_ptr< Envelope > mEnvelope
double GetTrimRight() const noexcept
Returns the play end offset in seconds from the ending of the underlying sequence.
std::shared_ptr< SampleBlock > AppendNewBlock(samplePtr buffer, sampleFormat format, size_t len)
For use in importing pre-version-3 projects to preserve sharing of blocks; no dithering applied.
double GetTrimLeft() const noexcept
Returns the play start offset in seconds from the beginning of the underlying sequence.
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
sampleCount CountSamples(double t0, double t1) const
WaveClip(const WaveClip &) PROHIBITED
sampleCount GetPlayEndSample() const
const wxString & GetName() const
bool AfterPlayEndTime(double t) const
void TrimLeftTo(double to)
Sets the the left trimming to the absolute time (if that is in bounds)
bool FindCutLine(double cutLinePosition, double *cutLineStart=NULL, double *cutLineEnd=NULL) const
sampleCount GetPlayStartSample() const
void AppendSilence(double len, double envelopeValue)
void Paste(double t0, const WaveClip *other)
Paste data from other clip, resampling it if not equal rate.
sampleCount ToSequenceSamples(sampleCount s) const
sampleCount GetSequenceStartSample() const
Returns the index of the first sample of the underlying sequence.
bool GetIsPlaceholder() const
void HandleXMLEndTag(const std::string_view &tag) override
void InsertSilence(double t, double len, double *pEnvelopeValue=nullptr)
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
float GetRMS(double t0, double t1, bool mayThrow=true) const
void SetColourIndex(int index)
void SetSilence(sampleCount offset, sampleCount length)
Silences the 'length' amount of samples starting from 'offset'(relative to the play start)
double GetPlayEndTime() const
bool GetSamples(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
sampleCount TimeToSamples(double time) const noexcept
void TrimRightTo(double to)
Sets the the right trimming to the absolute time (if that is in bounds)
bool SharesBoundaryWithNextClip(const WaveClip *next) const
void OffsetCutLines(double t0, double len)
Offset cutlines right to time 't0' by time amount 'len'.
void SetTrimRight(double trim)
Sets the play end offset in seconds from the ending of the underlying sequence.
void TrimRight(double deltaTime)
Moves play end position by deltaTime.
void Offset(double delta) noexcept
double SamplesToTime(sampleCount s) const noexcept
sampleCount GetPlaySamplesCount() const
void WriteXML(XMLWriter &xmlFile) const
sampleCount GetSequenceSamplesCount() const
Returns the total number of samples in underlying sequence (not counting the cutlines)
void ExpandCutLine(double cutLinePosition)
void AppendSharedBlock(const std::shared_ptr< SampleBlock > &pBlock)
For use in importing pre-version-3 projects to preserve sharing of blocks.
void ConvertToSampleFormat(sampleFormat format, const std::function< void(size_t)> &progressReport={})
void ClearSequence(double t0, double t1)
void SetSamples(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat)
void ClearAndAddCutLine(double t0, double t1)
WaveClipHolders mCutLines
void SetTrimLeft(double trim)
Sets the play start offset in seconds from the beginning of the underlying sequence.
double GetSequenceEndTime() const
void Clear(double t0, double t1)
void UpdateEnvelopeTrackLen()
size_t GetAppendBufferLen() const
void Flush()
Flush must be called after last Append.
void TrimLeft(double deltaTime)
Moves play start position by deltaTime.
This class is an interface which should be implemented by classes which wish to be able to load and s...
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Positions or offsets within audio files need a wide type.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
static RegisteredToolbarFactory factory
virtual void MarkChanged()=0
virtual ~WaveClipListener()=0
virtual void Invalidate()=0