Audacity 3.2.0
Functions
EffectUI Namespace Reference

Functions

AUDACITY_DLL_API wxDialog * DialogFactory (wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access)
 
AUDACITY_DLL_API bool DoEffect (const PluginID &ID, const CommandContext &context, unsigned flags)
 'Repeat Last Effect'. More...
 

Function Documentation

◆ DialogFactory()

wxDialog * EffectUI::DialogFactory ( wxWindow &  parent,
EffectPlugin host,
EffectUIClientInterface client,
std::shared_ptr< EffectInstance > &  pInstance,
EffectSettingsAccess access 
)

Definition at line 1295 of file EffectUI.cpp.

1300{
1301 // Make sure there is an associated project, whose lifetime will
1302 // govern the lifetime of the dialog, even when the dialog is
1303 // non-modal, as for realtime effects
1304 auto project = FindProjectFromWindow(&parent);
1305 if ( !project )
1306 return nullptr;
1308 *project, host, client, pInstance, access } };
1309 if (dlg->Initialize())
1310 // release() is safe because parent will own it
1311 return dlg.release();
1312 return nullptr;
1313}
#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 1329 of file EffectUI.cpp.

1331{
1332 AudacityProject &project = context.project;
1333 auto &tracks = TrackList::Get( project );
1334 auto &trackPanel = TrackPanel::Get( project );
1335 auto &trackFactory = WaveTrackFactory::Get( project );
1336 auto rate = ProjectRate::Get(project).GetRate();
1337 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1338 auto &commandManager = CommandManager::Get( project );
1339 auto &window = ProjectWindow::Get( project );
1340
1341 const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
1342 if (!plug)
1343 return false;
1344
1345 EffectType type = plug->GetEffectType();
1346
1347 // Make sure there's no activity since the effect is about to be applied
1348 // to the project's tracks. Mainly for Apply during RTP, but also used
1349 // for batch commands
1350 if (flags & EffectManager::kConfigured)
1351 {
1352 ProjectAudioManager::Get( project ).Stop();
1353 //Don't Select All if repeating Generator Effect
1354 if (!(flags & EffectManager::kConfigured)) {
1356 }
1357 }
1358
1359 auto nTracksOriginally = tracks.size();
1360 wxWindow *focus = wxWindow::FindFocus();
1361 wxWindow *parent = nullptr;
1362 if (focus != nullptr) {
1363 parent = focus->GetParent();
1364 }
1365
1366 bool success = false;
1367 auto cleanup = finally( [&] {
1368
1369 if (!success) {
1370 // For now, we're limiting realtime preview to a single effect, so
1371 // make sure the menus reflect that fact that one may have just been
1372 // opened.
1373 MenuManager::Get(project).UpdateMenus( false );
1374 }
1375
1376 } );
1377
1378 int count = 0;
1379 bool clean = true;
1380 for (auto t : tracks.Selected< const WaveTrack >()) {
1381 if (t->GetEndTime() != 0.0)
1382 clean = false;
1383 count++;
1384 }
1385
1387
1388 em.SetSkipStateFlag( false );
1389 success = false;
1390 if (auto effect = em.GetEffect(ID)) {
1391 if (const auto pSettings = em.GetDefaultSettings(ID)) {
1392 const auto pAccess =
1393 std::make_shared<SimpleEffectSettingsAccess>(*pSettings);
1394 pAccess->ModifySettings([&](EffectSettings &settings){
1395 success = effect->DoEffect(settings,
1396 rate,
1397 &tracks,
1398 &trackFactory,
1399 selectedRegion,
1400 flags,
1401 &window,
1402 (flags & EffectManager::kConfigured) == 0
1404 : nullptr,
1405 pAccess);
1406 });
1407 }
1408 }
1409
1410 if (!success)
1411 return false;
1412
1413 if (em.GetSkipStateFlag())
1414 flags = flags | EffectManager::kSkipState;
1415
1416 if (!(flags & EffectManager::kSkipState))
1417 {
1418 auto shortDesc = em.GetCommandName(ID);
1419 auto longDesc = em.GetCommandDescription(ID);
1420 ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
1421 }
1422
1423 if (!(flags & EffectManager::kDontRepeatLast))
1424 {
1425 // Remember a successful generator, effect, analyzer, or tool Process
1426 auto shortDesc = em.GetCommandName(ID);
1427 /* i18n-hint: %s will be the name of the effect which will be
1428 * repeated if this menu item is chosen */
1429 auto lastEffectDesc = XO("Repeat %s").Format(shortDesc);
1430 auto& menuManager = MenuManager::Get(project);
1431 switch ( type ) {
1432 case EffectTypeGenerate:
1433 commandManager.Modify(wxT("RepeatLastGenerator"), lastEffectDesc);
1434 menuManager.mLastGenerator = ID;
1435 menuManager.mRepeatGeneratorFlags = EffectManager::kConfigured;
1436 break;
1437 case EffectTypeProcess:
1438 commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
1439 menuManager.mLastEffect = ID;
1440 menuManager.mRepeatEffectFlags = EffectManager::kConfigured;
1441 break;
1442 case EffectTypeAnalyze:
1443 commandManager.Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1444 menuManager.mLastAnalyzer = ID;
1445 menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypeplugin;
1446 menuManager.mRepeatAnalyzerFlags = EffectManager::kConfigured;
1447 break;
1448 case EffectTypeTool:
1449 commandManager.Modify(wxT("RepeatLastTool"), lastEffectDesc);
1450 menuManager.mLastTool = ID;
1451 menuManager.mLastToolRegistration = MenuCreator::repeattypeplugin;
1452 menuManager.mRepeatToolFlags = EffectManager::kConfigured;
1453 if (shortDesc == NYQUIST_PROMPT_NAME) {
1454 menuManager.mRepeatToolFlags = EffectManager::kRepeatNyquistPrompt; //Nyquist Prompt is not configured
1455 }
1456 break;
1457 }
1458 }
1459
1460 //STM:
1461 //The following automatically re-zooms after sound was generated.
1462 // IMO, it was disorienting, removing to try out without re-fitting
1463 //mchinen:12/14/08 reapplying for generate effects
1464 if (type == EffectTypeGenerate)
1465 {
1466 if (count == 0 || (clean && selectedRegion.t0() == 0.0))
1467 window.DoZoomFit();
1468 // trackPanel->Refresh(false);
1469 }
1470
1471 // PRL: RedrawProject explicitly because sometimes history push is skipped
1472 window.RedrawProject();
1473
1474 if (focus != nullptr && focus->GetParent()==parent) {
1475 focus->SetFocus();
1476 }
1477
1478 // A fix for Bug 63
1479 // New tracks added? Scroll them into view so that user sees them.
1480 // Don't care what track type. An analyser might just have added a
1481 // Label track and we want to see it.
1482 if( tracks.size() > nTracksOriginally ){
1483 // 0.0 is min scroll position, 1.0 is max scroll position.
1484 trackPanel.VerticalScroll( 1.0 );
1485 }
1486 else {
1487 auto pTrack = *tracks.Selected().begin();
1488 if (!pTrack)
1489 pTrack = *tracks.Any().begin();
1490 if (pTrack) {
1491 TrackFocus::Get(project).Set(pTrack);
1492 pTrack->EnsureVisible();
1493 }
1494 }
1495
1496 return true;
1497}
EffectType
@ EffectTypeAnalyze
@ EffectTypeGenerate
@ EffectTypeTool
@ EffectTypeProcess
#define XO(s)
Definition: Internat.h:31
#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:89
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:62
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:643
EffectType GetEffectType() const
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:98
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:468
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2802
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
AUDACITY_DLL_API wxDialog * DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1295
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(), EffectManager::kConfigured, EffectManager::kDontRepeatLast, EffectManager::kRepeatNyquistPrompt, EffectManager::kSkipState, NYQUIST_PROMPT_NAME, CommandContext::project, ProjectHistory::PushState(), MenuCreator::repeattypeplugin, SelectUtilities::SelectAllIfNone(), ViewInfo::selectedRegion, EffectManager::SetSkipStateFlag(), settings(), ProjectAudioManager::Stop(), MenuManager::UpdateMenus(), and XO.

Referenced by MacroCommands::ApplyEffectCommand(), HandleTextualCommand(), EffectUIHost::OnApply(), PluginActions::Handler::OnEffect(), NyqBench::OnGo(), PluginActions::Handler::OnRepeatLastAnalyzer(), PluginActions::Handler::OnRepeatLastEffect(), PluginActions::Handler::OnRepeatLastGenerator(), PluginActions::Handler::OnRepeatLastTool(), and TrackActions::Handler::OnStereoToMono().

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