Audacity  3.0.3
Functions
EffectUI Namespace Reference

Functions

AUDACITY_DLL_API wxDialog * DialogFactory (wxWindow &parent, EffectHostInterface *pHost, EffectUIClientInterface *client)
 
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,
EffectHostInterface pHost,
EffectUIClientInterface client 
)

Definition at line 1819 of file EffectUI.cpp.

1821 {
1822  auto pEffect = dynamic_cast< Effect* >( pHost );
1823  if ( ! pEffect )
1824  return nullptr;
1825 
1826  // Make sure there is an associated project, whose lifetime will
1827  // govern the lifetime of the dialog, even when the dialog is
1828  // non-modal, as for realtime effects
1829  auto project = FindProjectFromWindow(&parent);
1830  if ( !project )
1831  return nullptr;
1832 
1834  safenew EffectUIHost{ &parent, *project, pEffect, client} };
1835 
1836  if (dlg->Initialize())
1837  {
1838  // release() is safe because parent will own it
1839  return dlg.release();
1840  }
1841 
1842  return nullptr;
1843 };

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

1861 {
1862  AudacityProject &project = context.project;
1863  const auto &settings = ProjectSettings::Get( project );
1864  auto &tracks = TrackList::Get( project );
1865  auto &trackPanel = TrackPanel::Get( project );
1866  auto &trackFactory = WaveTrackFactory::Get( project );
1867  auto rate = settings.GetRate();
1868  auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
1869  auto &commandManager = CommandManager::Get( project );
1870  auto &window = ProjectWindow::Get( project );
1871 
1872  const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
1873  if (!plug)
1874  return false;
1875 
1876  EffectType type = plug->GetEffectType();
1877 
1878  // Make sure there's no activity since the effect is about to be applied
1879  // to the project's tracks. Mainly for Apply during RTP, but also used
1880  // for batch commands
1881  if (flags & EffectManager::kConfigured)
1882  {
1883  ProjectAudioManager::Get( project ).Stop();
1884  //Don't Select All if repeating Generator Effect
1885  if (!(flags & EffectManager::kConfigured)) {
1887  }
1888  }
1889 
1890  auto nTracksOriginally = tracks.size();
1891  wxWindow *focus = wxWindow::FindFocus();
1892  wxWindow *parent = nullptr;
1893  if (focus != nullptr) {
1894  parent = focus->GetParent();
1895  }
1896 
1897  bool success = false;
1898  auto cleanup = finally( [&] {
1899 
1900  if (!success) {
1901  // For now, we're limiting realtime preview to a single effect, so
1902  // make sure the menus reflect that fact that one may have just been
1903  // opened.
1904  MenuManager::Get(project).UpdateMenus( false );
1905  }
1906 
1907  } );
1908 
1909  int count = 0;
1910  bool clean = true;
1911  for (auto t : tracks.Selected< const WaveTrack >()) {
1912  if (t->GetEndTime() != 0.0)
1913  clean = false;
1914  count++;
1915  }
1916 
1918 
1919  em.SetSkipStateFlag( false );
1920  if (auto effect = em.GetEffect(ID)) {
1921 #if defined(EXPERIMENTAL_EFFECTS_RACK)
1922  if (effect->SupportsRealtime())
1923  {
1924  EffectRack::Get( context.project ).Add(effect);
1925  }
1926 #endif
1927  effect->SetUIFlags(flags);
1928  success = effect->DoEffect(
1929  rate,
1930  &tracks,
1931  &trackFactory,
1932  selectedRegion,
1933  &window,
1934  (flags & EffectManager::kConfigured) == 0
1935  ? DialogFactory
1936  : nullptr
1937  );
1938  }
1939  else
1940  success = false;
1941 
1942  if (!success)
1943  return false;
1944 
1945  if (em.GetSkipStateFlag())
1946  flags = flags | EffectManager::kSkipState;
1947 
1948  if (!(flags & EffectManager::kSkipState))
1949  {
1950  auto shortDesc = em.GetCommandName(ID);
1951  auto longDesc = em.GetCommandDescription(ID);
1952  ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
1953  }
1954 
1955  if (!(flags & EffectManager::kDontRepeatLast))
1956  {
1957  // Remember a successful generator, effect, analyzer, or tool Process
1958  auto shortDesc = em.GetCommandName(ID);
1959  /* i18n-hint: %s will be the name of the effect which will be
1960  * repeated if this menu item is chosen */
1961  auto lastEffectDesc = XO("Repeat %s").Format(shortDesc);
1962  auto& menuManager = MenuManager::Get(project);
1963  switch ( type ) {
1964  case EffectTypeGenerate:
1965  commandManager.Modify(wxT("RepeatLastGenerator"), lastEffectDesc);
1966  menuManager.mLastGenerator = ID;
1967  menuManager.mRepeatGeneratorFlags = EffectManager::kConfigured;
1968  break;
1969  case EffectTypeProcess:
1970  commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
1971  menuManager.mLastEffect = ID;
1972  menuManager.mRepeatEffectFlags = EffectManager::kConfigured;
1973  break;
1974  case EffectTypeAnalyze:
1975  commandManager.Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
1976  menuManager.mLastAnalyzer = ID;
1977  menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypeplugin;
1978  menuManager.mRepeatAnalyzerFlags = EffectManager::kConfigured;
1979  break;
1980  case EffectTypeTool:
1981  commandManager.Modify(wxT("RepeatLastTool"), lastEffectDesc);
1982  menuManager.mLastTool = ID;
1983  menuManager.mLastToolRegistration = MenuCreator::repeattypeplugin;
1984  menuManager.mRepeatToolFlags = EffectManager::kConfigured;
1985  if (shortDesc == NYQUIST_PROMPT_NAME) {
1986  menuManager.mRepeatToolFlags = EffectManager::kRepeatNyquistPrompt; //Nyquist Prompt is not configured
1987  }
1988  break;
1989  }
1990  }
1991 
1992  //STM:
1993  //The following automatically re-zooms after sound was generated.
1994  // IMO, it was disorienting, removing to try out without re-fitting
1995  //mchinen:12/14/08 reapplying for generate effects
1996  if (type == EffectTypeGenerate)
1997  {
1998  if (count == 0 || (clean && selectedRegion.t0() == 0.0))
1999  window.DoZoomFit();
2000  // trackPanel->Refresh(false);
2001  }
2002 
2003  // PRL: RedrawProject explicitly because sometimes history push is skipped
2004  window.RedrawProject();
2005 
2006  if (focus != nullptr && focus->GetParent()==parent) {
2007  focus->SetFocus();
2008  }
2009 
2010  // A fix for Bug 63
2011  // New tracks added? Scroll them into view so that user sees them.
2012  // Don't care what track type. An analyser might just have added a
2013  // Label track and we want to see it.
2014  if( tracks.size() > nTracksOriginally ){
2015  // 0.0 is min scroll position, 1.0 is max scroll position.
2016  trackPanel.VerticalScroll( 1.0 );
2017  }
2018  else {
2019  auto pTrack = *tracks.Selected().begin();
2020  if (!pTrack)
2021  pTrack = *tracks.Any().begin();
2022  if (pTrack) {
2023  TrackFocus::Get(project).Set(pTrack);
2024  pTrack->EnsureVisible();
2025  }
2026  }
2027 
2028  return true;
2029 }

