Audacity 3.2.0
libraries/lib-builtin-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 "BasicUI.h"
18#include "Project.h"
19#include "Prefs.h"
20#include "SyncLock.h"
21#include "ViewInfo.h"
22#include "WaveTrack.h"
23
24#include "TimeWarper.h"
25
27{
28 const auto duration = settings.extra.GetDuration();
29
30 // Set up mOutputTracks.
31 // This effect needs all for sync-lock grouping.
32 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } }, true };
33
34 // Iterate over the tracks
35 bool bGoodResult = true;
36 int ntrack = 0;
37
38 outputs.Get().Any().VisitWhile(bGoodResult,
39 [&](auto &&fallthrough){ return [&](WaveTrack &track) {
40 if (!track.GetSelected())
41 return fallthrough();
42 bool editClipCanMove = GetEditClipsCanMove();
43
44 //if we can't move clips, and we're generating into an empty space,
45 //make sure there's room.
46 if (!editClipCanMove &&
47 track.IsEmpty(mT0, mT1 + 1.0 / track.GetRate()) &&
48 !track.IsEmpty(mT0,
49 mT0 + duration - (mT1 - mT0) - 1.0 / track.GetRate()))
50 {
51 using namespace BasicUI;
53 XO("There is not enough room available to generate the audio"),
54 MessageBoxOptions {}.IconStyle(Icon::Error));
55 bGoodResult = false;
56 return;
57 }
58
59 if (duration > 0.0) {
60 // Create a temporary track
61 auto copy = track.EmptyCopy();
62 // Fill with data
64 bGoodResult = false;
65 if (bGoodResult) {
66 copy->Flush();
67 PasteTimeWarper warper{ mT1, mT0 + duration };
68 auto pProject = FindProject();
69 const auto &selectedRegion =
71 // According to https://manual.audacityteam.org/man/silence.html,
72 // generating silence with an audio selection should behave like
73 // the "Silence Audio" command, which doesn't affect track clip
74 // boundaries.
75 constexpr auto preserve = true;
76 constexpr auto merge = true;
77 track.ClearAndPaste(
78 selectedRegion.t0(), selectedRegion.t1(), *copy, preserve,
79 merge, &warper);
80 }
81 else
82 return;
83 }
84 else
85 // If the duration is zero, there's no need to actually
86 // generate anything
87 track.Clear(mT0, mT1);
88
89 ntrack++;
90 }; },
91 [&](Track &t) {
93 t.SyncLockAdjust(mT1, mT0 + duration);
94 }
95 );
96
97 if (bGoodResult) {
98 outputs.Commit();
99 mT1 = mT0 + duration; // Update selection.
100 }
101
102 return bGoodResult;
103}
Toolkit-neutral facade for basic user interface services.
XO("Cut/Copy/Paste")
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
static Settings & settings()
Definition: TrackInfo.cpp:51
bool GetEditClipsCanMove()
Definition: WaveTrack.cpp:3408
double mT1
Definition: EffectBase.h:123
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:122
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:220
virtual EffectType GetType() const =0
Type determines how it behaves.
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
virtual bool GenerateTrack(const EffectSettings &settings, WaveTrack &tmp)=0
GenerateTrack() must be overridden by the actual generator class.
bool Process(EffectInstance &instance, EffectSettings &settings) override
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
static bool IsSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:80
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40
MessageBoxOptions && IconStyle(Icon style) &&
Definition: BasicUI.h:104
Externalized state of a plug-in.