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

An Extreme Time Stretch and Time Smear effect. More...

#include <Paulstretch.h>

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

Public Member Functions

 EffectPaulstretch ()
 
virtual ~EffectPaulstretch ()
 
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...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 
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
 
- 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
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
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 NumericFormatSymbol 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 EffectPaulstretchFetchParameters (EffectPaulstretch &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("Paulstretch") }
 
- 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 Member Functions

void OnText (wxCommandEvent &evt)
 
size_t GetBufferSize (double rate) const
 
bool ProcessOne (const WaveChannel &track, WaveChannel &outputTrack, double t0, double t1, int count)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent
 
float mAmount
 
float mTime_resolution
 

Static Private Attributes

static constexpr EffectParameter Amount
 
static constexpr EffectParameter Time
 

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

An Extreme Time Stretch and Time Smear effect.

Definition at line 21 of file Paulstretch.h.

Constructor & Destructor Documentation

◆ EffectPaulstretch()

EffectPaulstretch::EffectPaulstretch ( )

Definition at line 96 of file Paulstretch.cpp.

97{
98 Parameters().Reset(*this);
99
101}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:214
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override
Definition: Paulstretch.cpp:36

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectPaulstretch()

EffectPaulstretch::~EffectPaulstretch ( )
virtual

Definition at line 103 of file Paulstretch.cpp.

104{
105}

Member Function Documentation

◆ CalcPreviewInputLength()

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

Implements EffectBase.

Definition at line 133 of file Paulstretch.cpp.

135{
136 // FIXME: Preview is currently at the project rate, but should really be
137 // at the track rate (bugs 1284 and 852).
138 auto minDuration = GetBufferSize(mProjectRate) * 2 + 1;
139
140 // Preview playback may need to be trimmed but this is the smallest selection that we can use.
141 double minLength = std::max<double>(minDuration / mProjectRate, previewLength / mAmount);
142
143 return minLength;
144}
double mProjectRate
Definition: EffectBase.h:112
size_t GetBufferSize(double rate) const

References GetBufferSize(), mAmount, and EffectBase::mProjectRate.

Here is the call graph for this function:

◆ FetchParameters()

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

Definition at line 25 of file Paulstretch.h.

25{ return &e; }

◆ GetBufferSize()

size_t EffectPaulstretch::GetBufferSize ( double  rate) const
private

Definition at line 249 of file Paulstretch.cpp.

250{
251 // Audacity's fft requires a power of 2
252 float tmp = rate * mTime_resolution / 2.0;
253 tmp = log(tmp) / log(2.0);
254 tmp = pow(2.0, floor(tmp + 0.5));
255
256 auto stmp = size_t(tmp);
257 if (stmp != tmp)
258 // overflow
259 return 0;
260 if (stmp >= 2 * stmp)
261 // overflow
262 return 0;
263
264 return std::max<size_t>(stmp, 128);
265}
float mTime_resolution
Definition: Paulstretch.h:64

References mTime_resolution.

Referenced by CalcPreviewInputLength(), and ProcessOne().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString EffectPaulstretch::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 114 of file Paulstretch.cpp.

115{
116 return XO("Paulstretch is only for an extreme time-stretch or \"stasis\" effect");
117}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectPaulstretch::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 109 of file Paulstretch.cpp.

110{
111 return Symbol;
112}
static const ComponentInterfaceSymbol Symbol
Definition: Paulstretch.h:26

References Symbol.

◆ GetType()

EffectType EffectPaulstretch::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 126 of file Paulstretch.cpp.

127{
128 return EffectTypeProcess;
129}
@ EffectTypeProcess

References EffectTypeProcess.

◆ ManualPage()

ManualPageID EffectPaulstretch::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 119 of file Paulstretch.cpp.

120{
121 return L"Paulstretch";
122}

◆ OnText()

void EffectPaulstretch::OnText ( wxCommandEvent &  evt)
private

Definition at line 243 of file Paulstretch.cpp.

244{
246 mUIParent, mUIParent->TransferDataFromWindow());
247}
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
wxWeakRef< wxWindow > mUIParent
Definition: Paulstretch.h:61

References EffectEditor::EnableApply(), and mUIParent.

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectPaulstretch::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 36 of file Paulstretch.cpp.

37{
40 > parameters;
41 return parameters;
42}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Time
Definition: Paulstretch.h:71
static constexpr EffectParameter Amount
Definition: Paulstretch.h:69

References Amount, EffectPaulstretch(), and Time.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectEditor > EffectPaulstretch::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 196 of file Paulstretch.cpp.

199{
200 mUIParent = S.GetParent();
201 S.StartMultiColumn(2, wxALIGN_CENTER);
202 {
203 S
204 .Validator<FloatingPointValidator<float>>(
205 1, &mAmount, NumValidatorStyle::DEFAULT, Amount.min)
206 /* i18n-hint: This is how many times longer the sound will be, e.g. applying
207 * the effect to a 1-second sample, with the default Stretch Factor of 10.0
208 * will give an (approximately) 10 second sound
209 */
210 .AddTextBox(XXO("&Stretch Factor:"), wxT(""), 10);
211
212 S
213 .Validator<FloatingPointValidator<float>>(
214 3, &mTime_resolution, NumValidatorStyle::ONE_TRAILING_ZERO, Time.min)
215 .AddTextBox(XXO("&Time Resolution (seconds):"), L"", 10);
216 }
217 S.EndMultiColumn();
218 return nullptr;
219};
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
#define S(N)
Definition: ToChars.cpp:64
const Type min
Minimum value.

References Amount, mAmount, EffectParameter< Structure, Member, Type, Value >::min, mTime_resolution, mUIParent, S, Time, wxT(), and XXO().

Here is the call graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 147 of file Paulstretch.cpp.

148{
149 // Pass true because sync lock adjustment is needed
150 EffectOutputTracks outputs{ *mTracks, {{ mT0, mT1 }}, true };
151 auto newT1 = mT1;
152 int count = 0;
153 // Process selected wave tracks first, to find the new t1 value
154 for (const auto track : outputs.Get().Selected<WaveTrack>()) {
155 double trackStart = track->GetStartTime();
156 double trackEnd = track->GetEndTime();
157 double t0 = mT0 < trackStart ? trackStart : mT0;
158 double t1 = mT1 > trackEnd ? trackEnd : mT1;
159 if (t1 > t0) {
160 auto tempList = track->WideEmptyCopy();
161 const auto channels = track->Channels();
162 auto iter = (*tempList->Any<WaveTrack>().begin())->Channels().begin();
163 for (const auto pChannel : channels) {
164 if (!ProcessOne(*pChannel, **iter++, t0, t1, count++))
165 return false;
166 }
167 const auto pNewTrack = *tempList->Any<WaveTrack>().begin();
168 pNewTrack->Flush();
169 newT1 = std::max(newT1, mT0 + pNewTrack->GetEndTime());
170 track->Clear(t0, t1);
171 track->Paste(t0, *tempList);
172 }
173 else
174 count += track->NChannels();
175 }
176
177 // Sync lock adjustment of other tracks
178 outputs.Get().Any().Visit(
179 [&](auto &&fallthrough){ return [&](WaveTrack &track) {
180 if (!track.IsSelected())
181 fallthrough();
182 }; },
183 [&](Track &track) {
185 track.SyncLockAdjust(mT1, newT1);
186 }
187 );
188 mT1 = newT1;
189
190 outputs.Commit();
191
192 return true;
193}
double mT1
Definition: EffectBase.h:116
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:115
Use this object to copy the input tracks to tentative outputTracks.
bool ProcessOne(const WaveChannel &track, WaveChannel &outputTrack, double t0, double t1, int count)
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:82
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:123
A Track that contains audio waveform data.
Definition: WaveTrack.h:220
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), SyncLock::IsSyncLockSelected(), EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, and ProcessOne().

Here is the call graph for this function:

◆ ProcessOne()

bool EffectPaulstretch::ProcessOne ( const WaveChannel track,
WaveChannel outputTrack,
double  t0,
double  t1,
int  count 
)
private

Definition at line 267 of file Paulstretch.cpp.

269{
270 const auto badAllocMessage =
271 XO("Requested value exceeds memory capacity.");
272
273 const auto rate = track.GetTrack().GetRate();
274 const auto stretch_buf_size = GetBufferSize(rate);
275 if (stretch_buf_size == 0) {
276 EffectUIServices::DoMessageBox(*this, badAllocMessage);
277 return {};
278 }
279
280 double amount = this->mAmount;
281
282 auto start = track.TimeToLongSamples(t0);
283 auto end = track.TimeToLongSamples(t1);
284 auto len = end - start;
285
286 const auto minDuration = stretch_buf_size * 2 + 1;
287 if (minDuration < stretch_buf_size) {
288 // overflow!
289 EffectUIServices::DoMessageBox(*this, badAllocMessage);
290 return {};
291 }
292
293 if (len < minDuration) { //error because the selection is too short
294
295 float maxTimeRes = log( len.as_double() ) / log(2.0);
296 maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5);
297 maxTimeRes = maxTimeRes / rate;
298
299 if (this->IsPreviewing()) {
300 double defaultPreviewLen;
301 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &defaultPreviewLen, 6.0);
302
303 if ((minDuration / mProjectRate) < defaultPreviewLen) {
305 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
306 XO("Audio selection too short to preview.\n\n"
307 "Try increasing the audio selection to at least %.1f seconds,\n"
308 "or reducing the 'Time Resolution' to less than %.1f seconds.")
309 .Format(
310 (minDuration / rate) + 0.05, // round up to 1/10 s.
311 floor(maxTimeRes * 10.0) / 10.0),
312 wxOK | wxICON_EXCLAMATION );
313 }
314 else {
316 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
317 XO("Unable to Preview.\n\n"
318 "For the current audio selection, the maximum\n"
319 "'Time Resolution' is %.1f seconds.")
320 .Format( floor(maxTimeRes * 10.0) / 10.0 ),
321 wxOK | wxICON_EXCLAMATION );
322 }
323 }
324 else {
326 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
327 XO("The 'Time Resolution' is too long for the selection.\n\n"
328 "Try increasing the audio selection to at least %.1f seconds,\n"
329 "or reducing the 'Time Resolution' to less than %.1f seconds.")
330 .Format(
331 (minDuration / rate) + 0.05, // round up to 1/10 s.
332 floor(maxTimeRes * 10.0) / 10.0),
333 wxOK | wxICON_EXCLAMATION );
334 }
335
336 return {};
337 }
338
339 auto dlen = len.as_double();
340 double adjust_amount = dlen /
341 (dlen - ((double)stretch_buf_size * 2.0));
342 amount = 1.0 + (amount - 1.0) * adjust_amount;
343
344 try {
345 // This encloses all the allocations of buffers, including those in
346 // the constructor of the PaulStretch object
347
348 PaulStretch stretch(amount, stretch_buf_size, rate);
349
350 auto nget = stretch.get_nsamples_for_fill();
351
352 auto bufsize = stretch.poolsize;
353 Floats buffer0{ bufsize };
354 float *bufferptr0 = buffer0.get();
355 bool first_time = true;
356
357 const auto fade_len = std::min<size_t>(100, bufsize / 2 - 1);
358 bool cancelled = false;
359
360 {
361 Floats fade_track_smps{ fade_len };
362 decltype(len) s=0;
363
364 while (s < len) {
365 track.GetFloats(bufferptr0, start + s, nget);
366 stretch.process(buffer0.get(), nget);
367
368 if (first_time) {
369 stretch.process(buffer0.get(), 0);
370 };
371
372 s += nget;
373
374 if (first_time){//blend the start of the selection
375 track.GetFloats(fade_track_smps.get(), start, fade_len);
376 first_time = false;
377 for (size_t i = 0; i < fade_len; i++){
378 float fi = (float)i / (float)fade_len;
379 stretch.out_buf[i] =
380 stretch.out_buf[i] * fi + (1.0 - fi) * fade_track_smps[i];
381 }
382 }
383 if (s >= len){//blend the end of the selection
384 track.GetFloats(fade_track_smps.get(), end - fade_len, fade_len);
385 for (size_t i = 0; i < fade_len; i++){
386 float fi = (float)i / (float)fade_len;
387 auto i2 = bufsize / 2 - 1 - i;
388 stretch.out_buf[i2] =
389 stretch.out_buf[i2] * fi + (1.0 - fi) *
390 fade_track_smps[fade_len - 1 - i];
391 }
392 }
393
394 outputTrack.Append((samplePtr)stretch.out_buf.get(), floatSample, stretch.out_bufsize);
395
396 nget = stretch.get_nsamples();
397 if (TrackProgress(count,
398 s.as_double() / len.as_double()
399 )) {
400 cancelled = true;
401 break;
402 }
403 }
404 }
405
406 if (!cancelled)
407 return true;
408 }
409 catch ( const std::bad_alloc& ) {
410 EffectUIServices::DoMessageBox(*this, badAllocMessage);
411 }
412 return false;
413};
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
char * samplePtr
Definition: SampleFormat.h:55
bool IsPreviewing() const
Definition: EffectBase.h:89
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:349
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Abstract base class used in importing a file.
Class that helps EffectPaulStretch. It does the FFTs and inner loop of the effect.
Definition: Paulstretch.cpp:47
WaveTrack & GetTrack()
Definition: WaveTrack.h:1117
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2347
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:152
double GetRate() const override
Definition: WaveTrack.cpp:868
sampleCount TimeToLongSamples(double t0) const
virtual bool Read(const wxString &key, bool *value) const =0
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References WaveChannel::Append(), EffectUIServices::DoMessageBox(), PackedArray::end(), floatSample, PaulStretch::get_nsamples(), PaulStretch::get_nsamples_for_fill(), GetBufferSize(), WaveChannel::GetFloats(), WaveTrack::GetRate(), WaveChannel::GetTrack(), gPrefs, EffectBase::IsPreviewing(), mAmount, EffectBase::mProjectRate, PaulStretch::out_buf, PaulStretch::out_bufsize, PaulStretch::poolsize, PaulStretch::process(), audacity::BasicSettings::Read(), WideSampleSequence::TimeToLongSamples(), Effect::TrackProgress(), wxT(), and XO().

Referenced by Process().

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

◆ TransferDataFromWindow()

bool EffectPaulstretch::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

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

Reimplemented from StatefulEffectUIServices.

Definition at line 231 of file Paulstretch.cpp.

232{
233 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
234 {
235 return false;
236 }
237
238 return true;
239}

References mUIParent.

◆ TransferDataToWindow()

bool EffectPaulstretch::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

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

Reimplemented from StatefulEffectUIServices.

Definition at line 221 of file Paulstretch.cpp.

222{
223 if (!mUIParent->TransferDataToWindow())
224 {
225 return false;
226 }
227
228 return true;
229}

References mUIParent.

Member Data Documentation

◆ Amount

constexpr EffectParameter EffectPaulstretch::Amount
staticconstexprprivate
Initial value:
L"Stretch Factor", 10.0f, 1.0, FLT_MAX, 1 }

Definition at line 69 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mAmount

float EffectPaulstretch::mAmount
private

Definition at line 63 of file Paulstretch.h.

Referenced by CalcPreviewInputLength(), PopulateOrExchange(), and ProcessOne().

◆ mTime_resolution

float EffectPaulstretch::mTime_resolution
private

Definition at line 64 of file Paulstretch.h.

Referenced by GetBufferSize(), and PopulateOrExchange().

◆ mUIParent

wxWeakRef<wxWindow> EffectPaulstretch::mUIParent
private

◆ Symbol

const ComponentInterfaceSymbol EffectPaulstretch::Symbol { XO("Paulstretch") }
static

Definition at line 26 of file Paulstretch.h.

Referenced by GetSymbol().

◆ Time

constexpr EffectParameter EffectPaulstretch::Time
staticconstexprprivate
Initial value:
L"Time Resolution", 0.25f, 0.00099f, FLT_MAX, 1 }

Definition at line 71 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().


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