TODO: Lift the possible user-prompting part out of this function, so that the recursive paths into this function via Effect::Delegate are simplified, and we don't have both EffectSettings and EffectSettingsAccessPtr If pAccess is not null, settings should have come from its Get()
| 55 | // and we don't have both EffectSettings and EffectSettingsAccessPtr |
| 56 | // If pAccess is not null, settings should have come from its Get() |
| 57 | bool EffectBase::DoEffect(EffectSettings &settings, |
| 58 | const InstanceFinder &finder, |
| 59 | double projectRate, |
| 60 | TrackList *list, |
| 61 | WaveTrackFactory *factory, |
| 62 | NotifyingSelectedRegion &selectedRegion, |
| 63 | unsigned flags, |
| 64 | const EffectSettingsAccessPtr &pAccess) |
| 65 | { |
| 66 | auto cleanup0 = valueRestorer(mUIFlags, flags); |
| 67 | wxASSERT(selectedRegion.duration() >= 0.0); |
| 68 | |
| 69 | mFactory = factory; |
| 70 | mProjectRate = projectRate; |
| 71 | |
| 72 | SetTracks(list); |
| 73 | // Don't hold a dangling pointer when done |
| 74 | Finally Do([&]{ SetTracks(nullptr); }); |
| 75 | |
| 76 | // This is for performance purposes only, no additional recovery implied |
| 77 | auto &pProject = *const_cast<AudacityProject*>(FindProject()); // how to remove this const_cast? |
| 78 | TransactionScope trans(pProject, "Effect"); |
| 79 | |
| 80 | // Update track/group counts |
| 81 | CountWaveTracks(); |
| 82 | |
| 83 | bool isSelection = false; |
| 84 | |
| 85 | auto duration = 0.0; |
| 86 | if (GetType() == EffectTypeGenerate) |
| 87 | GetConfig(GetDefinition(), PluginSettings::Private, |
| 88 | CurrentSettingsGroup(), |
| 89 | EffectSettingsExtra::DurationKey(), duration, GetDefaultDuration()); |
| 90 | |
| 91 | WaveTrack *newTrack{}; |
| 92 | bool success = false; |
| 93 | auto oldDuration = duration; |
| 94 | |
| 95 | auto cleanup = finally( [&] { |
| 96 | if (!success) { |
| 97 | if (newTrack) { |
| 98 | mTracks->Remove(*newTrack); |
| 99 | } |
| 100 | // On failure, restore the old duration setting |
| 101 | settings.extra.SetDuration(oldDuration); |
| 102 | } |
| 103 | else |
| 104 | trans.Commit(); |
| 105 | |
| 106 | mPresetNames.clear(); |
| 107 | } ); |
| 108 | |
| 109 | // We don't yet know the effect type for code in the Nyquist Prompt, so |
| 110 | // assume it requires a track and handle errors when the effect runs. |
| 111 | if ((GetType() == EffectTypeGenerate || GetPath() == NYQUIST_PROMPT_ID) && (mNumTracks == 0)) { |
| 112 | auto track = mFactory->Create(); |
| 113 | track->SetName(mTracks->MakeUniqueTrackName(WaveTrack::GetDefaultAudioTrackNamePreference())); |
| 114 | newTrack = mTracks->Add(track); |
no test coverage detected