mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-22 14:32:58 +02:00
More commands documented in wiki implemented.
- Added new facility whereby parameters can be optional, and can be tested for their presence. - Can now set Pan, Gain, Selected, Solo, Mute, Focused using SetTrackInfo, mirroring what GetTrackInfo can do.
This commit is contained in:
@@ -95,6 +95,7 @@ CommandImplementation::CommandImplementation(CommandType &type,
|
||||
std::unique_ptr<CommandOutputTarget> &&output)
|
||||
: mType(type),
|
||||
mParams(type.GetSignature().GetDefaults()),
|
||||
mSetParams(),
|
||||
mOutput(std::move(output))
|
||||
{
|
||||
wxASSERT(mOutput);
|
||||
@@ -128,6 +129,14 @@ void CommandImplementation::CheckParam(const wxString ¶mName)
|
||||
+ wxT("' parameter, but that parameter doesn't exist in the command signature!"));
|
||||
}
|
||||
|
||||
bool CommandImplementation::HasParam( const wxString ¶mName)
|
||||
{
|
||||
// Test for not even in map...
|
||||
if( mParams.count(paramName) < 1)
|
||||
return false;
|
||||
return mSetParams[paramName];
|
||||
}
|
||||
|
||||
bool CommandImplementation::GetBool(const wxString ¶mName)
|
||||
{
|
||||
CheckParam(paramName);
|
||||
@@ -208,6 +217,7 @@ bool CommandImplementation::SetParameter(const wxString ¶mName, const wxVari
|
||||
return false;
|
||||
}
|
||||
mParams[paramName] = validator.GetConverted();
|
||||
mSetParams[ paramName ] = true;
|
||||
|
||||
// (debug)
|
||||
// Status(wxT("Set parameter ") + paramName + wxT(" to type ") + mParams[paramName].GetType() + wxT(", value ") + mParams[paramName].MakeString());
|
||||
|
@@ -120,6 +120,7 @@ class CommandImplementation /* not final */ : public Command
|
||||
private:
|
||||
CommandType &mType;
|
||||
ParamValueMap mParams;
|
||||
ParamBoolMap mSetParams;
|
||||
|
||||
/// Using the command signature, looks up a possible parameter value and
|
||||
/// checks whether it passes the validator.
|
||||
@@ -133,6 +134,7 @@ protected:
|
||||
const wxString ¶mName,
|
||||
const wxVariant ¶m);
|
||||
void CheckParam(const wxString ¶mName);
|
||||
bool HasParam( const wxString ¶mName);
|
||||
bool GetBool(const wxString ¶mName);
|
||||
long GetLong(const wxString ¶mName);
|
||||
double GetDouble(const wxString ¶mName);
|
||||
|
@@ -25,6 +25,7 @@ class CommandType;
|
||||
// Map from parameter name to the value of the parameter
|
||||
// to do: use hash
|
||||
typedef std::map<wxString, wxVariant> ParamValueMap;
|
||||
typedef std::map<wxString, bool> ParamBoolMap;
|
||||
|
||||
// Map from parameter name to a suitable Validator
|
||||
// to do: use hash
|
||||
|
@@ -35,7 +35,7 @@ void SetProjectInfoCommandType::BuildSignature(CommandSignature &signature)
|
||||
infoTypeValidator->AddOption(wxT("MuteTracks"));
|
||||
infoTypeValidator->AddOption(wxT("SoloTracks"));
|
||||
|
||||
signature.AddParameter(wxT("Type"), wxT("Name"), std::move(infoTypeValidator));
|
||||
signature.AddParameter(wxT("Type"), wxT("SelectedTracks"), std::move(infoTypeValidator));
|
||||
|
||||
auto TracksSetValidator = make_movable<BoolArrayValidator>();
|
||||
signature.AddParameter(wxT(kSetOfTracksStr), wxT("x"), std::move(TracksSetValidator));
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#include "SetTrackInfoCommand.h"
|
||||
#include "../Project.h"
|
||||
#include "../Track.h"
|
||||
#include "../TrackPanel.h"
|
||||
#include "../WaveTrack.h"
|
||||
|
||||
wxString SetTrackInfoCommandType::BuildName()
|
||||
{
|
||||
@@ -29,12 +31,20 @@ void SetTrackInfoCommandType::BuildSignature(CommandSignature &signature)
|
||||
{
|
||||
auto trackIndexValidator = make_movable<IntValidator>();
|
||||
signature.AddParameter(wxT("TrackIndex"), 0, std::move(trackIndexValidator));
|
||||
|
||||
auto infoTypeValidator = make_movable<OptionValidator>();
|
||||
infoTypeValidator->AddOption(wxT("Name"));
|
||||
signature.AddParameter(wxT("Type"), wxT("Name"), std::move(infoTypeValidator));
|
||||
auto nameValidator = make_movable<DefaultValidator>();
|
||||
signature.AddParameter(wxT("Name"), wxT("Unnamed"), std::move(nameValidator));
|
||||
auto panValidator = make_movable<DoubleValidator>();
|
||||
signature.AddParameter(wxT("Pan"), wxT("1.0"), std::move(panValidator));
|
||||
auto gainValidator = make_movable<DoubleValidator>();
|
||||
signature.AddParameter(wxT("Gain"), wxT("1.0"), std::move(gainValidator));
|
||||
auto selectedValidator = make_movable<BoolValidator>();
|
||||
signature.AddParameter(wxT("Selected"), wxT("True"), std::move(selectedValidator));
|
||||
auto focusedValidator = make_movable<BoolValidator>();
|
||||
signature.AddParameter(wxT("Focused"), wxT("True"), std::move(focusedValidator));
|
||||
auto soloValidator = make_movable<BoolValidator>();
|
||||
signature.AddParameter(wxT("Solo"), wxT("True"), std::move(soloValidator));
|
||||
auto muteValidator = make_movable<BoolValidator>();
|
||||
signature.AddParameter(wxT("Mute"), wxT("True"), std::move(muteValidator));
|
||||
}
|
||||
|
||||
CommandHolder SetTrackInfoCommandType::Create(std::unique_ptr<CommandOutputTarget> &&target)
|
||||
@@ -44,9 +54,11 @@ CommandHolder SetTrackInfoCommandType::Create(std::unique_ptr<CommandOutputTarge
|
||||
|
||||
bool SetTrackInfoCommand::Apply(CommandExecutionContext context)
|
||||
{
|
||||
wxString mode = GetString(wxT("Type"));
|
||||
//wxString mode = GetString(wxT("Type"));
|
||||
|
||||
long trackIndex = GetLong(wxT("TrackIndex"));
|
||||
long trackIndex = 0;
|
||||
if( HasParam("TrackIndex") )
|
||||
trackIndex = GetLong(wxT("TrackIndex"));
|
||||
|
||||
// (Note: track selection ought to be somewhere else)
|
||||
long i = 0;
|
||||
@@ -63,15 +75,26 @@ bool SetTrackInfoCommand::Apply(CommandExecutionContext context)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode.IsSameAs(wxT("Name")))
|
||||
auto wt = dynamic_cast<WaveTrack *>(t);
|
||||
auto pt = dynamic_cast<PlayableTrack *>(t);
|
||||
|
||||
if( HasParam( "Name" ) )
|
||||
t->SetName(GetString(wxT("Name")));
|
||||
if( wt && HasParam( "Pan" ) )
|
||||
wt->SetPan(GetDouble(wxT("Pan")));
|
||||
if( wt && HasParam( "Gain" ) )
|
||||
wt->SetGain(GetDouble(wxT("Gain")));
|
||||
if( HasParam( "Selected" ) )
|
||||
t->SetSelected(GetBool(wxT("Selected")));
|
||||
if(HasParam("Focused"))
|
||||
{
|
||||
wxString name = GetString(wxT("Name"));
|
||||
t->SetName(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(wxT("Invalid info type!"));
|
||||
return false;
|
||||
TrackPanel *panel = context.GetProject()->GetTrackPanel();
|
||||
panel->SetFocusedTrack( t );
|
||||
}
|
||||
if( pt && HasParam( "Solo" ) )
|
||||
pt->SetSolo(GetBool(wxT("Solo")));
|
||||
if( pt && HasParam( "Mute" ) )
|
||||
pt->SetMute(GetBool(wxT("Mute")));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user