MCPcopy Create free account
hub / github.com/audacity/audacity / Process

Method Process

libraries/lib-builtin-effects/Generator.cpp:26–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include "TimeWarper.h"
25
26bool Generator::Process(EffectInstance &, EffectSettings &settings)
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;
52 ShowMessageBox(
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
63 if (!GenerateTrack(settings, *copy))
64 bGoodResult = false;
65 if (bGoodResult) {
66 copy->Flush();
67 PasteTimeWarper warper{ mT1, mT0 + duration };
68 auto pProject = FindProject();
69 const auto &selectedRegion =
70 ViewInfo::Get(*pProject).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 }

Callers

nothing calls this directly

Calls 15

GetEditClipsCanMoveFunction · 0.85
ShowMessageBoxFunction · 0.85
GetFunction · 0.85
GetDurationMethod · 0.80
VisitWhileMethod · 0.80
EmptyCopyMethod · 0.80
ClearAndPasteMethod · 0.80
AnyMethod · 0.45
GetMethod · 0.45
GetSelectedMethod · 0.45
IsEmptyMethod · 0.45
GetRateMethod · 0.45

Tested by

no test coverage detected