Audacity 3.2.0
Functions
EffectUI Namespace Reference

Functions

AUDACITY_DLL_API DialogFactoryResults DialogFactory (wxWindow &parent, EffectBase &host, EffectUIServices &client, EffectSettingsAccess &access)
 
AUDACITY_DLL_API bool DoEffect (const PluginID &ID, const CommandContext &context, unsigned flags)
 'Repeat Last Effect'. More...
 

Function Documentation

◆ DialogFactory()

DialogFactoryResults EffectUI::DialogFactory ( wxWindow &  parent,
EffectBase host,
EffectUIServices client,
EffectSettingsAccess access 
)

Definition at line 1111 of file EffectUI.cpp.

1114{
1115 // Make sure there is an associated project, whose lifetime will
1116 // govern the lifetime of the dialog, even when the dialog is
1117 // non-modal, as for realtime effects
1118 auto project = FindProjectFromWindow(&parent);
1119 if ( !project )
1120 return {};
1121 std::shared_ptr<EffectInstance> pInstance;
1123 *project, host, client, pInstance, access } };
1124 if (!pInstance) {
1125 dlg->SetClosed();
1126 return {};
1127 }
1128 if (dlg->Initialize()) {
1129 auto pEditor = dlg->GetEditor();
1130 // release() is safe because parent will own it
1131 return { dlg.release(), pInstance, pEditor };
1132 }
1133 return {};
1134}
#define safenew
Definition: MemoryX.h:9
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:163
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
const auto project

References FindProjectFromWindow(), project, and safenew.

Referenced by DoEffect(), and MacroCommands::PromptForParamsFor().

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

◆ DoEffect()

bool EffectUI::DoEffect ( const PluginID ID,
const CommandContext context,
unsigned  flags 
)

'Repeat Last Effect'.

Run an effect given the plugin ID

DoEffect() takes a PluginID and executes the associated effect.

At the moment flags are used only to indicate whether to prompt for

Definition at line 1148 of file EffectUI.cpp.

1150{
1151 AudacityProject &project = context.project;
1152 auto &tracks = TrackList::Get( project );
1153 auto &trackFactory = WaveTrackFactory::Get( project );
1154 auto rate = ProjectRate::Get(project).GetRate();
1155 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1156 auto &commandManager = CommandManager::Get( project );
1157 auto &viewport = Viewport::Get(project);
1158 auto &window = GetProjectFrame(project);
1159
1160 const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
1161
1162 if (!plug || !PluginManager::IsPluginAvailable(*plug))
1163 {
1165 XO("This plugin could not be loaded.\nIt may have been deleted."),
1167 .Caption(XO("Plugin Error")));
1168
1169 return false;
1170 }
1171
1172 EffectType type = plug->GetEffectType();
1173
1174 // Make sure there's no activity since the effect is about to be applied
1175 // to the project's tracks. Mainly for Apply during RTP, but also used
1176 // for batch commands
1177 if (flags & EffectManager::kConfigured)
1178 {
1180 //Don't Select All if repeating Generator Effect
1181 if (!(flags & EffectManager::kConfigured)) {
1183 }
1184 }
1185
1186 auto nTracksOriginally = tracks.Size();
1187 wxWindow *focus = wxWindow::FindFocus();
1188 wxWindow *parent = nullptr;
1189 if (focus != nullptr) {
1190 parent = focus->GetParent();
1191 }
1192
1193 bool success = false;
1194 auto cleanup = finally( [&] {
1195
1196 if (!success) {
1197 // For now, we're limiting realtime preview to a single effect, so
1198 // make sure the menus reflect that fact that one may have just been
1199 // opened.
1201 }
1202
1203 } );
1204
1205 const auto range = tracks.Selected<const WaveTrack>();
1206 bool anyTracks = !range.empty();
1207 bool clean = std::all_of(range.begin(), range.end(),
1208 [](const WaveTrack *t){ return t->GetEndTime() == 0; });
1209
1211
1212 em.SetSkipStateFlag( false );
1213 success = false;
1214 if (auto effect = dynamic_cast<Effect*>(em.GetEffect(ID))) {
1215 if (const auto pSettings = em.GetDefaultSettings(ID)) {
1216 const auto pAccess =
1217 std::make_shared<SimpleEffectSettingsAccess>(*pSettings);
1218 const auto finder =
1219 [effect, &window, pAccess, flags] (EffectSettings &settings)
1220 -> std::optional<std::shared_ptr<EffectInstanceEx>>
1221 {
1222 // Prompting will be bypassed when applying an effect that has
1223 // already been configured, e.g. repeating the last effect on a
1224 // different selection. Prompting may call EffectPreview
1225 std::shared_ptr<EffectInstance> pInstance;
1226 std::shared_ptr<EffectInstanceEx> pInstanceEx;
1227 if ((flags & EffectManager::kConfigured) == 0 && pAccess) {
1228 const auto pServices = dynamic_cast<EffectUIServices *>(effect);
1229 if (!pServices ||
1230 !pServices->ShowHostInterface(*effect,
1231 window, DialogFactory, pInstance, *pAccess, true)
1232 )
1233 return {};
1234 else if (!(pInstanceEx =
1235 std::dynamic_pointer_cast<EffectInstanceEx>(pInstance)
1236 ))
1237 return {};
1238 else
1239 // Retrieve again after the dialog modified settings
1240 settings = pAccess->Get();
1241 }
1242 return { pInstanceEx };
1243 };
1244 pAccess->ModifySettings([&](EffectSettings &settings){
1245 success = effect->DoEffect(settings, finder,
1246 rate,
1247 &tracks,
1248 &trackFactory,
1249 selectedRegion,
1250 flags,
1251 pAccess);
1252 return nullptr;
1253 });
1254 }
1255 }
1256
1257 if (!success)
1258 return false;
1259
1260 if (em.GetSkipStateFlag())
1261 flags = flags | EffectManager::kSkipState;
1262
1263 if (!(flags & EffectManager::kSkipState))
1264 {
1265 auto shortDesc = em.GetCommandName(ID);
1266 auto longDesc = em.GetCommandDescription(ID);
1267 ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
1268 }
1269
1270 if (!(flags & EffectManager::kDontRepeatLast))
1271 {
1272 // Remember a successful generator, effect, analyzer, or tool Process
1273 auto shortDesc = em.GetCommandName(ID);
1274 /* i18n-hint: %s will be the name of the effect which will be
1275 * repeated if this menu item is chosen */
1276 auto lastEffectDesc = XO("Repeat %s").Format(shortDesc);
1277 switch ( type ) {
1278 case EffectTypeGenerate:
1279 commandManager.Modify(wxT("RepeatLastGenerator"), lastEffectDesc);
1280 commandManager.mLastGenerator = ID;
1281 commandManager.mRepeatGeneratorFlags = EffectManager::kConfigured;
1282 break;
1283 case EffectTypeProcess:
1284 commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
1285 commandManager.mLastEffect = ID;
1286 commandManager.mRepeatEffectFlags = EffectManager::kConfigured;
1287 break;
1288 case EffectTypeAnalyze:
1289 commandManager.Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1290 commandManager.mLastAnalyzer = ID;
1291 commandManager.mLastAnalyzerRegistration =
1293 commandManager.mRepeatAnalyzerFlags = EffectManager::kConfigured;
1294 break;
1295 case EffectTypeTool:
1296 commandManager.Modify(wxT("RepeatLastTool"), lastEffectDesc);
1297 commandManager.mLastTool = ID;
1298 commandManager.mLastToolRegistration =
1300 commandManager.mRepeatToolFlags = EffectManager::kConfigured;
1301 if (shortDesc == NYQUIST_PROMPT_NAME) {
1302 commandManager.mRepeatToolFlags = EffectManager::kRepeatNyquistPrompt; //Nyquist Prompt is not configured
1303 }
1304 break;
1305 }
1306 }
1307
1308 //STM:
1309 //The following automatically re-zooms after sound was generated.
1310 // IMO, it was disorienting, removing to try out without re-fitting
1311 //mchinen:12/14/08 reapplying for generate effects
1312 if (type == EffectTypeGenerate)
1313 {
1314 if (!anyTracks || (clean && selectedRegion.t0() == 0.0))
1315 viewport.ZoomFitHorizontally();
1316 }
1317
1318 // PRL: Redraw explicitly because sometimes history push is skipped
1319 viewport.Redraw();
1320
1321 if (focus != nullptr && focus->GetParent()==parent) {
1322 focus->SetFocus();
1323 }
1324
1325 // A fix for Bug 63
1326 // New tracks added? Scroll them into view so that user sees them.
1327 // Don't care what track type. An analyser might just have added a
1328 // Label track and we want to see it.
1329 if (tracks.Size() > nTracksOriginally) {
1330 viewport.ScrollToBottom();
1331 }
1332 else {
1333 auto pTrack = *tracks.Selected().begin();
1334 if (!pTrack)
1335 pTrack = *tracks.begin();
1336 if (pTrack) {
1337 TrackFocus::Get(project).Set(pTrack);
1339 }
1340 }
1341
1342 return true;
1343}
wxT("CloseDown"))
EffectType
@ EffectTypeAnalyze
@ EffectTypeGenerate
@ EffectTypeTool
@ EffectTypeProcess
XO("Cut/Copy/Paste")
#define NYQUIST_PROMPT_NAME
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
const auto tracks
static Settings & settings()
Definition: TrackInfo.cpp:69
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
AudacityProject & project
static CommandManager & Get(AudacityProject &project)
void UpdateMenus(bool checkActive=true)
Base class for many of the effects in Audacity.
Definition: Effect.h:26
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:48
bool GetSkipStateFlag()
void SetSkipStateFlag(bool flag)
EffectPlugin * GetEffect(const PluginID &ID)
static EffectManager & Get()
EffectSettings * GetDefaultSettings(const PluginID &ID)
TranslatableString GetCommandName(const PluginID &ID)
TranslatableString GetCommandDescription(const PluginID &ID)
EffectType GetEffectType() const
static bool IsPluginAvailable(const PluginDescriptor &plug)
const PluginDescriptor * GetPlugin(const PluginID &ID) const
static PluginManager & Get()
void Stop(bool stopStream=true)
static ProjectAudioManager & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
Track * Get()
Definition: TrackFocus.cpp:156
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void ShowTrack(const Track &track)
Definition: Viewport.cpp:456
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:3349
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:279
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:375
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectBase &host, EffectUIServices &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1111
void SelectAllIfNone(AudacityProject &project)
Externalized state of a plug-in.

