1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-03 09:29:30 +02:00

Adding the ability to load 'non-recognised' modules, with a warning to the user (the main point).

Removing duplicate code from LoadModules, at the expense of making  ModuleManager::Initialize more monolithic.

Make MultiDialog a bit more general.

Remove a few warnings.

Some logging has been turned back on when loading libs, we could turn it off again.

To test you could compile mod-nyq-bench and make sure it is available on the bottom of the 'View' menu, then unselect it in the Prefs -> Modules an retry.
This commit is contained in:
martynshaw99 2013-06-05 00:35:10 +00:00
parent 44c03e7de8
commit 37f74e27bb
5 changed files with 78 additions and 138 deletions

View File

@ -1128,14 +1128,11 @@ bool AudacityApp::OnInit()
wxFrame *temporarywindow = new wxFrame(NULL, -1, wxT("temporarytopwindow"));
SetTopWindow(temporarywindow);
// Initialize the ModuleManager
ModuleManager::Initialize();
// Initialize the CommandHandler
InitCommandHandler();
// load audacity plug-in modules
LoadModules(*mCmdHandler);
// Initialize the ModuleManager, including loading found modules
ModuleManager::Initialize(*mCmdHandler);
// Locale
// wxWidgets 2.3 has a much nicer wxLocale API. We can make this code much

View File

@ -33,6 +33,7 @@ i.e. an alternative to the usual interface, for Audacity.
#include "Prefs.h"
#include "LoadModules.h"
#include "widgets/MultiDialog.h"
#define initFnName "ExtensionModuleInit"
#define versionFnName "GetVersionString"
@ -92,84 +93,6 @@ bool IsAllowedModule( wxString fname )
return bLoad;
}
void LoadModule(wxString fname)
{
if( !IsAllowedModule( fname ) )
return;
wxLogDebug(wxT("About to load module %s"), fname.c_str());
wxLogNull logNo; // Don't show wxWidgets Error if cannot load within this method. (Fix bug 544.)
tModuleInit mainFn = NULL;
// As a courtesy to some modules that might be bridges to
// open other modules, we set the current working
// directory to be the module's directory.
wxString saveOldCWD = ::wxGetCwd();
wxString prefix = ::wxPathOnly(fname);
::wxSetWorkingDirectory(prefix);
wxDynamicLibrary* pDLL = new wxDynamicLibrary();
if (pDLL && pDLL->Load(fname, wxDL_LAZY))
{
// We've loaded and initialised OK.
// So look for special case functions:
// (a) for scripting.
if( scriptFn == NULL )
scriptFn = (tpRegScriptServerFunc)(pDLL->GetSymbol(wxT(scriptFnName)));
// (b) for hijacking the entire Audacity panel.
if( pPanelHijack==NULL )
pPanelHijack = (tPanelFn)(pDLL->GetSymbol(wxT(mainPanelFnName)));
}
::wxSetWorkingDirectory(saveOldCWD);
}
void LoadModules(CommandHandler &cmdHandler)
{
wxArrayString audacityPathList = wxGetApp().audacityPathList;
wxArrayString pathList;
wxArrayString files;
wxString pathVar;
unsigned int i;
#if 0
// Code from LoadLadspa that might be useful in load modules.
pathVar = wxGetenv(wxT("AUDACITY_MODULES_PATH"));
if (pathVar != wxT(""))
wxGetApp().AddMultiPathsToPathList(pathVar, pathList);
#ifdef __WXGTK__
wxGetApp().AddUniquePathToPathList(INSTALL_PREFIX wxT("/modules"), pathList);
wxGetApp().AddUniquePathToPathList(wxT("/usr/local/lib/modules"), pathList);
wxGetApp().AddUniquePathToPathList(wxT("/usr/lib/modules"), pathList);
#endif
#endif
for(i=0; i<audacityPathList.GetCount(); i++) {
wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
wxGetApp().AddUniquePathToPathList(prefix + wxT("modules"),
pathList);
}
#ifdef __WXMSW__
wxGetApp().FindFilesInPathList(wxT("*.dll"), pathList, files);
#else
wxGetApp().FindFilesInPathList(wxT("*.so"), pathList, files);
#endif
for(i=0; i<files.GetCount(); i++)
LoadModule(files[i]);
// After loading all the modules, we may have a registered scripting function.
if(scriptFn)
{
ScriptCommandRelay::SetCommandHandler(cmdHandler);
ScriptCommandRelay::SetRegScriptServerFunc(scriptFn);
NonGuiThread::StartChild(&ScriptCommandRelay::Run);
}
}
Module::Module(const wxString & name)
{
mName = name;
@ -184,7 +107,7 @@ Module::~Module()
bool Module::Load()
{
wxLogNull logNo;
// wxLogNull logNo;
if (mLib->IsLoaded()) {
if (mDispatch) {
@ -243,8 +166,13 @@ int Module::Dispatch(ModuleDispatchTypes type)
return 0;
}
void * Module::GetSymbol(wxString name)
{
return mLib->GetSymbol(name);
}
//
// Module Manager (using wxPluginManager would be MUCH better)
// Module Manager
//
ModuleManager *ModuleManager::mInstance;
@ -265,7 +193,7 @@ void ModuleManager::OnExit()
mModules.Clear();
}
void ModuleManager::Initialize()
void ModuleManager::Initialize(CommandHandler &cmdHandler)
{
wxArrayString audacityPathList = wxGetApp().audacityPathList;
wxArrayString pathList;
@ -273,12 +201,10 @@ void ModuleManager::Initialize()
wxString pathVar;
size_t i;
// JKC: Is this code duplicating LoadModules() ????
// Code from LoadLadspa that might be useful in load modules.
pathVar = wxGetenv(wxT("AUDACITY_MODULES_PATH"));
if (pathVar != wxT("")) {
if (pathVar != wxT(""))
wxGetApp().AddMultiPathsToPathList(pathVar, pathList);
}
for (i = 0; i < audacityPathList.GetCount(); i++) {
wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
@ -288,24 +214,59 @@ void ModuleManager::Initialize()
#if defined(__WXMSW__)
wxGetApp().FindFilesInPathList(wxT("*.dll"), pathList, files);
// #elif defined(__WXMAC__)
// wxGetApp().FindFilesInPathList(wxT("*.dylib"), pathList, files);
#else
wxGetApp().FindFilesInPathList(wxT("*.so"), pathList, files);
#endif
for (i = 0; i < files.GetCount(); i++) {
if( IsAllowedModule( files[i] ) )
if( !IsAllowedModule( files[i] ) )
{
wxString ShortName = wxFileName( files[i] ).GetName();
wxString msg;
msg.Printf(_("Unkown Module \"%s\""), ShortName.c_str());
const wxChar *buttons[] = {_("Yes"), _("No"), NULL}; // could add a button here for 'yes and remember that', and put it into the cfg file
int action;
action = ShowMultiDialog(msg, _("Warning - Unknown Module"), buttons, _("Load this module?"), false);
if(action == 1) // "No"
continue;
wxLogDebug(wxT("Unknown module %s accepted"), ShortName.c_str());
}
wxLogDebug(wxT("About to load module %s"), wxFileName( files[i] ).GetName().c_str());
// As a courtesy to some modules that might be bridges to
// open other modules, we set the current working
// directory to be the module's directory.
wxString saveOldCWD = ::wxGetCwd();
wxString prefix = ::wxPathOnly(files[i]);
::wxSetWorkingDirectory(prefix);
Module *module = new Module(files[i]);
if (module->Load()) {
mInstance->mModules.Add(module);
// We've loaded and initialised OK.
// So look for special case functions:
wxLogNull logNo; // Don't show wxWidgets errors if we can't do these. (Was: Fix bug 544.)
// (a) for scripting.
if( scriptFn == NULL )
scriptFn = (tpRegScriptServerFunc)(module->GetSymbol(wxT(scriptFnName)));
// (b) for hijacking the entire Audacity panel.
if( pPanelHijack==NULL )
{
pPanelHijack = (tPanelFn)(module->GetSymbol(wxT(mainPanelFnName)));
}
}
else {
delete module;
}
::wxSetWorkingDirectory(saveOldCWD);
}
// After loading all the modules, we may have a registered scripting function.
if(scriptFn)
{
ScriptCommandRelay::SetCommandHandler(cmdHandler);
ScriptCommandRelay::SetRegScriptServerFunc(scriptFn);
NonGuiThread::StartChild(&ScriptCommandRelay::Run);
}
}
@ -322,14 +283,3 @@ int ModuleManager::Dispatch(ModuleDispatchTypes type)
}
IMPLEMENT_DYNAMIC_CLASS(ModuleManager, wxModule);
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3

View File

@ -17,9 +17,6 @@
class CommandHandler;
void LoadModules(CommandHandler &cmdHandler);
void LoadModule(wxString fname);
wxWindow * MakeHijackPanel();
//
@ -51,6 +48,7 @@ public:
bool Load();
void Unload();
int Dispatch(ModuleDispatchTypes type);
void * GetSymbol(wxString name);
private:
wxString mName;
@ -67,7 +65,7 @@ public:
virtual bool OnInit();
virtual void OnExit();
static void Initialize();
static void Initialize(CommandHandler &cmdHandler);
static int Dispatch(ModuleDispatchTypes type);
private:
@ -79,14 +77,3 @@ private:
};
#endif /* __AUDACITY_LOADMODULES_H__ */
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3

View File

@ -38,7 +38,7 @@ class MultiDialog : public wxDialog
public:
MultiDialog(wxString message,
wxString title,
const wxChar **buttons);
const wxChar **buttons, wxString boxMsg, bool log);
~MultiDialog() {};
private:
@ -59,7 +59,7 @@ END_EVENT_TABLE()
MultiDialog::MultiDialog(wxString message,
wxString title,
const wxChar **buttons)
const wxChar **buttons, wxString boxMsg, bool log)
: wxDialog(NULL, (wxWindowID)-1, title,
wxDefaultPosition, wxDefaultSize,
wxCAPTION) // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
@ -91,24 +91,30 @@ MultiDialog::MultiDialog(wxString message,
}
mRadioBox = new wxRadioBox(this,-1,
_(" Please select an action "),
boxMsg,
wxDefaultPosition, wxDefaultSize,
count, buttonLabels,
1, wxRA_SPECIFY_COLS);
mRadioBox->SetName(_("Please select an action"));
mRadioBox->SetName(boxMsg);
mRadioBox->SetSelection(0);
vSizer->Add(mRadioBox, 1, wxEXPAND | wxALIGN_CENTER | wxALL, 5);
wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* pButton = new wxButton(this, ID_SHOW_LOG_BUTTON, _("Show Log for Details"));
wxButton* pButton;
if(log)
{
pButton = new wxButton(this, ID_SHOW_LOG_BUTTON, _("Show Log for Details"));
buttonSizer->Add(pButton, 0, wxALIGN_LEFT | wxALL, 5);
pButton->SetDefault(); // Encourage user to look at files.
buttonSizer->AddSpacer(40);
}
pButton = new wxButton(this, wxID_OK, _("OK"));
if(!log)
pButton->SetDefault();
buttonSizer->Add(pButton, 0, wxALIGN_RIGHT | wxALL, 5);
vSizer->Add(buttonSizer, 0, wxALIGN_CENTER | wxALL, 5);
@ -122,12 +128,12 @@ MultiDialog::MultiDialog(wxString message,
delete[] buttonLabels;
}
void MultiDialog::OnOK(wxCommandEvent &event)
void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{
EndModal(mRadioBox->GetSelection());
}
void MultiDialog::OnShowLog(wxCommandEvent &event)
void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
{
GetActiveProject()->OnShowLog();
}
@ -135,9 +141,9 @@ void MultiDialog::OnShowLog(wxCommandEvent &event)
int ShowMultiDialog(wxString message,
wxString title,
const wxChar **buttons)
const wxChar **buttons, wxString boxMsg, bool log)
{
MultiDialog dlog(message, title, buttons);
MultiDialog dlog(message, title, buttons, boxMsg, log);
dlog.CentreOnParent();
return dlog.ShowModal();
}

View File

@ -21,6 +21,6 @@
// Return the zero-based index of the chosen button.
int ShowMultiDialog(wxString message,
wxString title,
const wxChar **buttons);
const wxChar **buttons, wxString boxMsg = _("Please select an action"), bool log = true);
#endif // __AUDACITY_MULTIDIALOG__