1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 08:09:41 +02:00

Each command class registers itself

This commit is contained in:
Paul Licameli 2019-01-17 11:45:51 -05:00
parent 0ca5775234
commit 2522459637
19 changed files with 105 additions and 0 deletions

View File

@ -21,6 +21,7 @@ threshold of difference in two selected tracks
#include "../Audacity.h"
#include "CompareAudioCommand.h"
#include "LoadCommands.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
@ -37,6 +38,8 @@ threshold of difference in two selected tracks
const ComponentInterfaceSymbol CompareAudioCommand::Symbol
{ XO("Compare Audio") };
namespace{ BuiltinCommandsModule::Registration< CompareAudioCommand > reg; }
extern void RegisterCompareAudio( Registrar & R){
R.AddCommand( std::make_unique<CompareAudioCommand>() );
// std::unique_ptr<CommandOutputTargets> &&target

View File

@ -21,6 +21,7 @@ parameters. It is for development purposes.
#include "../Audacity.h"
#include "Demo.h"
#include "LoadCommands.h"
#include <float.h>
@ -35,6 +36,8 @@ parameters. It is for development purposes.
const ComponentInterfaceSymbol DemoCommand::Symbol
{ XO("Demo") };
namespace{ BuiltinCommandsModule::Registration< DemoCommand > reg; }
bool DemoCommand::DefineParams( ShuttleParams & S ){
S.Define( delay, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f );
S.Define( decay, wxT("Decay"), 0.5f, 0.0f, FLT_MAX, 1.0f );

View File

@ -19,6 +19,7 @@
#include "../Audacity.h"
#include "DragCommand.h"
#include "LoadCommands.h"
#include "../Project.h"
#include "../WaveTrack.h"
#include "../Shuttle.h"
@ -30,6 +31,8 @@
const ComponentInterfaceSymbol DragCommand::Symbol
{ XO("Drag") };
namespace{ BuiltinCommandsModule::Registration< DragCommand > reg; }
DragCommand::DragCommand()
{
}

View File

@ -23,6 +23,7 @@ This class now lists
#include "../Audacity.h" // for USE_* macros
#include "GetInfoCommand.h"
#include "LoadCommands.h"
#include "../Project.h"
#include "CommandManager.h"
#include "CommandTargets.h"
@ -53,6 +54,7 @@ This class now lists
const ComponentInterfaceSymbol GetInfoCommand::Symbol
{ XO("Get Info") };
namespace{ BuiltinCommandsModule::Registration< GetInfoCommand > reg; }
enum {
kCommands,
//kCommandsPlus,

View File

@ -19,6 +19,7 @@
#include "../Audacity.h"
#include "GetTrackInfoCommand.h"
#include "LoadCommands.h"
#include "../NoteTrack.h"
#include "../WaveTrack.h"
#include "../Shuttle.h"
@ -28,6 +29,9 @@
const ComponentInterfaceSymbol GetTrackInfoCommand::Symbol
{ XO("Get Track Info") };
// GET_TRACK_INFO subsumed by GET_INFO
// namespace{ BuiltinCommandsModule::Registration< GetTrackInfoCommand > reg; }
const int nTypes =3;
static const EnumValueSymbol kTypes[nTypes] =
{

View File

@ -18,6 +18,7 @@
#include "HelpCommand.h"
#include "../Shuttle.h"
#include "LoadCommands.h"
#include "../ShuttleGui.h"
#include "CommandContext.h"
#include "../effects/EffectManager.h"
@ -25,6 +26,8 @@
const ComponentInterfaceSymbol HelpCommand::Symbol
{ XO("Help") };
namespace{ BuiltinCommandsModule::Registration< HelpCommand > reg; }
bool HelpCommand::DefineParams( ShuttleParams & S ){
S.Define( mCommandName, wxT("Command"), "Help" );
return true;

View File

@ -17,6 +17,7 @@
#include "../Audacity.h"
#include "ImportExportCommands.h"
#include "LoadCommands.h"
#include "../ProjectFileManager.h"
#include "../ViewInfo.h"
#include "../export/Export.h"
@ -27,6 +28,8 @@
const ComponentInterfaceSymbol ImportCommand::Symbol
{ XO("Import2") };
namespace{ BuiltinCommandsModule::Registration< ImportCommand > reg; }
bool ImportCommand::DefineParams( ShuttleParams & S ){
S.Define( mFileName, wxT("Filename"), "" );
return true;
@ -58,6 +61,8 @@ bool ExportCommand::DefineParams( ShuttleParams & S ){
const ComponentInterfaceSymbol ExportCommand::Symbol
{ XO("Export2") };
namespace{ BuiltinCommandsModule::Registration< ExportCommand > reg2; }
void ExportCommand::PopulateOrExchange(ShuttleGui & S)
{
S.AddSpace(0, 5);

View File

@ -35,6 +35,24 @@ modelled on BuiltinEffectsModule
#include "../commands/SetProjectCommand.h"
#include "../commands/DragCommand.h"
struct BuiltinCommandsModule::Entry {
wxString name;
Factory factory;
using Entries = std::vector< Entry >;
static Entries &Registry()
{
static Entries result;
return result;
}
};
void BuiltinCommandsModule::DoRegistration(
const ComponentInterfaceSymbol &name, const Factory &factory )
{
Entry::Registry().emplace_back( Entry{ name.Internal(), factory } );
}
//
// Define the list of COMMANDs that will be autoregistered and how to instantiate each
//

View File

@ -11,6 +11,8 @@
#include "audacity/ModuleInterface.h"
#include <functional>
#include <memory>
#include "../MemoryX.h"
class AudacityCommand;
@ -27,6 +29,16 @@ public:
BuiltinCommandsModule(ModuleManagerInterface *moduleManager, const wxString *path);
virtual ~BuiltinCommandsModule();
using Factory = std::function< std::unique_ptr<AudacityCommand> () >;
// Typically you make a static object of this type in the .cpp file that
// also implements the Command subclass.
template< typename Subclass >
struct Registration final { Registration() {
DoRegistration(
Subclass::Symbol, []{ return std::make_unique< Subclass >(); } );
} };
// ComponentInterface implementation
PluginPath GetPath() override;
@ -62,6 +74,11 @@ private:
std::unique_ptr<AudacityCommand> Instantiate(const PluginPath & path);
private:
struct Entry;
static void DoRegistration(
const ComponentInterfaceSymbol &name, const Factory &factory );
ModuleManagerInterface *mModMan;
wxString mPath;

View File

@ -16,6 +16,7 @@
#include "../Audacity.h"
#include "MessageCommand.h"
#include "LoadCommands.h"
#include "CommandContext.h"
#include "../Shuttle.h"
#include "../ShuttleGui.h"
@ -23,6 +24,8 @@
const ComponentInterfaceSymbol MessageCommand::Symbol
{ XO("Message") };
namespace{ BuiltinCommandsModule::Registration< MessageCommand > reg; }
bool MessageCommand::DefineParams( ShuttleParams & S ){
S.Define( mMessage, wxT("Text"), "Some message" );
return true;

View File

@ -17,6 +17,7 @@
#include "../Audacity.h"
#include "OpenSaveCommands.h"
#include "LoadCommands.h"
#include "../Project.h"
#include "../ProjectFileManager.h"
#include "../ProjectManager.h"
@ -29,6 +30,8 @@
const ComponentInterfaceSymbol OpenProjectCommand::Symbol
{ XO("Open Project2") };
namespace{ BuiltinCommandsModule::Registration< OpenProjectCommand > reg; }
bool OpenProjectCommand::DefineParams( ShuttleParams & S ){
S.Define( mFileName, wxT("Filename"), "test.aup" );
S.OptionalN(bHasAddToHistory).Define( mbAddToHistory, wxT("AddToHistory"), false );
@ -71,6 +74,8 @@ bool OpenProjectCommand::Apply(const CommandContext & context){
const ComponentInterfaceSymbol SaveProjectCommand::Symbol
{ XO("Save Project2") };
namespace{ BuiltinCommandsModule::Registration< SaveProjectCommand > reg2; }
bool SaveProjectCommand::DefineParams( ShuttleParams & S ){
S.Define( mFileName, wxT("Filename"), "name.aup" );
S.Define( mbAddToHistory, wxT("AddToHistory"), false );

View File

@ -18,6 +18,7 @@ SetPreferenceCommand classes
#include "../Audacity.h"
#include "PreferenceCommands.h"
#include "LoadCommands.h"
#include "../Prefs.h"
#include "../Shuttle.h"
#include "../ShuttleGui.h"
@ -27,6 +28,8 @@ SetPreferenceCommand classes
const ComponentInterfaceSymbol GetPreferenceCommand::Symbol
{ XO("Get Preference") };
namespace{ BuiltinCommandsModule::Registration< GetPreferenceCommand > reg; }
bool GetPreferenceCommand::DefineParams( ShuttleParams & S ){
S.Define( mName, wxT("Name"), wxT("") );
return true;
@ -57,6 +60,8 @@ bool GetPreferenceCommand::Apply(const CommandContext & context)
const ComponentInterfaceSymbol SetPreferenceCommand::Symbol
{ XO("Set Preference") };
namespace{ BuiltinCommandsModule::Registration< SetPreferenceCommand > reg2; }
bool SetPreferenceCommand::DefineParams( ShuttleParams & S ){
S.Define( mName, wxT("Name"), wxT("") );
S.Define( mValue, wxT("Value"), wxT("") );

View File

@ -22,6 +22,7 @@ small calculations of rectangles.
#include <mutex>
#include "LoadCommands.h"
#include "../Project.h"
#include <wx/toplevel.h>
#include <wx/dcscreen.h>
@ -47,6 +48,8 @@ small calculations of rectangles.
const ComponentInterfaceSymbol ScreenshotCommand::Symbol
{ XO("Screenshot") };
namespace{ BuiltinCommandsModule::Registration< ScreenshotCommand > reg; }
static const EnumValueSymbol
kCaptureWhatStrings[ ScreenshotCommand::nCaptureWhats ] =

View File

@ -35,6 +35,7 @@ explicitly code all three.
#include <wx/string.h>
#include <float.h>
#include "LoadCommands.h"
#include "../ProjectSelectionManager.h"
#include "../TrackPanel.h"
#include "../Shuttle.h"
@ -47,6 +48,8 @@ explicitly code all three.
const ComponentInterfaceSymbol SelectTimeCommand::Symbol
{ XO("Select Time") };
namespace{ BuiltinCommandsModule::Registration< SelectTimeCommand > reg; }
// Relative to project and relative to selection cover MOST options, since you can already
// set a selection to a clip.
const int nRelativeTos =6;
@ -142,6 +145,8 @@ bool SelectTimeCommand::Apply(const CommandContext & context){
const ComponentInterfaceSymbol SelectFrequenciesCommand::Symbol
{ XO("Select Frequencies") };
namespace{ BuiltinCommandsModule::Registration< SelectFrequenciesCommand > reg2; }
bool SelectFrequenciesCommand::DefineParams( ShuttleParams & S ){
S.OptionalN( bHasTop ).Define( mTop, wxT("High"), 0.0, 0.0, (double)FLT_MAX);
S.OptionalN( bHasBottom ).Define( mBottom, wxT("Low"), 0.0, 0.0, (double)FLT_MAX);
@ -179,6 +184,8 @@ bool SelectFrequenciesCommand::Apply(const CommandContext & context){
const ComponentInterfaceSymbol SelectTracksCommand::Symbol
{ XO("Select Tracks") };
namespace{ BuiltinCommandsModule::Registration< SelectTracksCommand > reg3; }
const int nModes =3;
static const EnumValueSymbol kModes[nModes] =
{
@ -262,3 +269,5 @@ bool SelectTracksCommand::Apply(const CommandContext &context)
const ComponentInterfaceSymbol SelectCommand::Symbol
{ XO("Select") };
namespace{ BuiltinCommandsModule::Registration< SelectCommand > reg4; }

View File

@ -19,6 +19,7 @@
#include "../Audacity.h"
#include "SetClipCommand.h"
#include "LoadCommands.h"
#include "../WaveClip.h"
#include "../WaveTrack.h"
#include "../Shuttle.h"
@ -27,6 +28,8 @@
const ComponentInterfaceSymbol SetClipCommand::Symbol
{ XO("Set Clip") };
namespace{ BuiltinCommandsModule::Registration< SetClipCommand > reg; }
SetClipCommand::SetClipCommand()
{
}

View File

@ -19,6 +19,7 @@
#include "../Audacity.h"
#include "SetEnvelopeCommand.h"
#include "LoadCommands.h"
#include "../WaveClip.h"
#include "../WaveTrack.h"
#include "../Envelope.h"
@ -28,6 +29,9 @@
const ComponentInterfaceSymbol SetEnvelopeCommand::Symbol
{ XO("Set Envelope") };
namespace{ BuiltinCommandsModule::Registration< SetEnvelopeCommand > reg; }
SetEnvelopeCommand::SetEnvelopeCommand()
{
}

View File

@ -19,6 +19,7 @@
#include "../Audacity.h"
#include "SetLabelCommand.h"
#include "LoadCommands.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
#include "../LabelTrack.h"
@ -30,6 +31,8 @@
const ComponentInterfaceSymbol SetLabelCommand::Symbol
{ XO("Set Label") };
namespace{ BuiltinCommandsModule::Registration< SetLabelCommand > reg; }
SetLabelCommand::SetLabelCommand()
{
}

View File

@ -20,6 +20,7 @@
#include "../Audacity.h"
#include "SetProjectCommand.h"
#include "LoadCommands.h"
#include "../Project.h"
#include "../WaveTrack.h"
#include "../Shuttle.h"
@ -32,6 +33,8 @@
const ComponentInterfaceSymbol SetProjectCommand::Symbol
{ XO("Set Project") };
namespace{ BuiltinCommandsModule::Registration< SetProjectCommand > reg; }
SetProjectCommand::SetProjectCommand()
{
}

View File

@ -36,6 +36,7 @@ SetTrackAudioCommand and SetTrackVisualsCommand.
#include "../Audacity.h"
#include "SetTrackInfoCommand.h"
#include "LoadCommands.h"
#include "../Project.h"
#include "../TrackPanelAx.h"
#include "../TrackPanel.h"
@ -124,6 +125,8 @@ bool SetTrackBase::Apply(const CommandContext & context )
const ComponentInterfaceSymbol SetTrackStatusCommand::Symbol
{ XO("Set Track Status") };
namespace{ BuiltinCommandsModule::Registration< SetTrackStatusCommand > reg; }
bool SetTrackStatusCommand::DefineParams( ShuttleParams & S ){
SetTrackBase::DefineParams( S );
S.OptionalN( bHasTrackName ).Define( mTrackName, wxT("Name"), _("Unnamed") );
@ -184,6 +187,8 @@ bool SetTrackStatusCommand::ApplyInner(const CommandContext & context, Track * t
const ComponentInterfaceSymbol SetTrackAudioCommand::Symbol
{ XO("Set Track Audio") };
namespace{ BuiltinCommandsModule::Registration< SetTrackAudioCommand > reg2; }
bool SetTrackAudioCommand::DefineParams( ShuttleParams & S ){
SetTrackBase::DefineParams( S );
S.OptionalN( bHasMute ).Define( bMute, wxT("Mute"), false );
@ -239,6 +244,8 @@ bool SetTrackAudioCommand::ApplyInner(const CommandContext & context, Track * t
const ComponentInterfaceSymbol SetTrackVisualsCommand::Symbol
{ XO("Set Track Visuals") };
namespace{ BuiltinCommandsModule::Registration< SetTrackVisualsCommand > reg3; }
enum kColours
{
kColour0,
@ -430,6 +437,8 @@ bool SetTrackVisualsCommand::ApplyInner(const CommandContext & context, Track *
const ComponentInterfaceSymbol SetTrackCommand::Symbol
{ XO("Set Track") };
namespace{ BuiltinCommandsModule::Registration< SetTrackCommand > reg4; }
SetTrackCommand::SetTrackCommand()
{
mSetStatus.mbPromptForTracks = false;