Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EffectTruncSilence Class Referencefinal

Truncate Silence automatically reduces the length of passages where the volume is below a set threshold level. More...

#include <TruncSilence.h>

Inheritance diagram for EffectTruncSilence:
[legend]
Collaboration diagram for EffectTruncSilence:
[legend]

Public Member Functions

 EffectTruncSilence ()
 
virtual ~EffectTruncSilence ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 
bool Analyze (RegionList &silenceList, RegionList &trackSilences, const WaveTrack &wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=nullptr, double *minInputLength=nullptr) const
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 
std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
bool NeedsDither () const override
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatID GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

Static Public Member Functions

static EffectTruncSilenceFetchParameters (EffectTruncSilence &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
- Static Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public Member Functions inherited from EffectUIServices
static int DoMessageBox (const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Truncate Silence") }
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Types

enum  kActions { kTruncate , kCompress , nActions }
 

Private Member Functions

void Intersect (RegionList &dest, const RegionList &src)
 
void OnControlChange (wxCommandEvent &evt)
 
void UpdateUI ()
 
bool ProcessIndependently ()
 
bool ProcessAll ()
 
bool FindSilences (RegionList &silences, const TrackIterRange< const WaveTrack > &range)
 
bool DoRemoval (const RegionList &silences, const TrackIterRange< Track > &range, unsigned iGroup, unsigned nGroups, double &totalCutLen)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent {}
 
double mThresholdDB {}
 
int mActionIndex
 
double mInitialAllowedSilence
 
double mTruncLongestAllowedSilence
 
double mSilenceCompressPercent
 
bool mbIndependent
 
size_t mBlendFrameCount
 
wxTextCtrl * mThresholdText
 
wxChoice * mActionChoice
 
wxTextCtrl * mInitialAllowedSilenceT
 
wxTextCtrl * mTruncLongestAllowedSilenceT
 
wxTextCtrl * mSilenceCompressPercentT
 
wxCheckBox * mIndependent
 

Static Private Attributes

static const EnumValueSymbol kActionStrings [nActions]
 
static constexpr EffectParameter Threshold
 
static constexpr EnumParameter ActIndex
 
static constexpr EffectParameter Minimum
 
static constexpr EffectParameter Truncate
 
static constexpr EffectParameter Compress
 
static constexpr EffectParameter Independent
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Detailed Description

Truncate Silence automatically reduces the length of passages where the volume is below a set threshold level.

Definition at line 32 of file TruncSilence.h.

Member Enumeration Documentation

◆ kActions

Enumerator
kTruncate 
kCompress 
nActions 

Definition at line 125 of file TruncSilence.h.

Constructor & Destructor Documentation

◆ EffectTruncSilence()

EffectTruncSilence::EffectTruncSilence ( )

Definition at line 116 of file TruncSilence.cpp.

117{
118 Parameters().Reset(*this);
119
120 SetLinearEffectFlag(false);
121
122 // This used to be changeable via the audacity.cfg/registry. Doubtful that was
123 // ever done.
124 //
125 // Original comment:
126 //
127 // mBlendFrameCount only retrieved from prefs ... not using dialog
128 // Only way to change (for windows) is thru registry
129 // The values should be figured dynamically ... too many frames could be invalid
131}
static const size_t DEF_BlendFrameCount
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:215
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override

References DEF_BlendFrameCount.

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectTruncSilence()

EffectTruncSilence::~EffectTruncSilence ( )
virtual

Definition at line 133 of file TruncSilence.cpp.

134{
135}

Member Function Documentation

◆ Analyze()

bool EffectTruncSilence::Analyze ( RegionList silenceList,
RegionList trackSilences,
const WaveTrack wt,
sampleCount silentFrame,
sampleCount index,
int  whichTrack,
double *  inputLength = nullptr,
double *  minInputLength = nullptr 
) const
Precondition
wt.IsLeader()

Definition at line 518 of file TruncSilence.cpp.

522{
523 assert(wt.IsLeader());
524 const auto rate = wt.GetRate();
525
526 // Smallest silent region to detect in frames
527 auto minSilenceFrames =
529
530 double truncDbSilenceThreshold = DB_TO_LINEAR(mThresholdDB);
531 auto blockLen = wt.GetMaxBlockSize();
532 auto start = wt.TimeToLongSamples(mT0);
533 auto end = wt.TimeToLongSamples(mT1);
534 sampleCount outLength = 0;
535
536 double previewLength;
537 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
538 // Minimum required length in samples.
539 const sampleCount previewLen(previewLength * rate);
540
541 // Keep position in overall silences list for optimization
542 RegionList::iterator rit(silenceList.begin());
543
544 // Allocate buffers
545 Floats buffers[] {
546 Floats{ blockLen },
547 Floats{ blockLen }
548 };
549
550 // Loop through current track
551 while (*index < end) {
552 if (inputLength && ((outLength >= previewLen) ||
553 (*index - start > wt.TimeToLongSamples(*minInputLength)))
554 ) {
555 *inputLength = std::min<double>(*inputLength, *minInputLength);
556 if (outLength >= previewLen) {
557 *minInputLength = *inputLength;
558 }
559 return true;
560 }
561
562 if (!inputLength) {
563 // Show progress dialog, test for cancellation
564 bool cancelled = TotalProgress(
565 detectFrac * (whichTrack +
566 (*index - start).as_double() /
567 (end - start).as_double()) /
568 (double)GetNumWaveTracks());
569 if (cancelled)
570 return false;
571 }
572
573 // Optimization: if not in a silent region skip ahead to the next one
574
575 double curTime = wt.LongSamplesToTime(*index);
576 for ( ; rit != silenceList.end(); ++rit) {
577 // Find the first silent region ending after current time
578 if (rit->end >= curTime) {
579 break;
580 }
581 }
582
583 if (rit == silenceList.end()) {
584 // No more regions -- no need to process the rest of the track
585 if (inputLength) {
586 // Add available samples up to previewLength.
587 auto remainingTrackSamples =
588 wt.TimeToLongSamples(wt.GetEndTime()) - *index;
589 auto requiredTrackSamples = previewLen - outLength;
590 outLength += (remainingTrackSamples > requiredTrackSamples)
591 ? requiredTrackSamples
592 : remainingTrackSamples;
593 }
594
595 break;
596 }
597 else if (rit->start > curTime) {
598 // End current silent region, skip ahead
599 if (*silentFrame >= minSilenceFrames) {
600 trackSilences.push_back(Region(
601 wt.LongSamplesToTime(*index - *silentFrame),
602 wt.LongSamplesToTime(*index)
603 ));
604 }
605 *silentFrame = 0;
606 auto newIndex = wt.TimeToLongSamples(rit->start);
607 if (inputLength) {
608 auto requiredTrackSamples = previewLen - outLength;
609 // Add non-silent sample to outLength
610 outLength += ((newIndex - *index) > requiredTrackSamples)
611 ? requiredTrackSamples
612 : newIndex - *index;
613 }
614
615 *index = newIndex;
616 }
617 // End of optimization
618
619 // Limit size of current block if we've reached the end
620 auto count = limitSampleBufferSize( blockLen, end - *index );
621
622 // Fill buffers
623 size_t iChannel = 0;
624 for (const auto pChannel : wt.Channels())
625 pChannel->GetFloats(buffers[iChannel++].get(), *index, count);
626
627 // Look for silenceList in current block
628 for (decltype(count) i = 0; i < count; ++i) {
629 if (inputLength && ((outLength >= previewLen) ||
630 (outLength > wt.TimeToLongSamples(*minInputLength)))
631 ) {
632 *inputLength =
633 wt.LongSamplesToTime(*index + i) - wt.LongSamplesToTime(start);
634 break;
635 }
636
637 const bool silent = std::all_of(buffers, buffers + iChannel,
638 [&](const Floats &buffer){
639 return fabs(buffer[i]) < truncDbSilenceThreshold;
640 });
641 if (silent)
642 (*silentFrame)++;
643 else {
644 sampleCount allowed = 0;
645 if (*silentFrame >= minSilenceFrames) {
646 if (inputLength) {
647 switch (mActionIndex) {
648 case kTruncate:
649 outLength +=
651 break;
652 case kCompress:
653 allowed =
655 outLength += sampleCount(
656 allowed.as_double() +
657 (*silentFrame - allowed).as_double()
659 );
660 break;
661 // default: // Not currently used.
662 }
663 }
664
665 // Record the silent region
666 trackSilences.push_back(Region(
667 wt.LongSamplesToTime(*index + i - *silentFrame),
668 wt.LongSamplesToTime(*index + i)
669 ));
670 }
671 else if (inputLength) { // included as part of non-silence
672 outLength += *silentFrame;
673 }
674 *silentFrame = 0;
675 if (inputLength) {
676 ++outLength; // Add non-silent sample to outLength
677 }
678 }
679 }
680 // Next block
681 *index += count;
682 }
683
684 if (inputLength) {
685 *inputLength = std::min<double>(*inputLength, *minInputLength);
686 if (outLength >= previewLen) {
687 *minInputLength = *inputLength;
688 }
689 }
690
691 return true;
692}
wxT("CloseDown"))
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:335
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
WaveTrack::Region Region
const double detectFrac
static const double DEF_MinTruncMs
double mT1
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:115
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:335
int GetNumWaveTracks() const
Definition: Effect.h:139
double mInitialAllowedSilence
Definition: TruncSilence.h:108
double mSilenceCompressPercent
Definition: TruncSilence.h:110
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:109
auto Channels()
Definition: WaveTrack.h:277
bool IsLeader() const override
Definition: WaveTrack.cpp:2820
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:3092
double GetRate() const override
Definition: WaveTrack.cpp:1128
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:2741
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
virtual bool Read(const wxString &key, bool *value) const =0
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References sampleCount::as_double(), WaveTrack::Channels(), DB_TO_LINEAR, DEF_MinTruncMs, detectFrac, PackedArray::end(), WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), WaveTrack::GetRate(), gPrefs, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, WaveTrack::IsLeader(), kCompress, kTruncate, limitSampleBufferSize(), WideSampleSequence::LongSamplesToTime(), mActionIndex, mInitialAllowedSilence, mSilenceCompressPercent, EffectBase::mT0, EffectBase::mT1, mThresholdDB, mTruncLongestAllowedSilence, audacity::BasicSettings::Read(), WideSampleSequence::TimeToLongSamples(), Effect::TotalProgress(), and wxT().

