1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +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( push )
#pragma warning( disable: 4100 ) // unused parameters. #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. // 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( 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 ){;}; 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 ) 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); mpEap->Write(key, var);
} }
void ShuttleGetAutomation::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) 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); 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 ) 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); mpEap->Write(key, var);
} }
void ShuttleGetAutomation::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) 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); mpEap->WriteFloat(key, var);
} }
void ShuttleGetAutomation::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) 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); mpEap->WriteFloat(key, var);
} }
void ShuttleGetAutomation::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) 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); mpEap->Write(key, var);
} }
void ShuttleGetAutomation::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) 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); mpEap->Write(key, var);
} }
void ShuttleGetAutomation::DefineEnum( wxString &var, const wxChar * key, const wxString vdefault, wxArrayString strings ) void ShuttleGetAutomation::DefineEnum( wxString &var, const wxChar * key, const wxString vdefault, wxArrayString strings )
{ {
if( !ShouldSet() ) return;
mpEap->Write(key, var); mpEap->Write(key, var);
} }
void ShuttleGetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, wxArrayString strings ) void ShuttleGetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, wxArrayString strings )
{ {
if( !ShouldSet() ) return;
mpEap->Write(key, strings[var]); 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 ) void ShuttleSetAutomation::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
// Use of temp in this and related functions is to handle the case of // 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 ) void ShuttleSetAutomation::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
int temp =var; 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 ) 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 ) if( !bOK )
return; return;
int temp = var; 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 ) void ShuttleSetAutomation::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
float temp = var; 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 ) void ShuttleSetAutomation::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
double temp = var; 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 ) void ShuttleSetAutomation::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
double temp = var; 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 ) void ShuttleSetAutomation::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
wxString temp = var; 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 ) void ShuttleSetAutomation::DefineEnum( wxString &var, const wxChar * key, const wxString vdefault, wxArrayString strings )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
int temp =0; 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 ) void ShuttleSetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, wxArrayString strings )
{ {
CouldGet( key );
if( !bOK ) if( !bOK )
return; return;
int temp = var; int temp = var;
@ -498,6 +558,12 @@ void ShuttleSetAutomation::DefineEnum( int &var, const wxChar * key, const int v
var = temp; var = temp;
} }
bool ShuttleGetDefinition::IsOptional(){
bool result = pOptionalFlag ? true : false;
pOptionalFlag = NULL;
return result;
}
ShuttleGetDefinition::ShuttleGetDefinition( CommandMessageTarget & target ) : CommandMessageTargetDecorator( target ) ShuttleGetDefinition::ShuttleGetDefinition( CommandMessageTarget & target ) : CommandMessageTargetDecorator( target )
{ {
} }
@ -508,7 +574,10 @@ void ShuttleGetDefinition::Define( bool & var, const wxChar * key, const boo
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "bool", "type" ); AddItem( "bool", "type" );
AddItem( vdefault ? "True" : "False", "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault ? "True" : "False", "default" );
EndStruct(); EndStruct();
} }
@ -517,7 +586,10 @@ void ShuttleGetDefinition::Define( int & var, const wxChar * key, const int
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "int", "type" ); AddItem( "int", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -526,7 +598,10 @@ void ShuttleGetDefinition::Define( size_t & var, const wxChar * key, const
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "size_t", "type" ); AddItem( "size_t", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -536,7 +611,10 @@ void ShuttleGetDefinition::Define( float & var, const wxChar * key, const floa
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "float", "type" ); AddItem( "float", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -545,7 +623,10 @@ void ShuttleGetDefinition::Define( double & var, const wxChar * key, const flo
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "float", "type" ); AddItem( "float", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -554,7 +635,10 @@ void ShuttleGetDefinition::Define( double & var, const wxChar * key, const dou
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "double", "type" ); AddItem( "double", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -564,7 +648,10 @@ void ShuttleGetDefinition::Define( wxString &var, const wxChar * key, const wxSt
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "string", "type" ); AddItem( "string", "type" );
AddItem( vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault, "default" );
EndStruct(); EndStruct();
} }
@ -574,7 +661,10 @@ void ShuttleGetDefinition::DefineEnum( wxString &var, const wxChar * key, const
StartStruct(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "enum", "type" ); AddItem( "enum", "type" );
AddItem( vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( vdefault, "default" );
AddField( "enum" ); AddField( "enum" );
StartArray(); StartArray();
for( size_t i=0;i<strings.Count(); i++ ) 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(); StartStruct();
AddItem( wxString(key), "key" ); AddItem( wxString(key), "key" );
AddItem( "enum", "type" ); AddItem( "enum", "type" );
AddItem( (double)vdefault, "default" ); if( IsOptional() )
AddItem( "unchanged", "default" );
else
AddItem( (double)vdefault, "default" );
AddField( "enum" ); AddField( "enum" );
StartArray(); StartArray();
for( size_t i=0;i<strings.Count(); i++ ) for( size_t i=0;i<strings.Count(); i++ )

View File

@ -67,11 +67,13 @@ class ShuttleParams : public Shuttle
{ {
public: public:
wxString mParams; wxString mParams;
bool *pOptionalFlag;
CommandAutomationParameters * mpEap; CommandAutomationParameters * mpEap;
ShuttleParams(){ mParams = wxT("") ;mpEap=NULL;} ShuttleParams(){ mParams = wxT("") ;mpEap=NULL;pOptionalFlag=NULL;}
virtual ~ShuttleParams() {} virtual ~ShuttleParams() {}
bool ExchangeWithMaster(const wxString & Name) override; 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( 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( 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 ); 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 class ShuttleGetAutomation : public ShuttleParams
{ {
public: 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( 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( 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; 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;}; ShuttleSetAutomation(){ bWrite = false; bOK = false;};
bool bOK; bool bOK;
bool bWrite; bool bWrite;
ShuttleParams & Optional( bool & var ) override;
bool CouldGet(const wxString &key);
void SetForValidating( CommandAutomationParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;}; void SetForValidating( CommandAutomationParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
void SetForWriting(CommandAutomationParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;}; 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; 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: public:
ShuttleGetDefinition( CommandMessageTarget & target ); ShuttleGetDefinition( CommandMessageTarget & target );
wxString Result; 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( 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( 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; 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; return *this;
} }
ShuttleGui & ShuttleGui::Optional( bool &bVar ){
TieCheckBox( "Set", bVar );
return *this;
};
GuiWaveTrack * ShuttleGui::AddGuiWaveTrack( const wxString & WXUNUSED(Name)) GuiWaveTrack * ShuttleGui::AddGuiWaveTrack( const wxString & WXUNUSED(Name))
{ {
#ifdef EXPERIMENTAL_TRACK_PANEL #ifdef EXPERIMENTAL_TRACK_PANEL

View File

@ -369,7 +369,7 @@ public:
ShuttleGui(wxWindow * pParent,teShuttleMode ShuttleMode); ShuttleGui(wxWindow * pParent,teShuttleMode ShuttleMode);
~ShuttleGui(void); ~ShuttleGui(void);
public: public:
ShuttleGui & Optional( bool & var ){ var = true;return *this;}; ShuttleGui & Optional( bool & bVar );
ShuttleGui & Id(int id ); ShuttleGui & Id(int id );
// Prop() sets the proportion value, defined as in wxSizer::Add(). // 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. 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.StartMultiColumn(2, wxALIGN_CENTER);
{ {
S.TieNumericTextBox( _("Track Index"), mTrackIndex ); S.TieNumericTextBox( _("Track Index"), mTrackIndex );
}
S.EndMultiColumn();
S.StartMultiColumn(3, wxALIGN_CENTER);
{
S.Optional( bHasTrackName ).TieTextBox( _("Name"), mTrackName ); S.Optional( bHasTrackName ).TieTextBox( _("Name"), mTrackName );
S.Optional( bHasPan ).TieSlider( _("Pan"), mPan, 1.0, -1.0); S.Optional( bHasPan ).TieSlider( _("Pan"), mPan, 1.0, -1.0);
S.Optional( bHasGain ).TieSlider( _("Gain"), mGain, 10.0, 0.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( bHasSelected ).TieCheckBox( _("Selected"), bSelected );
S.Optional( bHasFocused ).TieCheckBox( _("Focused"), bFocused); S.Optional( bHasFocused ).TieCheckBox( _("Focused"), bFocused);
S.Optional( bHasSolo ).TieCheckBox( _("Solo"), bSolo); S.Optional( bHasSolo ).TieCheckBox( _("Solo"), bSolo);