Audacity 3.2.0
Functions
EffectUI Namespace Reference

Functions

AUDACITY_DLL_API DialogFactoryResults DialogFactory (wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &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,
EffectPlugin host,
EffectUIClientInterface client,
EffectSettingsAccess access 
)

Definition at line 1202 of file EffectUI.cpp.

1205{
1206 // Make sure there is an associated project, whose lifetime will
1207 // govern the lifetime of the dialog, even when the dialog is
1208 // non-modal, as for realtime effects
1209 auto project = FindProjectFromWindow(&parent);
1210 if ( !project )
1211 return {};
1212 std::shared_ptr<EffectInstance> pInstance;
1214 *project, host, client, pInstance, access } };
1215 if (!pInstance) {
1216 dlg->SetClosed();
1217 return {};
1218 }
1219 if (dlg->Initialize()) {
1220 auto pValidator = dlg->GetValidator();
1221 // release() is safe because parent will own it
1222 return { dlg.release(), pInstance, pValidator };
1223 }
1224 return {};
1225}
#define safenew
Definition: MemoryX.h:10
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:162
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)

References FindProjectFromWindow(), 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 1241 of file EffectUI.cpp.

1243{
1244 AudacityProject &project = context.project;
1245 auto &tracks = TrackList::Get( project );
1246 auto &trackPanel = TrackPanel::Get( project );
1247 auto &trackFactory = WaveTrackFactory::Get( project );
1248 auto rate = ProjectRate::Get(project).GetRate();
1249 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1250 auto &commandManager = CommandManager::Get( project );
1251 auto &window = ProjectWindow::Get( project );
1252
1253 const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
1254
1255 if (!plug || !PluginManager::IsPluginAvailable(*plug))
1256 {
1258 XO("This plugin could not be loaded.\nIt may have been deleted."),
1260 .Caption(XO("Plugin Error")));
1261
1262 return false;
1263 }
1264
1265 EffectType type = plug->GetEffectType();
1266
1267 // Make sure there's no activity since the effect is about to be applied
1268 // to the project's tracks. Mainly for Apply during RTP, but also used
1269 // for batch commands
1270 if (flags & EffectManager::kConfigured)
1271 {
1272 ProjectAudioManager::Get( project ).Stop();
1273 //Don't Select All if repeating Generator Effect
1274 if (!(flags & EffectManager::kConfigured)) {
1276 }
1277 }
1278
1279 auto nTracksOriginally = tracks.size();
1280 wxWindow *focus = wxWindow::FindFocus();
1281 wxWindow *parent = nullptr;
1282 if (focus != nullptr) {
1283 parent = focus->GetParent();
1284 }
1285
1286 bool success = false;
1287 auto cleanup = finally( [&] {
1288
1289 if (!success) {
1290 // For now, we're limiting realtime preview to a single effect, so
1291 // make sure the menus reflect that fact that one may have just been
1292 // opened.
1293 MenuManager::Get(project).UpdateMenus( false );
1294 }
1295
1296 } );
1297
1298 int count = 0;
1299 bool clean = true;
1300 for (auto t : tracks.Selected< const WaveTrack >()) {
1301 if (t->GetEndTime() != 0.0)
1302 clean = false;
1303 count++;
1304 }
1305
1307
1308 em.SetSkipStateFlag( false );
1309 success = false;
1310 if (auto effect = em.GetEffect(ID)) {
1311 if (const auto pSettings = em.GetDefaultSettings(ID)) {
1312 const auto pAccess =
1313 std::make_shared<SimpleEffectSettingsAccess>(*pSettings);
1314 pAccess->ModifySettings([&](EffectSettings &settings){
1315 success = effect->DoEffect(settings,
1316 rate,
1317 &tracks,
1318 &trackFactory,
1319 selectedRegion,
1320 flags,
1321 &window,
1322 (flags & EffectManager::kConfigured) == 0
1324 : nullptr,
1325 pAccess);
1326 return nullptr;
1327 });
1328 }
1329 }
1330
1331 if (!success)
1332 return false;
1333
1334 if (em.GetSkipStateFlag())
1335 flags = flags | EffectManager::kSkipState;
1336
1337 if (!(flags & EffectManager::kSkipState))
1338 {
1339 auto shortDesc = em.GetCommandName(ID);
1340 auto longDesc = em.GetCommandDescription(ID);
1341 ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
1342 }
1343
1344 if (!(flags & EffectManager::kDontRepeatLast))
1345 {
1346 // Remember a successful generator, effect, analyzer, or tool Process
1347 auto shortDesc = em.GetCommandName(ID);
1348 /* i18n-hint: %s will be the name of the effect which will be
1349 * repeated if this menu item is chosen */
1350 auto lastEffectDesc = XO("Repeat %s").Format(shortDesc);
1351 auto& menuManager = MenuManager::Get(project);
1352 switch ( type ) {
1353 case EffectTypeGenerate:
1354 commandManager.Modify(wxT("RepeatLastGenerator"), lastEffectDesc);
1355 menuManager.mLastGenerator = ID;
1356 menuManager.mRepeatGeneratorFlags = EffectManager::kConfigured;
1357 break;
1358 case EffectTypeProcess:
1359 commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
1360 menuManager.mLastEffect = ID;
1361 menuManager.mRepeatEffectFlags = EffectManager::kConfigured;
1362 break;
1363 case EffectTypeAnalyze:
1364 commandManager.Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1365 menuManager.mLastAnalyzer = ID;
1366 menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypeplugin;
1367 menuManager.mRepeatAnalyzerFlags = EffectManager::kConfigured;
1368 break;
1369 case EffectTypeTool:
1370 commandManager.Modify(wxT("RepeatLastTool"), lastEffectDesc);
1371 menuManager.mLastTool = ID;
1372 menuManager.mLastToolRegistration = MenuCreator::repeattypeplugin;
1373 menuManager.mRepeatToolFlags = EffectManager::kConfigured;
1374 if (shortDesc == NYQUIST_PROMPT_NAME) {
1375 menuManager.mRepeatToolFlags = EffectManager::kRepeatNyquistPrompt; //Nyquist Prompt is not configured
1376 }
1377 break;
1378 }
1379 }
1380
1381 //STM:
1382 //The following automatically re-zooms after sound was generated.
1383 // IMO, it was disorienting, removing to try out without re-fitting
1384 //mchinen:12/14/08 reapplying for generate effects
1385 if (type == EffectTypeGenerate)
1386 {
1387 if (count == 0 || (clean && selectedRegion.t0() == 0.0))
1388 window.DoZoomFit();
1389 // trackPanel->Refresh(false);
1390 }
1391
1392 // PRL: RedrawProject explicitly because sometimes history push is skipped
1393 window.RedrawProject();
1394
1395 if (focus != nullptr && focus->GetParent()==parent) {
1396 focus->SetFocus();
1397 }
1398
1399 // A fix for Bug 63
1400 // New tracks added? Scroll them into view so that user sees them.
1401 // Don't care what track type. An analyser might just have added a
1402 // Label track and we want to see it.
1403 if( tracks.size() > nTracksOriginally ){
1404 // 0.0 is min scroll position, 1.0 is max scroll position.
1405 trackPanel.VerticalScroll( 1.0 );
1406 }
1407 else {
1408 auto pTrack = *tracks.Selected().begin();
1409 if (!pTrack)
1410 pTrack = *tracks.Any().begin();
1411 if (pTrack) {
1412 TrackFocus::Get(project).Set(pTrack);
1413 pTrack->EnsureVisible();
1414 }
1415 }
1416
1417 return true;
1418}
wxT("CloseDown"))
EffectType
@ EffectTypeAnalyze
@ EffectTypeGenerate
@ EffectTypeTool
@ EffectTypeProcess
XO("Cut/Copy/Paste")
#define NYQUIST_PROMPT_NAME
static Settings & settings()
Definition: TrackInfo.cpp:87
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)
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)
@ repeattypeplugin
Definition: Menus.h:61
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:575
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
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:97
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:217
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:234
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2797
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
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:269
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1202
void SelectAllIfNone(AudacityProject &project)
Externalized state of a plug-in.

References DialogFactory(), EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, Track::EnsureVisible(), PluginManager::Get(), EffectManager::Get(), TrackFocus::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), CommandManager::Get(), MenuManager::Get(), ProjectAudioManager::Get(), ProjectWindow::Get(), TrackPanel::Get(), WaveTrackFactory::Get(), EffectManager::GetCommandDescription(), EffectManager::GetCommandName(), EffectManager::GetDefaultSettings(), EffectManager::GetEffect(), PluginDescriptor::GetEffectType(), PluginManager::GetPlugin(), ProjectRate::GetRate(), EffectManager::GetSkipStateFlag(), PluginManager::IsPluginAvailable(), EffectManager::kConfigured, EffectManager::kDontRepeatLast, EffectManager::kRepeatNyquistPrompt, EffectManager::kSkipState, NYQUIST_PROMPT_NAME, CommandContext::project, ProjectHistory::PushState(), MenuCreator::repeattypeplugin, SelectUtilities::SelectAllIfNone(), ViewInfo::selectedRegion, EffectManager::SetSkipStateFlag(), settings(), BasicUI::ShowMessageBox(), ProjectAudioManager::Stop(), MenuManager::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: