mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 07:59:27 +02:00
With EXPERIMENTAL_MODULE_PREFS we now have a dynamic list of modules, and we have options, enable, disable, ask, failed, new (=ask once and remember the answer). Without the #define the behaviour is unchanged. We ask about each module each time Audacity runs.
This commit is contained in:
parent
2b3214049a
commit
55e6a71fd3
@ -34,7 +34,9 @@ i.e. an alternative to the usual interface, for Audacity.
|
|||||||
|
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
#include "Prefs.h"
|
#include "Prefs.h"
|
||||||
|
#include "./prefs/ModulePrefs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "LoadModules.h"
|
#include "LoadModules.h"
|
||||||
#include "widgets/MultiDialog.h"
|
#include "widgets/MultiDialog.h"
|
||||||
|
|
||||||
@ -77,27 +79,6 @@ wxWindow * MakeHijackPanel()
|
|||||||
// starts a thread and reads script commands.
|
// starts a thread and reads script commands.
|
||||||
static tpRegScriptServerFunc scriptFn;
|
static tpRegScriptServerFunc scriptFn;
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
|
||||||
bool IsAllowedModule( wxString fname )
|
|
||||||
{
|
|
||||||
bool bLoad = false;
|
|
||||||
wxString ShortName = wxFileName( fname ).GetName();
|
|
||||||
if( (ShortName.CmpNoCase( wxT("mod-script-pipe")) == 0 ))
|
|
||||||
{
|
|
||||||
gPrefs->Read(wxT("/Module/mod-script-pipe"), &bLoad, false);
|
|
||||||
}
|
|
||||||
else if( (ShortName.CmpNoCase( wxT("mod-nyq-bench")) == 0 ))
|
|
||||||
{
|
|
||||||
gPrefs->Read(wxT("/Module/mod-nyq-bench"), &bLoad, false);
|
|
||||||
}
|
|
||||||
else if( (ShortName.CmpNoCase( wxT("mod-track-panel")) == 0 ))
|
|
||||||
{
|
|
||||||
gPrefs->Read(wxT("/Module/mod-track-panel"), &bLoad, false);
|
|
||||||
}
|
|
||||||
return bLoad;
|
|
||||||
}
|
|
||||||
#endif // EXPERIMENTAL_MODULE_PREFS
|
|
||||||
|
|
||||||
Module::Module(const wxString & name)
|
Module::Module(const wxString & name)
|
||||||
{
|
{
|
||||||
mName = name;
|
mName = name;
|
||||||
@ -236,8 +217,19 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
|
|||||||
::wxSetWorkingDirectory(prefix);
|
::wxSetWorkingDirectory(prefix);
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
if( !IsAllowedModule( files[i] ) ) // don't try and check the in-date-ness before this as that means loading the module to call it's GetVersionString, which could do anything.
|
int iModuleStatus = ModulePrefs::GetModuleStatus( files[i] );
|
||||||
|
if( iModuleStatus == kModuleDisabled )
|
||||||
|
continue;
|
||||||
|
if( iModuleStatus == kModuleFailed )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( (iModuleStatus == kModuleAsk ) ||
|
||||||
|
(iModuleStatus == kModuleNew )
|
||||||
|
)
|
||||||
#endif
|
#endif
|
||||||
|
// JKC: I don't like prompting for the plug-ins individually
|
||||||
|
// I think it would be better to show the module prefs page,
|
||||||
|
// and let the user decide for each one.
|
||||||
{
|
{
|
||||||
wxString ShortName = wxFileName( files[i] ).GetName();
|
wxString ShortName = wxFileName( files[i] ).GetName();
|
||||||
wxString msg;
|
wxString msg;
|
||||||
@ -246,9 +238,22 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
|
|||||||
const wxChar *buttons[] = {_("Yes"), _("No"), NULL}; // could add a button here for 'yes and remember that', and put it into the cfg file. Needs more thought.
|
const wxChar *buttons[] = {_("Yes"), _("No"), NULL}; // could add a button here for 'yes and remember that', and put it into the cfg file. Needs more thought.
|
||||||
int action;
|
int action;
|
||||||
action = ShowMultiDialog(msg, _("Module Loader"), buttons, _("Try and load this module?"), false);
|
action = ShowMultiDialog(msg, _("Module Loader"), buttons, _("Try and load this module?"), false);
|
||||||
if(action == 1) // "No"
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
|
// If we're not prompting always, accept the answer permanantly
|
||||||
|
if( iModuleStatus == kModuleNew ){
|
||||||
|
iModuleStatus = (action==1)?kModuleDisabled : kModuleEnabled;
|
||||||
|
ModulePrefs::SetModuleStatus( files[i], iModuleStatus );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if(action == 1){ // "No"
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
|
// Before attempting to load, we set the state to bad.
|
||||||
|
// That way, if we crash, we won't try again.
|
||||||
|
ModulePrefs::SetModuleStatus( files[i], kModuleFailed );
|
||||||
|
#endif
|
||||||
|
|
||||||
Module *module = new Module(files[i]);
|
Module *module = new Module(files[i]);
|
||||||
if (module->Load()) // it will get rejected if there are version problems
|
if (module->Load()) // it will get rejected if there are version problems
|
||||||
@ -265,8 +270,13 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
|
|||||||
{
|
{
|
||||||
pPanelHijack = (tPanelFn)(module->GetSymbol(wxT(mainPanelFnName)));
|
pPanelHijack = (tPanelFn)(module->GetSymbol(wxT(mainPanelFnName)));
|
||||||
}
|
}
|
||||||
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
|
// Loaded successfully, restore the status.
|
||||||
|
ModulePrefs::SetModuleStatus( files[i], iModuleStatus);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// No need to save status, as we already set kModuleFailed.
|
||||||
delete module;
|
delete module;
|
||||||
}
|
}
|
||||||
::wxSetWorkingDirectory(saveOldCWD);
|
::wxSetWorkingDirectory(saveOldCWD);
|
||||||
|
@ -37,8 +37,41 @@ ModulePrefs::~ModulePrefs()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModulePrefs::GetAllModuleStatuses(){
|
||||||
|
wxString str;
|
||||||
|
long dummy;
|
||||||
|
|
||||||
|
// Modules could for example be:
|
||||||
|
// mod-script-pipe
|
||||||
|
// mod-nyq-bench
|
||||||
|
// mod-track-panel
|
||||||
|
|
||||||
|
mModules.Clear();
|
||||||
|
mStatuses.Clear();
|
||||||
|
|
||||||
|
|
||||||
|
// Iterate through all Modules listed in prefs.
|
||||||
|
// Get their names and values.
|
||||||
|
gPrefs->SetPath( wxT("Module/") );
|
||||||
|
bool bCont = gPrefs->GetFirstEntry(str, dummy);
|
||||||
|
while ( bCont ) {
|
||||||
|
int iStatus;
|
||||||
|
gPrefs->Read( str, &iStatus, kModuleDisabled );
|
||||||
|
if( iStatus > kModuleNew ){
|
||||||
|
iStatus = kModuleNew;
|
||||||
|
gPrefs->Write( str, iStatus );
|
||||||
|
}
|
||||||
|
//wxLogDebug( wxT("Entry: %s Value: %i"), str.c_str(), iStatus );
|
||||||
|
mModules.Add( str );
|
||||||
|
mStatuses.Add( iStatus );
|
||||||
|
bCont = gPrefs->GetNextEntry(str, dummy);
|
||||||
|
}
|
||||||
|
gPrefs->SetPath( wxT("") );
|
||||||
|
}
|
||||||
|
|
||||||
void ModulePrefs::Populate()
|
void ModulePrefs::Populate()
|
||||||
{
|
{
|
||||||
|
GetAllModuleStatuses();
|
||||||
//------------------------- Main section --------------------
|
//------------------------- Main section --------------------
|
||||||
// Now construct the GUI itself.
|
// Now construct the GUI itself.
|
||||||
// Use 'eIsCreatingFromPrefs' so that the GUI is
|
// Use 'eIsCreatingFromPrefs' so that the GUI is
|
||||||
@ -50,20 +83,26 @@ void ModulePrefs::Populate()
|
|||||||
|
|
||||||
void ModulePrefs::PopulateOrExchange(ShuttleGui & S)
|
void ModulePrefs::PopulateOrExchange(ShuttleGui & S)
|
||||||
{
|
{
|
||||||
|
wxArrayString StatusChoices;
|
||||||
|
StatusChoices.Add( _("Disabled" ) );
|
||||||
|
StatusChoices.Add( _("Enabled" ) );
|
||||||
|
StatusChoices.Add( _("Ask" ) );
|
||||||
|
StatusChoices.Add( _("Failed" ) );
|
||||||
|
StatusChoices.Add( _("New" ) );
|
||||||
S.SetBorder(2);
|
S.SetBorder(2);
|
||||||
|
|
||||||
S.StartStatic(_("Enable these Modules (if present), next time Audacity is started"));
|
S.StartStatic(_(""));
|
||||||
{
|
{
|
||||||
S.AddFixedText(_("These are experimental. Enable them only if you've read the manual\nand know what you are doing.") );
|
S.AddFixedText(_("These are experimental Modules. Enable them only if you've read the manual\nand know what you are doing.") );
|
||||||
S.TieCheckBox(_("mod-&script-pipe"),
|
S.AddFixedText(wxString(wxT(" ")) + _("'Ask' means Audacity will ask if you want to load the plug-each time it starts.") );
|
||||||
wxT("/Module/mod-script-pipe"),
|
S.AddFixedText(wxString(wxT(" ")) + _("'Failed' means Audacity thinks the plug-in is broken and won't run it.") );
|
||||||
false);
|
S.AddFixedText(wxString(wxT(" ")) + _("'New' is like 'Ask', but asks just once.") );
|
||||||
S.TieCheckBox(_("mod-&nyq-bench"),
|
S.StartMultiColumn( 2 );
|
||||||
wxT("/Module/mod-nyq-bench"),
|
int i;
|
||||||
false);
|
for(i=0;i<(int)mModules.GetCount();i++)
|
||||||
S.TieCheckBox(_("mod-&track-panel"),
|
S.TieChoice( mModules[i], mStatuses[i], &StatusChoices );
|
||||||
wxT("/Module/mod-track-panel"),
|
S.EndMultiColumn();
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
S.EndStatic();
|
S.EndStatic();
|
||||||
}
|
}
|
||||||
@ -72,6 +111,33 @@ bool ModulePrefs::Apply()
|
|||||||
{
|
{
|
||||||
ShuttleGui S(this, eIsSavingToPrefs);
|
ShuttleGui S(this, eIsSavingToPrefs);
|
||||||
PopulateOrExchange(S);
|
PopulateOrExchange(S);
|
||||||
|
int i;
|
||||||
|
for(i=0;i<(int)mModules.GetCount();i++)
|
||||||
|
SetModuleStatus( mModules[i], mStatuses[i] );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// static function that tells us about a module.
|
||||||
|
int ModulePrefs::GetModuleStatus( wxString fname ){
|
||||||
|
// Default status is new module, and we will ask once.
|
||||||
|
int iStatus = kModuleNew;
|
||||||
|
|
||||||
|
wxString ShortName = wxFileName( fname ).GetName();
|
||||||
|
wxString PrefName = wxString( wxT("/Module/") ) + ShortName.Lower();
|
||||||
|
|
||||||
|
gPrefs->Read( PrefName, &iStatus, kModuleNew );
|
||||||
|
// fix up a bad status.
|
||||||
|
if( iStatus > kModuleNew )
|
||||||
|
iStatus=kModuleNew;
|
||||||
|
return iStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModulePrefs::SetModuleStatus( wxString fname, int iStatus ){
|
||||||
|
wxString ShortName = wxFileName( fname ).GetName();
|
||||||
|
wxString PrefName = wxString( wxT("/Module/") ) + ShortName.Lower();
|
||||||
|
gPrefs->Write( PrefName, iStatus );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
|
|
||||||
#include "PrefsPanel.h"
|
#include "PrefsPanel.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kModuleDisabled = 0,
|
||||||
|
kModuleEnabled = 1,
|
||||||
|
kModuleAsk = 2, // Will ask, each time, when audacity starts.
|
||||||
|
kModuleFailed = 3, // Audacity thinks this is a bad module.
|
||||||
|
kModuleNew = 4 // Audacity will ask once, and remember the answer.
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class ModulePrefs:public PrefsPanel
|
class ModulePrefs:public PrefsPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -28,9 +38,15 @@ class ModulePrefs:public PrefsPanel
|
|||||||
~ModulePrefs();
|
~ModulePrefs();
|
||||||
virtual bool Apply();
|
virtual bool Apply();
|
||||||
|
|
||||||
|
static int GetModuleStatus( wxString fname );
|
||||||
|
static void SetModuleStatus( wxString fname, int iStatus );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void GetAllModuleStatuses();
|
||||||
void Populate();
|
void Populate();
|
||||||
void PopulateOrExchange(ShuttleGui & S);
|
void PopulateOrExchange(ShuttleGui & S);
|
||||||
|
wxArrayString mModules;
|
||||||
|
wxArrayInt mStatuses;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user