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

1108{
1109 // Make sure there is an associated project, whose lifetime will
1110 // govern the lifetime of the dialog, even when the dialog is
1111 // non-modal, as for realtime effects
1112 auto project = FindProjectFromWindow(&parent);
1113 if ( !project )
1114 return {};
1115 std::shared_ptr<EffectInstance> pInstance;
1117 *project, host, client, pInstance, access } };
1118 if (!pInstance) {
1119 dlg->SetClosed();
1120 return {};
1121 }
1122 if (dlg->Initialize()) {
1123 auto pEditor = dlg->GetEditor();
1124 // release() is safe because parent will own it
1125 return { dlg.release(), pInstance, pEditor };
1126 }
1127 return {};
1128}
#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 1144 of file EffectUI.cpp.

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

References DialogFactory(), EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, Track::EnsureVisible(), BasicUI::FindFocus(), PluginManager::Get(), EffectManager::Get(), TrackFocus::Get(), ProjectHistory::Get(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), WaveTrackFactory::Get(), CommandManager::Get(), MenuManager::Get(), ProjectAudioManager::Get(), ProjectWindow::Get(), TrackPanel::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: