Audacity 3.2.0
src/effects/Generator.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Generator.cpp
6
7 Effects that generate audio can derive from Generator.
8
9 Dominic Mazzoni
10 Vaughan Johnson
11
12**********************************************************************/
13
14#include "Generator.h"
15#include "EffectOutputTracks.h"
16
17#include "Project.h"
18#include "Prefs.h"
19#include "SyncLock.h"
20#include "ViewInfo.h"
21#include "WaveTrack.h"
22
23#include "TimeWarper.h"
24
25#include "AudacityMessageBox.h"
26
28{
29 const auto duration = settings.extra.GetDuration();
30
31 // Set up mOutputTracks.
32 // This effect needs all for sync-lock grouping.
33 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } }, true };
34
35 // Iterate over the tracks
36 bool bGoodResult = true;
37 int ntrack = 0;
38
39 outputs.Get().Any().VisitWhile(bGoodResult,
40 [&](auto &&fallthrough){ return [&](WaveTrack &track) {
41 if (!track.GetSelected())
42 return fallthrough();
43 bool editClipCanMove = GetEditClipsCanMove();
44
45 //if we can't move clips, and we're generating into an empty space,
46 //make sure there's room.
47 if (!editClipCanMove &&
48 track.IsEmpty(mT0, mT1 + 1.0 / track.GetRate()) &&
49 !track.IsEmpty(mT0,
50 mT0 + duration - (mT1 - mT0) - 1.0 / track.GetRate()))
51 {
53 XO("There is not enough room available to generate the audio"),
54 wxICON_STOP,
55 XO("Error") );
56 bGoodResult = false;
57 return;
58 }
59
60 if (duration > 0.0) {
61 // Create a temporary track
62 auto list = track.WideEmptyCopy();
63 // Fill with data
64 if (!GenerateTrack(settings, *list))
65 bGoodResult = false;
66 if (bGoodResult) {
67 (*list->Any<WaveTrack>().begin())->Flush();
68 PasteTimeWarper warper{ mT1, mT0 + duration };
69 auto pProject = FindProject();
70 const auto &selectedRegion =
72 // According to https://manual.audacityteam.org/man/silence.html,
73 // generating silence with an audio selection should behave like
74 // the "Silence Audio" command, which doesn't affect track clip
75 // boundaries.
76 constexpr auto preserve = true;
77 constexpr auto merge = true;
78 track.ClearAndPaste(
79 selectedRegion.t0(), selectedRegion.t1(), *list, preserve,
80 merge, &warper);
81 }
82 else
83 return;
84 }
85 else
86 // If the duration is zero, there's no need to actually
87 // generate anything
88 track.Clear(mT0, mT1);
89
90 ntrack++;
91 }; },
92 [&](Track &t) {
94 t.SyncLockAdjust(mT1, mT0 + duration);
95 }
96 );
97
98 if (bGoodResult) {
99 outputs.Commit();
100 mT1 = mT0 + duration; // Update selection.
101 }
102
103 return bGoodResult;
104}
XO("Cut/Copy/Paste")
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
static Settings & settings()
Definition: TrackInfo.cpp:69
bool GetEditClipsCanMove()
Definition: WaveTrack.cpp:4578
double mT1
Definition: EffectBase.h:116
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:115
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:225
virtual EffectType GetType() const =0
Type determines how it behaves.
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
AUDACITY_DLL_API bool Process(EffectInstance &instance, EffectSettings &settings) override
virtual bool GenerateTrack(const EffectSettings &settings, TrackList &tmp)=0
GenerateTrack() must be overridden by the actual generator class.
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
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:122
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
Externalized state of a plug-in.