References DialogFactory(), EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, anonymous_namespace{Scrubbing.cpp}::finder, BasicUI::FindFocus(), PluginManager::Get(), TrackFocus::Get(), EffectManager::Get(), CommandManager::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), Viewport::Get(), WaveTrackFactory::Get(), ProjectAudioManager::Get(), EffectManager::GetCommandDescription(), EffectManager::GetCommandName(), EffectManager::GetDefaultSettings(), EffectManager::GetEffect(), PluginDescriptor::GetEffectType(), PluginManager::GetPlugin(), GetProjectFrame(), ProjectRate::GetRate(), EffectManager::GetSkipStateFlag(), PluginManager::IsPluginAvailable(), EffectManager::kConfigured, EffectManager::kDontRepeatLast, EffectManager::kRepeatNyquistPrompt, EffectManager::kSkipState, NYQUIST_PROMPT_NAME, CommandContext::project, project, ProjectHistory::PushState(), CommandManager::repeattypeplugin, SelectUtilities::SelectAllIfNone(), ViewInfo::selectedRegion, EffectManager::SetSkipStateFlag(), settings(), BasicUI::ShowMessageBox(), Viewport::ShowTrack(), ProjectAudioManager::Stop(), tracks, CommandManager::UpdateMenus(), wxT(), and XO().

Referenced by MacroCommands::ApplyEffectCommand(), CommandDispatch::HandleTextualCommand(), EffectUIHost::OnApply(), anonymous_namespace{PluginMenus.cpp}::OnEffect(), NyqBench::OnGo(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastAnalyzer(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastEffect(), anonymous_namespace{PluginMenus.cpp}::OnRepeatLastGenerator(), anonymous_namespace{BatchProcessDialog.cpp}::OnRepeatLastTool(), and anonymous_namespace{TrackMenus.cpp}::OnStereoToMono().

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