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 1112 of file EffectUI.cpp.

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

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