References DialogFactory(), Effect::DoEffect(), EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, Track::EnsureVisible(), EffectManager::Get(), PluginManager::Get(), TrackFocus::Get(), CommandManager::Get(), MenuManager::Get(), ProjectAudioManager::Get(), ProjectHistory::Get(), ProjectSettings::Get(), ProjectWindow::Get(), TrackList::Get(), TrackPanel::Get(), ViewInfo::Get(), WaveTrackFactory::Get(), EffectManager::GetCommandDescription(), EffectManager::GetCommandName(), EffectManager::GetEffect(), PluginDescriptor::GetEffectType(), PluginManager::GetPlugin(), 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(), Effect::SetUIFlags(), ProjectAudioManager::Stop(), Effect::SupportsRealtime(), MenuManager::UpdateMenus(), and XO.

Referenced by MacroCommands::ApplyEffectCommand(), MacroCommands::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:
EffectManager::GetSkipStateFlag
bool GetSkipStateFlag()
Definition: EffectManager.cpp:218
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:156
WaveTrackFactory::Get
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2803
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
ProjectAudioManager::Get
static ProjectAudioManager & Get(AudacityProject &project)
Definition: ProjectAudioManager.cpp:51
Track::EnsureVisible
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:101
Effect
Base class for many of the effects in Audacity.
Definition: Effect.h:70
EffectTypeGenerate
@ EffectTypeGenerate
Definition: EffectInterface.h:58
EffectManager::kConfigured
@ kConfigured
Definition: EffectManager.h:53
EffectManager::kDontRepeatLast
@ kDontRepeatLast
Definition: EffectManager.h:57
EffectManager::GetCommandName
TranslatableString GetCommandName(const PluginID &ID)
Definition: EffectManager.cpp:101
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:222
XO
#define XO(s)
Definition: Internat.h:31
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:40
ProjectWindow::Get
static ProjectWindow & Get(AudacityProject &project)
Definition: ProjectWindow.cpp:532
FindProjectFromWindow
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
Definition: ProjectWindowBase.cpp:39
EffectManager::Get
static EffectManager & Get()
Definition: EffectManager.cpp:42
MenuCreator::repeattypeplugin
@ repeattypeplugin
Definition: Menus.h:62
EffectUI::DialogFactory
AUDACITY_DLL_API wxDialog * DialogFactory(wxWindow &parent, EffectHostInterface *pHost, EffectUIClientInterface *client)
Definition: EffectUI.cpp:1819
EffectManager::SetSkipStateFlag
void SetSkipStateFlag(bool flag)
Definition: EffectManager.cpp:213
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:199
EffectManager
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:46
MenuManager::UpdateMenus
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:634
EffectManager::GetEffect
Effect * GetEffect(const PluginID &ID)
Definition: EffectManager.cpp:706
NYQUIST_PROMPT_NAME
#define NYQUIST_PROMPT_NAME
Definition: PluginManager.h:334
SelectUtilities::SelectAllIfNone
void SelectAllIfNone(AudacityProject &project)
Definition: SelectUtilities.cpp:84
EffectTypeTool
@ EffectTypeTool
Definition: EffectInterface.h:61
TrackFocus::Get
Track * Get()
Definition: TrackPanelAx.cpp:755
PluginDescriptor
Definition: PluginManager.h:46
ProjectAudioManager::Stop
void Stop(bool stopStream=true)
Definition: ProjectAudioManager.cpp:309
EffectManager::kRepeatNyquistPrompt
@ kRepeatNyquistPrompt
Definition: EffectManager.h:61
ProjectHistory::PushState
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
Definition: ProjectHistory.cpp:90
PluginManager::Get
static PluginManager & Get()
Definition: PluginManager.cpp:1766
PluginDescriptor::GetEffectType
EffectType GetEffectType() const
Definition: PluginManager.cpp:1247
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:495
EffectTypeAnalyze
@ EffectTypeAnalyze
Definition: EffectInterface.h:60
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
EffectUIHost
Definition: EffectUI.h:119
EffectManager::kSkipState
@ kSkipState
Definition: EffectManager.h:55
EffectManager::GetCommandDescription
TranslatableString GetCommandDescription(const PluginID &ID)
Definition: EffectManager.cpp:128
CommandManager::Get
static CommandManager & Get(AudacityProject &project)
Definition: CommandManager.cpp:202
Destroy_ptr
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:289
EffectType
EffectType
Definition: EffectInterface.h:55
safenew
#define safenew
Definition: MemoryX.h:10
settings
static Settings & settings()
Definition: TrackInfo.cpp:87
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:52
PluginManager::GetPlugin
const PluginDescriptor * GetPlugin(const PluginID &ID)
Definition: PluginManager.cpp:2546
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26