1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Optional parameters now working.

This commit is contained in:
James Crook 2018-02-09 12:58:43 +00:00 committed by Paul Licameli
parent c02a29e261
commit 2180379a18
5 changed files with 125 additions and 12 deletions

View File

@ -336,6 +336,22 @@ bool ShuttleParams::ExchangeWithMaster(const wxString & WXUNUSED(Name))
#pragma warning( push )
#pragma warning( disable: 4100 ) // unused parameters.
// The ShouldSet and CouldGet functions have an important side effect
// on the pOptionalFlag. They 'use it up' and clear it down for the next parameter.
// Tests for parameter being optional.
// Prepares for next parameter by clearing the pointer.
// Reports on whether the parameter should be set, i.e. should set
// if it was chosen to be set, or was not optional.
bool ShuttleParams::ShouldSet(){
if( !pOptionalFlag )
return true;
bool result = *pOptionalFlag;
pOptionalFlag = NULL;
return result;
}
// These are functions to override. They do nothing.
void ShuttleParams::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl){;};
void ShuttleParams::Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ){;};
@ -355,56 +371,92 @@ void ShuttleParams::DefineEnum( int &var, const wxChar * key, const int vdefault
}
*/
// ShuttleGetAutomation gets from the shuttle into typically a string.
ShuttleParams & ShuttleGetAutomation::Optional( bool & var ){
pOptionalFlag = &var;
return *this;
};
void ShuttleGetAutomation::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{
if( !ShouldSet() ) return;
mpEap->WriteFloat(key, var);
}
void ShuttleGetAutomation::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{
if( !ShouldSet() ) return;
mpEap->WriteFloat(key, var);
}
void ShuttleGetAutomation::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::DefineEnum( wxString &var, const wxChar * key, const wxString vdefault, wxArrayString strings )
{
if( !ShouldSet() ) return;
mpEap->Write(key, var);
}
void ShuttleGetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, wxArrayString strings )
{
if( !ShouldSet() ) return;
mpEap->Write(key, strings[var]);
}
ShuttleParams & ShuttleSetAutomation::Optional( bool & var ){
pOptionalFlag = &var;
return *this;
};
// Tests for parameter being optional.
// Prepares for next parameter by clearing the pointer.
// If the parameter is optional, finds out if it was actually provided.
// i.e. could it be got from automation?
// The result goes into the flag variable, so we typically ignore the result.
bool ShuttleSetAutomation::CouldGet( const wxString &key ){
// Not optional? Can get as we will get the default, at worst.
if( !pOptionalFlag )
return true;
bool result = mpEap->HasEntry( key );
*pOptionalFlag = result;
pOptionalFlag = NULL;
return result;
}
void ShuttleSetAutomation::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl )
{
CouldGet( key );
if( !bOK )
return;
// Use of temp in this and related functions is to handle the case of
@ -417,6 +469,7 @@ void ShuttleSetAutomation::Define( bool & var, const wxChar * key, const boo
void ShuttleSetAutomation::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
{
CouldGet( key );
if( !bOK )
return;
int temp =var;
@ -427,6 +480,7 @@ void ShuttleSetAutomation::Define( int & var, const wxChar * key, const int
void ShuttleSetAutomation::Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
{
CouldGet( key );
if( !bOK )
return;
int temp = var;
@ -437,6 +491,7 @@ void ShuttleSetAutomation::Define( size_t & var, const wxChar * key, const
void ShuttleSetAutomation::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{
CouldGet( key );
if( !bOK )
return;
float temp = var;
@ -448,6 +503,7 @@ void ShuttleSetAutomation::Define( float & var, const wxChar * key, const floa
void ShuttleSetAutomation::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{
CouldGet( key );
if( !bOK )
return;
double temp = var;
@ -458,6 +514,7 @@ void ShuttleSetAutomation::Define( double & var, const wxChar * key, const flo
void ShuttleSetAutomation::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl )
{
CouldGet( key );
if( !bOK )
return;
double temp = var;
@ -469,6 +526,7 @@ void ShuttleSetAutomation::Define( double & var, const wxChar * key, const dou
void ShuttleSetAutomation::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl )
{
CouldGet( key );
if( !bOK )
return;
wxString temp = var;
@ -480,6 +538,7 @@ void ShuttleSetAutomation::Define( wxString &var, const wxChar * key, const wxSt
void ShuttleSetAutomation::DefineEnum( wxString &var, const wxChar * key, const wxString vdefault, wxArrayString strings )
{
CouldGet( key );
if( !bOK )
return;
int temp =0;
@ -490,6 +549,7 @@ void ShuttleSetAutomation::DefineEnum( wxString &var, const wxChar * key, const
void ShuttleSetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, wxArrayString strings )
{
CouldGet( key );
if( !bOK )
return;
int temp = var;
@ -498,6 +558,12 @@ void ShuttleSetAutomation::DefineEnum( int &var, const wxChar * key, const int v
var = temp;
}
bool ShuttleGetDefinition::IsOptional(){
bool result = pOptionalFlag ? true : false;
pOptionalFlag = NULL;
return result;
}
ShuttleGetDefinition::ShuttleGetDefinition( CommandMessageTarget & target ) : CommandMessageTargetDecorator( target )
{
}
@ -508,7 +574,10 @@ void ShuttleGetDefinition::Define( bool & var, const wxChar * key, const boo
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "bool", "type" );
AddItem( vdefault ? "True" : "False", "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault ? "True" : "False", "default" );
EndStruct();
}
@ -517,7 +586,10 @@ void ShuttleGetDefinition::Define( int & var, const wxChar * key, const int
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "int", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct();
}
@ -526,7 +598,10 @@ void ShuttleGetDefinition::Define( size_t & var, const wxChar * key, const
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "size_t", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct();
}
@ -536,7 +611,10 @@ void ShuttleGetDefinition::Define( float & var, const wxChar * key, const floa
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "float", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct();
}
@ -545,7 +623,10 @@ void ShuttleGetDefinition::Define( double & var, const wxChar * key, const flo
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "float", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct();
}
@ -554,7 +635,10 @@ void ShuttleGetDefinition::Define( double & var, const wxChar * key, const dou
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "double", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct();
}
@ -564,7 +648,10 @@ void ShuttleGetDefinition::Define( wxString &var, const wxChar * key, const wxSt
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "string", "type" );
AddItem( vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault, "default" );
EndStruct();
}
@ -574,7 +661,10 @@ void ShuttleGetDefinition::DefineEnum( wxString &var, const wxChar * key, const
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "enum", "type" );
AddItem( vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault, "default" );
AddField( "enum" );
StartArray();
for( size_t i=0;i<strings.Count(); i++ )
@ -588,7 +678,10 @@ void ShuttleGetDefinition::DefineEnum( int&var, const wxChar * key, const int vd
StartStruct();
AddItem( wxString(key), "key" );
AddItem( "enum", "type" );
AddItem( (double)vdefault, "default" );
if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
AddField( "enum" );
StartArray();
for( size_t i=0;i<strings.Count(); i++ )

View File

@ -67,11 +67,13 @@ class ShuttleParams : public Shuttle
{
public:
wxString mParams;
bool *pOptionalFlag;
CommandAutomationParameters * mpEap;
ShuttleParams(){ mParams = wxT("") ;mpEap=NULL;}
ShuttleParams(){ mParams = wxT("") ;mpEap=NULL;pOptionalFlag=NULL;}
virtual ~ShuttleParams() {}
bool ExchangeWithMaster(const wxString & Name) override;
ShuttleParams & Optional( bool & var ){ var = true;return *this;};
bool ShouldSet();
virtual ShuttleParams & Optional( bool & var ){ pOptionalFlag = NULL;return *this;};
virtual void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false );
virtual void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
virtual void Define( int & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
@ -89,6 +91,7 @@ public:
class ShuttleGetAutomation : public ShuttleParams
{
public:
ShuttleParams & Optional( bool & var ) override;
void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
@ -109,6 +112,8 @@ public:
ShuttleSetAutomation(){ bWrite = false; bOK = false;};
bool bOK;
bool bWrite;
ShuttleParams & Optional( bool & var ) override;
bool CouldGet(const wxString &key);
void SetForValidating( CommandAutomationParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
void SetForWriting(CommandAutomationParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;};
void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
@ -130,6 +135,7 @@ class ShuttleGetDefinition : public ShuttleParams, public CommandMessageTargetDe
public:
ShuttleGetDefinition( CommandMessageTarget & target );
wxString Result;
bool IsOptional();
void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;

View File

@ -2044,6 +2044,12 @@ ShuttleGui & ShuttleGui::Id(int id )
return *this;
}
ShuttleGui & ShuttleGui::Optional( bool &bVar ){
TieCheckBox( "Set", bVar );
return *this;
};
GuiWaveTrack * ShuttleGui::AddGuiWaveTrack( const wxString & WXUNUSED(Name))
{
#ifdef EXPERIMENTAL_TRACK_PANEL

View File

@ -369,7 +369,7 @@ public:
ShuttleGui(wxWindow * pParent,teShuttleMode ShuttleMode);
~ShuttleGui(void);
public:
ShuttleGui & Optional( bool & var ){ var = true;return *this;};
ShuttleGui & Optional( bool & bVar );
ShuttleGui & Id(int id );
// Prop() sets the proportion value, defined as in wxSizer::Add().
ShuttleGui & Prop( int iProp ){ ShuttleGuiBase::Prop(iProp); return *this;}; // Has to be here too, to return a ShuttleGui and not a ShuttleGuiBase.

View File

@ -57,9 +57,17 @@ void SetTrackInfoCommand::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2, wxALIGN_CENTER);
{
S.TieNumericTextBox( _("Track Index"), mTrackIndex );
}
S.EndMultiColumn();
S.StartMultiColumn(3, wxALIGN_CENTER);
{
S.Optional( bHasTrackName ).TieTextBox( _("Name"), mTrackName );
S.Optional( bHasPan ).TieSlider( _("Pan"), mPan, 1.0, -1.0);
S.Optional( bHasGain ).TieSlider( _("Gain"), mGain, 10.0, 0.0);
}
S.EndMultiColumn();
S.StartMultiColumn(2, wxALIGN_CENTER);
{
S.Optional( bHasSelected ).TieCheckBox( _("Selected"), bSelected );
S.Optional( bHasFocused ).TieCheckBox( _("Focused"), bFocused);
S.Optional( bHasSolo ).TieCheckBox( _("Solo"), bSolo);