Referenced by CalcPreviewInputLength(), and FindSilences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalcPreviewInputLength()

double EffectTruncSilence::CalcPreviewInputLength ( const EffectSettings settings,
double  previewLength 
) const
overridevirtual

Implements EffectBase.

Definition at line 204 of file TruncSilence.cpp.

206{
207 double inputLength = mT1 - mT0;
208 double minInputLength = inputLength;
209
210 // Master list of silent regions
211 RegionList silences;
212
213 // Start with the whole selection silent
214 silences.push_back(Region(mT0, mT1));
215
216 int whichTrack = 0;
217
218 for (auto wt : inputTracks()->Selected<const WaveTrack>()) {
219 RegionList trackSilences;
220
221 auto index = wt->TimeToLongSamples(mT0);
222 sampleCount silentFrame = 0; // length of the current silence
223
224 Analyze(silences, trackSilences, *wt, &silentFrame, &index, whichTrack,
225 &inputLength, &minInputLength);
226
227 whichTrack += wt->NChannels();
228 }
229 return inputLength;
230}
const TrackList * inputTracks() const
Definition: EffectBase.h:91
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack &wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=nullptr, double *minInputLength=nullptr) const

References Analyze(), EffectBase::inputTracks(), EffectBase::mT0, and EffectBase::mT1.

