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

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

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

References DialogFactory(), EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, 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: