From af13e859227bdb618ba3e862f07b6b03b60a8146 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 13 Jan 2018 20:30:52 +0000 Subject: [PATCH] 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. --- src/commands/Command.cpp | 10 +++++ src/commands/Command.h | 2 + src/commands/CommandMisc.h | 1 + src/commands/SetProjectInfoCommand.cpp | 2 +- src/commands/SetTrackInfoCommand.cpp | 51 +++++++++++++++++++------- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 1b08caa50..c342197a4 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -95,6 +95,7 @@ CommandImplementation::CommandImplementation(CommandType &type, std::unique_ptr &&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()); diff --git a/src/commands/Command.h b/src/commands/Command.h index 8711aabe9..711c0c995 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -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); diff --git a/src/commands/CommandMisc.h b/src/commands/CommandMisc.h index b48c16502..de438301d 100644 --- a/src/commands/CommandMisc.h +++ b/src/commands/CommandMisc.h @@ -25,6 +25,7 @@ class CommandType; // Map from parameter name to the value of the parameter // to do: use hash typedef std::map ParamValueMap; +typedef std::map ParamBoolMap; // Map from parameter name to a suitable Validator // to do: use hash diff --git a/src/commands/SetProjectInfoCommand.cpp b/src/commands/SetProjectInfoCommand.cpp index d15180cfd..e2183b35a 100644 --- a/src/commands/SetProjectInfoCommand.cpp +++ b/src/commands/SetProjectInfoCommand.cpp @@ -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(); signature.AddParameter(wxT(kSetOfTracksStr), wxT("x"), std::move(TracksSetValidator)); diff --git a/src/commands/SetTrackInfoCommand.cpp b/src/commands/SetTrackInfoCommand.cpp index 3b70dfd81..74a5ae6f5 100644 --- a/src/commands/SetTrackInfoCommand.cpp +++ b/src/commands/SetTrackInfoCommand.cpp @@ -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(); signature.AddParameter(wxT("TrackIndex"), 0, std::move(trackIndexValidator)); - - auto infoTypeValidator = make_movable(); - infoTypeValidator->AddOption(wxT("Name")); - signature.AddParameter(wxT("Type"), wxT("Name"), std::move(infoTypeValidator)); auto nameValidator = make_movable(); signature.AddParameter(wxT("Name"), wxT("Unnamed"), std::move(nameValidator)); + auto panValidator = make_movable(); + signature.AddParameter(wxT("Pan"), wxT("1.0"), std::move(panValidator)); + auto gainValidator = make_movable(); + signature.AddParameter(wxT("Gain"), wxT("1.0"), std::move(gainValidator)); + auto selectedValidator = make_movable(); + signature.AddParameter(wxT("Selected"), wxT("True"), std::move(selectedValidator)); + auto focusedValidator = make_movable(); + signature.AddParameter(wxT("Focused"), wxT("True"), std::move(focusedValidator)); + auto soloValidator = make_movable(); + signature.AddParameter(wxT("Solo"), wxT("True"), std::move(soloValidator)); + auto muteValidator = make_movable(); + signature.AddParameter(wxT("Mute"), wxT("True"), std::move(muteValidator)); } CommandHolder SetTrackInfoCommandType::Create(std::unique_ptr &&target) @@ -44,9 +54,11 @@ CommandHolder SetTrackInfoCommandType::Create(std::unique_ptr(t); + auto pt = dynamic_cast(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; }