Here is the call graph for this function:

◆ DoRemoval()

bool EffectTruncSilence::DoRemoval ( const RegionList silences,
const TrackIterRange< Track > &  range,
unsigned  iGroup,
unsigned  nGroups,
double &  totalCutLen 
)
private
Precondition
range visits leaders only

Definition at line 382 of file TruncSilence.cpp.

386{
387 //
388 // Now remove the silent regions from all selected / sync-lock selected tracks.
389 //
390
391 // Loop over detected regions in reverse (so cuts don't change time values
392 // down the line)
393 int whichReg = 0;
394 RegionList::const_reverse_iterator rit;
395 for (rit = silences.rbegin(); rit != silences.rend(); ++rit)
396 {
397 const Region &region = *rit;
398 const Region *const r = &region;
399
400 // Progress dialog and cancellation. Do additional cleanup before return.
401 const double frac = detectFrac +
402 (1 - detectFrac) * (iGroup + whichReg / double(silences.size())) / nGroups;
403 if (TotalProgress(frac))
404 return false;
405
406 // Intersection may create regions smaller than allowed; ignore them.
407 // Allow one nanosecond extra for consistent results with exact milliseconds of allowed silence.
408 if ((r->end - r->start) < (mInitialAllowedSilence - 0.000000001))
409 continue;
410
411 // Find NEW silence length as requested
412 double inLength = r->end - r->start;
413 double outLength;
414
415 switch (mActionIndex)
416 {
417 case kTruncate:
418 outLength = std::min(mTruncLongestAllowedSilence, inLength);
419 break;
420 case kCompress:
421 outLength = mInitialAllowedSilence +
422 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0;
423 break;
424 default: // Not currently used.
425 outLength = std::min(mInitialAllowedSilence +
426 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0,
428 }
429
430 const double cutLen = std::max(0.0, inLength - outLength);
431 // Don't waste time cutting nothing.
432 if( cutLen == 0.0 )
433 continue;
434
435 totalCutLen += cutLen;
436
437 bool success = true;
438 double cutStart = (r->start + r->end - cutLen) / 2;
439 double cutEnd = cutStart + cutLen;
440 (range
442 - [&](const Track *pTrack) { return
443 // Don't waste time past the end of a track
444 pTrack->GetEndTime() < r->start;
445 }
446 ).VisitWhile(success,
447 [&](WaveTrack &wt) {
448 assert(wt.IsLeader());
449 // In WaveTracks, clear with a cross-fade
450 auto blendFrames = mBlendFrameCount;
451 // Round start/end times to frame boundaries
452 cutStart = wt.SnapToSample(cutStart);
453 cutEnd = wt.SnapToSample(cutEnd);
454
455 // Make sure the cross-fade does not affect non-silent frames
456 if (wt.LongSamplesToTime(blendFrames) > inLength) {
457 // Result is not more than blendFrames:
458 blendFrames = wt.TimeToLongSamples(inLength).as_size_t();
459 }
460
461 // Perform cross-fade in memory
462 struct Buffers {
463 Buffers(size_t size)
464 : buf1{ size }, buf2 { size }
465 {}
466 Floats buf1, buf2;
467 };
468 Buffers buffers[2]{ blendFrames, blendFrames };
469 auto t1 = wt.TimeToLongSamples(cutStart) - blendFrames / 2;
470 auto t2 = wt.TimeToLongSamples(cutEnd) - blendFrames / 2;
471
472 size_t iChannel = 0;
473 for (const auto pChannel : wt.Channels()) {
474 auto &buffer = buffers[iChannel];
475 pChannel->GetFloats(buffer.buf1.get(), t1, blendFrames);
476 pChannel->GetFloats(buffer.buf2.get(), t2, blendFrames);
477
478 for (decltype(blendFrames) i = 0; i < blendFrames; ++i) {
479 buffer.buf1[i] =
480 ((blendFrames - i) * buffer.buf1[i] + i * buffer.buf2[i]) /
481 (double)blendFrames;
482 }
483 ++iChannel;
484 }
485
486 assert(wt.IsLeader()); // given range visits leaders only
487 wt.Clear(cutStart, cutEnd);
488
489 iChannel = 0;
490 for (const auto pChannel : wt.Channels()) {
491 // Write cross-faded data
492 auto &buffer = buffers[iChannel];
493 success = success &&
494 pChannel->Set((samplePtr)buffer.buf1.get(), floatSample, t1,
495 blendFrames,
496 // This effect mostly shifts samples to remove silences, and
497 // does only a little bit of floating point calculations to
498 // cross-fade the splices, over a 100 sample interval by default.
499 // Don't dither.
501 ++iChannel;
502 }
503 },
504 [&](Track &t) {
505 assert(t.IsLeader());
506 // Non-wave tracks: just do a sync-lock adjust
507 t.SyncLockAdjust(cutEnd, cutStart);
508 }
509 );
510 if (!success)
511 return false;
512 ++whichReg;
513 }
514
515 return true;
516}
int min(int a, int b)
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
char * samplePtr
Definition: SampleFormat.h:57
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1479
double SnapToSample(double t) const
size_t as_size_t() const
Definition: SampleCount.cpp:16
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:235

References sampleCount::as_size_t(), WaveTrack::Channels(), WaveTrack::Clear(), detectFrac, WaveTrack::Region::end, floatSample, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, WaveTrack::IsLeader(), SyncLock::IsSelectedOrSyncLockSelected(), kCompress, kTruncate, WideSampleSequence::LongSamplesToTime(), mActionIndex, mBlendFrameCount, min(), mInitialAllowedSilence, mSilenceCompressPercent, mTruncLongestAllowedSilence, narrowestSampleFormat, size, WideSampleSequence::SnapToSample(), WaveTrack::Region::start, WideSampleSequence::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FetchParameters()

static EffectTruncSilence * EffectTruncSilence::FetchParameters ( EffectTruncSilence e,
EffectSettings  
)
inlinestatic

Definition at line 36 of file TruncSilence.h.

36{ return &e; }

◆ FindSilences()

bool EffectTruncSilence::FindSilences ( RegionList silences,
const TrackIterRange< const WaveTrack > &  range 
)
private
Precondition
range visits leaders only

Definition at line 334 of file TruncSilence.cpp.

336{
337 // Start with the whole selection silent
338 silences.push_back(Region(mT0, mT1));
339
340 // Remove non-silent regions in each track
341 int whichTrack = 0;
342 for (auto wt : range) {
343 assert(wt->IsLeader());
344 // Smallest silent region to detect in frames
345 auto minSilenceFrames =
347 * wt->GetRate());
348
349 //
350 // Scan the track for silences
351 //
352 RegionList trackSilences;
353
354 auto index = wt->TimeToLongSamples(mT0);
355 sampleCount silentFrame = 0;
356
357 // Detect silences
358 bool cancelled = !(Analyze(
359 silences, trackSilences, *wt, &silentFrame, &index, whichTrack));
360
361 // Buffer has been freed, so we're OK to return if cancelled
362 if (cancelled)
363 return false;
364
365 if (silentFrame >= minSilenceFrames)
366 {
367 // Track ended in silence -- record region
368 trackSilences.push_back(Region(
369 wt->LongSamplesToTime(index - silentFrame),
370 wt->LongSamplesToTime(index)
371 ));
372 }
373
374 // Intersect with the overall silent region list
375 Intersect(silences, trackSilences);
376 whichTrack++;
377 }
378
379 return true;
380}
void Intersect(RegionList &dest, const RegionList &src)

References Analyze(), DEF_MinTruncMs, Intersect(), mInitialAllowedSilence, EffectBase::mT0, and EffectBase::mT1.

Referenced by ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDescription()

TranslatableString EffectTruncSilence::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 144 of file TruncSilence.cpp.

145{
146 return XO("Automatically reduces the length of passages where the volume is below a specified level");
147}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectTruncSilence::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 139 of file TruncSilence.cpp.

140{
141 return Symbol;
142}
static const ComponentInterfaceSymbol Symbol
Definition: TruncSilence.h:37

References Symbol.

◆ GetType()

EffectType EffectTruncSilence::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 156 of file TruncSilence.cpp.

157{
158 return EffectTypeProcess;
159}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by ProcessAll(), and ProcessIndependently().

Here is the caller graph for this function:

◆ Intersect()

void EffectTruncSilence::Intersect ( RegionList dest,
const RegionList src 
)
private

Definition at line 802 of file TruncSilence.cpp.

803{
804 RegionList::iterator destIter;
805 destIter = dest.begin();
806 // Any time we reach the end of the dest list we're finished
807 if (destIter == dest.end())
808 return;
809 RegionList::iterator curDest = destIter;
810
811 // Operation: find non-silent regions in src, remove them from dest.
812 double nsStart = curDest->start;
813 double nsEnd;
814 bool lastRun = false; // must run the loop one extra time
815
816 RegionList::const_iterator srcIter = src.begin();
817
818 // This logic, causing the loop to run once after end of src, must occur
819 // each time srcIter is updated
820 if (srcIter == src.end())
821 {
822 lastRun = true;
823 }
824
825 while (srcIter != src.end() || lastRun)
826 {
827 // Don't use curSrc unless lastRun is false!
828 RegionList::const_iterator curSrc;
829
830 if (lastRun)
831 {
832 // The last non-silent region extends as far as possible
833 nsEnd = std::numeric_limits<double>::max();
834 }
835 else
836 {
837 curSrc = srcIter;
838 nsEnd = curSrc->start;
839 }
840
841 if (nsEnd > nsStart)
842 {
843 // Increment through dest until we have a region that could be affected
844 while (curDest->end <= nsStart)
845 {
846 ++destIter;
847 if (destIter == dest.end())
848 {
849 return;
850 }
851 curDest = destIter;
852 }
853
854 // Check for splitting dest region in two
855 if (nsStart > curDest->start && nsEnd < curDest->end)
856 {
857 // The second region
858 Region r(nsEnd, curDest->end);
859
860 // The first region
861 curDest->end = nsStart;
862
863 // Insert second region after first
864 RegionList::iterator nextIt(destIter);
865 ++nextIt;
866
867 // This should just read: destIter = dest.insert(nextIt, r); but we
868 // work around two two wxList::insert() bugs. First, in some
869 // versions it returns the wrong value. Second, in some versions,
870 // it crashes when you insert at list end.
871 if (nextIt == dest.end())
872 dest.push_back(r);
873 else
874 dest.insert(nextIt, r);
875 ++destIter; // (now points at the newly-inserted region)
876
877 curDest = destIter;
878 }
879
880 // Check for truncating the end of dest region
881 if (nsStart > curDest->start && nsStart < curDest->end &&
882 nsEnd >= curDest->end)
883 {
884 curDest->end = nsStart;
885
886 ++destIter;
887 if (destIter == dest.end())
888 {
889 return;
890 }
891 curDest = destIter;
892 }
893
894 // Check for all dest regions that need to be removed completely
895 while (nsStart <= curDest->start && nsEnd >= curDest->end)
896 {
897 destIter = dest.erase(destIter);
898 if (destIter == dest.end())
899 {
900 return;
901 }
902 curDest = destIter;
903 }
904
905 // Check for truncating the beginning of dest region
906 if (nsStart <= curDest->start &&
907 nsEnd > curDest->start && nsEnd < curDest->end)
908 {
909 curDest->start = nsEnd;
910 }
911 }
912
913 if (lastRun)
914 {
915 // done
916 lastRun = false;
917 }
918 else
919 {
920 // Next non-silent region starts at the end of this silent region
921 nsStart = curSrc->end;
922 ++srcIter;
923 if (srcIter == src.end())
924 {
925 lastRun = true;
926 }
927 }
928 }
929}

References PackedArray::end().

Referenced by FindSilences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSettings()

bool EffectTruncSilence::LoadSettings ( const CommandParameters parms,
EffectSettings settings 
) const
overridevirtual

Restore settings from keys and values.

Returns
true on success

Implements EffectSettingsManager.

Definition at line 161 of file TruncSilence.cpp.

163{
165
166 // A bit of special treatment for two parameters
167
168 // This control migrated from a choice to a text box in version 2.3.0
169 double myThreshold {};
170 bool newParams = [&] {
171 double temp;
172 if (!parms.ReadAndVerify(Threshold.key,
174 return false;
175 myThreshold = temp;
176 return true;
177 } ();
178
179 if ( !newParams ) {
180 int temp;
181 // Use legacy param:
182 if (!parms.ReadAndVerify(L"Db", &temp, 0,
184 return false;
185 myThreshold = enumToDB( temp );
186 }
187
188 {
189 int temp;
190 if (!parms.ReadAndVerify( ActIndex.key, &temp, ActIndex.def,
192 return false;
193
194 // TODO: fix this when settings are really externalized
195 const_cast<int&>(mActionIndex) = temp;
196 }
197 // TODO: fix this when settings are really externalized
198 const_cast<double&>(mThresholdDB) = myThreshold;
199 return true;
200}
static Settings & settings()
Definition: TrackInfo.cpp:69
static CommandParameters::ObsoleteMap kObsoleteActions[]
static const size_t nObsoleteActions
static double enumToDB(int val)
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
Restore settings from keys and values.
Definition: Effect.cpp:122
static constexpr EnumParameter ActIndex
Definition: TruncSilence.h:136
static const EnumValueSymbol kActionStrings[nActions]
Definition: TruncSilence.h:132
static constexpr EffectParameter Threshold
Definition: TruncSilence.h:134
static const size_t NumDbChoices
static const EnumValueSymbol DbChoices[]
const wxChar *const key
Identifier in configuration file.
const Type def
Default value.
const Type min
Minimum value.
const Type max
Maximum value.

References ActIndex, Enums::DbChoices, EffectParameter< Structure, Member, Type, Value >::def, enumToDB(), kActionStrings, EffectParameter< Structure, Member, Type, Value >::key, kObsoleteActions, Effect::LoadSettings(), mActionIndex, EffectParameter< Structure, Member, Type, Value >::max, EffectParameter< Structure, Member, Type, Value >::min, mThresholdDB, nActions, nObsoleteActions, Enums::NumDbChoices, CommandParameters::ReadAndVerify(), settings(), and Threshold.

Here is the call graph for this function:

◆ ManualPage()

ManualPageID EffectTruncSilence::ManualPage ( ) const
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 149 of file TruncSilence.cpp.

150{
151 return L"Truncate_Silence";
152}

◆ NeedsDither()

bool EffectTruncSilence::NeedsDither ( ) const
overridevirtual

Reimplemented from StatefulEffectBase.

Definition at line 976 of file TruncSilence.cpp.

977{
978 return false;
979}

◆ OnControlChange()

void EffectTruncSilence::OnControlChange ( wxCommandEvent &  evt)
private

Definition at line 963 of file TruncSilence.cpp.

964{
965 mActionChoice->GetValidator()->TransferFromWindow();
966
967 UpdateUI();
968
970 mUIParent, mUIParent->TransferDataFromWindow()))
971 {
972 return;
973 }
974}
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
wxChoice * mActionChoice
Definition: TruncSilence.h:116
wxWeakRef< wxWindow > mUIParent
Definition: TruncSilence.h:104

References EffectEditor::EnableApply(), mActionChoice, mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectTruncSilence::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 89 of file TruncSilence.cpp.

90{
93 > parameters;
94 return parameters;
95}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Independent
Definition: TruncSilence.h:144
static constexpr EffectParameter Minimum
Definition: TruncSilence.h:138
static constexpr EffectParameter Truncate
Definition: TruncSilence.h:140
static constexpr EffectParameter Compress
Definition: TruncSilence.h:142

References ActIndex, Compress, EffectTruncSilence(), Independent, Minimum, Threshold, and Truncate.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectEditor > EffectTruncSilence::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access,
const EffectOutputs pOutputs 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from PopulateUI instead of a DefaultEffectEditor; default implementation returns null

Reimplemented from StatefulEffectUIServices.

Definition at line 695 of file TruncSilence.cpp.

698{
699 mUIParent = S.GetParent();
700 wxASSERT(nActions == WXSIZEOF(kActionStrings));
701
702 S.AddSpace(0, 5);
703
704 S.StartStatic(XO("Detect Silence"));
705 {
706 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
707 {
708 // Threshold
710 .Validator<FloatingPointValidator<double>>(
711 3, &mThresholdDB, NumValidatorStyle::NO_TRAILING_ZEROES,
713 .NameSuffix(XO("db"))
714 .AddTextBox(XXO("&Threshold:"), wxT(""), 0);
715 S.AddUnits(XO("dB"));
716
717 // Ignored silence
718 mInitialAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
720 NumValidatorStyle::NO_TRAILING_ZEROES,
722 .NameSuffix(XO("seconds"))
723 .AddTextBox(XXO("&Duration:"), wxT(""), 12);
724 S.AddUnits(XO("seconds"));
725 }
726 S.EndMultiColumn();
727 }
728 S.EndStatic();
729
730 S.StartStatic(XO("Action"));
731 {
732 S.StartHorizontalLay();
733 {
734 // Action choices
735 auto actionChoices = Msgids( kActionStrings, nActions );
737 .Validator<wxGenericValidator>(&mActionIndex)
738 .MinSize( { -1, -1 } )
739 .AddChoice( {}, actionChoices );
740 }
741 S.EndHorizontalLay();
742 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
743 {
744 // Truncation / Compression factor
745
746 mTruncLongestAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
748 NumValidatorStyle::NO_TRAILING_ZEROES,
750 .NameSuffix(XO("seconds"))
751 .AddTextBox(XXO("Tr&uncate to:"), wxT(""), 12);
752 S.AddUnits(XO("seconds"));
753
754 mSilenceCompressPercentT = S.Validator<FloatingPointValidator<double>>(
756 NumValidatorStyle::NO_TRAILING_ZEROES,
758 .NameSuffix(XO("%"))
759 .AddTextBox(XXO("C&ompress to:"), wxT(""), 12);
760 S.AddUnits(XO("%"));
761 }
762 S.EndMultiColumn();
763
764 S.StartMultiColumn(2, wxALIGN_CENTER_HORIZONTAL);
765 {
766 mIndependent = S.AddCheckBox(XXO("Trunc&ate tracks independently"),
768 }
769 S.EndMultiColumn();
770 }
771 S.EndStatic();
772
773 UpdateUI();
774 return nullptr;
775}
XXO("&Cut/Copy/Paste Toolbar")
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mThresholdText
Definition: TruncSilence.h:115
wxCheckBox * mIndependent
Definition: TruncSilence.h:120
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:118
wxTextCtrl * mInitialAllowedSilenceT
Definition: TruncSilence.h:117
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:119

References Compress, kActionStrings, mActionChoice, mActionIndex, EffectParameter< Structure, Member, Type, Value >::max, mbIndependent, EffectParameter< Structure, Member, Type, Value >::min, mIndependent, Minimum, mInitialAllowedSilence, mInitialAllowedSilenceT, Msgids(), mSilenceCompressPercent, mSilenceCompressPercentT, mThresholdDB, mThresholdText, mTruncLongestAllowedSilence, mTruncLongestAllowedSilenceT, mUIParent, nActions, S, Threshold, Truncate, UpdateUI(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ Process()

bool EffectTruncSilence::Process ( EffectInstance instance,
EffectSettings settings 
)
overridevirtual

Implements StatefulEffectBase.

Definition at line 233 of file TruncSilence.cpp.

234{
235 const bool success =
238 : ProcessAll();
239
240 return success;
241}

References mbIndependent, ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:

◆ ProcessAll()

bool EffectTruncSilence::ProcessAll ( )
private

Definition at line 309 of file TruncSilence.cpp.

310{
311 // Copy tracks
312 EffectOutputTracks outputs {
313 *mTracks, GetType(), { { mT0, mT1 } }, true, true
314 };
315
316 // Master list of silent regions.
317 // This list should always be kept in order.
318 RegionList silences;
319
320 if (FindSilences(silences, outputs.Get().Selected<const WaveTrack>()))
321 {
322 auto trackRange = outputs.Get().Any();
323 double totalCutLen = 0.0;
324 if (DoRemoval(silences, trackRange, 0, 1, totalCutLen)) {
325 mT1 -= totalCutLen;
326 outputs.Commit();
327 return true;
328 }
329 }
330
331 return false;
332}
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
Use this object to copy the input tracks to tentative outputTracks.
bool FindSilences(RegionList &silences, const TrackIterRange< const WaveTrack > &range)
EffectType GetType() const override
Type determines how it behaves.
bool DoRemoval(const RegionList &silences, const TrackIterRange< Track > &range, unsigned iGroup, unsigned nGroups, double &totalCutLen)

References DoRemoval(), FindSilences(), GetType(), EffectBase::mT0, EffectBase::mT1, and EffectBase::mTracks.

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessIndependently()

bool EffectTruncSilence::ProcessIndependently ( )
private

Definition at line 243 of file TruncSilence.cpp.

244{
245 unsigned nGroups = 0;
246
247 const bool syncLock = SyncLockState::Get(*FindProject()).IsSyncLocked();
248
249 // Check if it's permissible
250 {
251 for (auto track : inputTracks()->Selected<const WaveTrack>()) {
252 if (syncLock) {
253 auto otherTracks =
254 SyncLock::Group(track).Filter<const WaveTrack>()
256 - [&](const Track *pTrack){ return pTrack == track; };
257 if (otherTracks) {
259 XO(
260"When truncating independently, there may only be one selected audio track in each Sync-Locked Track Group.") );
261 return false;
262 }
263 }
264
265 ++nGroups;
266 }
267 }
268
269 if (nGroups == 0)
270 // nothing to do
271 return true;
272
273 // Now do the work
274
275 // Copy tracks
276 EffectOutputTracks outputs {
277 *mTracks, GetType(), { { mT0, mT1 } }, true, true
278 };
279 double newT1 = 0.0;
280
281 {
282 unsigned iGroup = 0;
283 for (auto track : outputs.Get().Selected<WaveTrack>()) {
284 RegionList silences;
285 if (!FindSilences(silences,
286 TrackList::SingletonRange(&as_const(*track))))
287 return false;
288 // Treat tracks in the sync lock group only
289 Track *groupFirst, *groupLast;
290 auto range = syncLock
291 ? SyncLock::Group(track)
292 : TrackList::SingletonRange<Track>(track);
293 double totalCutLen = 0.0;
294 if (!DoRemoval(silences, range, iGroup, nGroups, totalCutLen))
295 return false;
296 newT1 = std::max(newT1, mT1 - totalCutLen);
297
298 ++iGroup;
299 }
300 }
301
302 mT1 = newT1;
303
304 outputs.Commit();
305
306 return true;
307}
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:225
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
bool IsSelected() const
Definition: Track.cpp:288
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1128

References EffectUIServices::DoMessageBox(), DoRemoval(), EffectBase::FindProject(), FindSilences(), SyncLockState::Get(), GetType(), SyncLock::Group(), EffectBase::inputTracks(), Track::IsSelected(), SyncLockState::IsSyncLocked(), EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, TrackList::SingletonRange(), and XO().

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransferDataFromWindow()

bool EffectTruncSilence::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 787 of file TruncSilence.cpp.

788{
789 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
790 {
791 return false;
792 }
793
794 mbIndependent = mIndependent->IsChecked();
795
796 return true;
797}

References mbIndependent, mIndependent, and mUIParent.

◆ TransferDataToWindow()

bool EffectTruncSilence::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 777 of file TruncSilence.cpp.

778{
779 if (!mUIParent->TransferDataToWindow())
780 {
781 return false;
782 }
783
784 return true;
785}

References mUIParent.

◆ UpdateUI()

void EffectTruncSilence::UpdateUI ( )
private

Definition at line 949 of file TruncSilence.cpp.

950{
951 switch (mActionIndex)
952 {
953 case kTruncate:
954 mTruncLongestAllowedSilenceT->Enable(true);
955 mSilenceCompressPercentT->Enable(false);
956 break;
957 case kCompress:
958 mTruncLongestAllowedSilenceT->Enable(false);
959 mSilenceCompressPercentT->Enable(true);
960 }
961}

References kCompress, kTruncate, mActionIndex, mSilenceCompressPercentT, and mTruncLongestAllowedSilenceT.

Referenced by OnControlChange(), and PopulateOrExchange().

Here is the caller graph for this function:

Member Data Documentation

◆ ActIndex

constexpr EnumParameter EffectTruncSilence::ActIndex
staticconstexprprivate
Initial value:

Definition at line 136 of file TruncSilence.h.

Referenced by LoadSettings(), and Parameters().

◆ Compress

constexpr EffectParameter EffectTruncSilence::Compress
staticconstexprprivate
Initial value:
L"Compress", 50.0, 0.0, 99.9, 1 }

Definition at line 142 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Independent

constexpr EffectParameter EffectTruncSilence::Independent
staticconstexprprivate
Initial value:
L"Independent", false, false, true, 1 }

Definition at line 144 of file TruncSilence.h.

Referenced by Parameters().

◆ kActionStrings

const EnumValueSymbol EffectTruncSilence::kActionStrings
staticprivate
Initial value:
=
{
{ XO("Truncate Detected Silence") },
{ XO("Compress Excess Silence") }
}

Definition at line 132 of file TruncSilence.h.

Referenced by LoadSettings(), and PopulateOrExchange().

◆ mActionChoice

wxChoice* EffectTruncSilence::mActionChoice
private

Definition at line 116 of file TruncSilence.h.

Referenced by OnControlChange(), and PopulateOrExchange().

◆ mActionIndex

int EffectTruncSilence::mActionIndex
private

Definition at line 107 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), LoadSettings(), PopulateOrExchange(), and UpdateUI().

◆ mbIndependent

bool EffectTruncSilence::mbIndependent
private

Definition at line 111 of file TruncSilence.h.

Referenced by PopulateOrExchange(), Process(), and TransferDataFromWindow().

◆ mBlendFrameCount

size_t EffectTruncSilence::mBlendFrameCount
private

Definition at line 113 of file TruncSilence.h.

Referenced by DoRemoval().

◆ mIndependent

wxCheckBox* EffectTruncSilence::mIndependent
private

Definition at line 120 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and TransferDataFromWindow().

◆ Minimum

constexpr EffectParameter EffectTruncSilence::Minimum
staticconstexprprivate
Initial value:
L"Minimum", 0.5, 0.001, 10000.0, 1 }

Definition at line 138 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mInitialAllowedSilence

double EffectTruncSilence::mInitialAllowedSilence
private

Definition at line 108 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), FindSilences(), and PopulateOrExchange().

◆ mInitialAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mInitialAllowedSilenceT
private

Definition at line 117 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mSilenceCompressPercent

double EffectTruncSilence::mSilenceCompressPercent
private

Definition at line 110 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), and PopulateOrExchange().

◆ mSilenceCompressPercentT

wxTextCtrl* EffectTruncSilence::mSilenceCompressPercentT
private

Definition at line 119 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mThresholdDB

double EffectTruncSilence::mThresholdDB {}
private

Definition at line 106 of file TruncSilence.h.

Referenced by Analyze(), LoadSettings(), and PopulateOrExchange().

◆ mThresholdText

wxTextCtrl* EffectTruncSilence::mThresholdText
private

Definition at line 115 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mTruncLongestAllowedSilence

double EffectTruncSilence::mTruncLongestAllowedSilence
private

Definition at line 109 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), and PopulateOrExchange().

◆ mTruncLongestAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mTruncLongestAllowedSilenceT
private

Definition at line 118 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mUIParent

wxWeakRef<wxWindow> EffectTruncSilence::mUIParent {}
private

◆ Symbol

const ComponentInterfaceSymbol EffectTruncSilence::Symbol { XO("Truncate Silence") }
static

Definition at line 37 of file TruncSilence.h.

Referenced by GetSymbol().

◆ Threshold

constexpr EffectParameter EffectTruncSilence::Threshold
staticconstexprprivate
Initial value:
L"Threshold", -20.0, -80.0, -20.0, 1 }

Definition at line 134 of file TruncSilence.h.

Referenced by LoadSettings(), Parameters(), and PopulateOrExchange().

◆ Truncate

constexpr EffectParameter EffectTruncSilence::Truncate
staticconstexprprivate
Initial value:
L"Truncate", 0.5, 0.0, 10000.0, 1 }

Definition at line 140 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().


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