mirror of
				https://github.com/cookiengineer/audacity
				synced 2025-11-03 23:53:55 +01:00 
			
		
		
		
	Support Spectral Selection and Spectrogram mode in Automation.
This commit is contained in:
		
				
					committed by
					
						
						Paul Licameli
					
				
			
			
				
	
			
			
			
						parent
						
							a137885769
						
					
				
				
					commit
					4274ba7d01
				
			@@ -15,11 +15,17 @@
 | 
			
		||||
\class SelectTimeCommand
 | 
			
		||||
\brief Command for changing the time selection
 | 
			
		||||
 | 
			
		||||
\class SelectFrequenciesCommand
 | 
			
		||||
\brief Command for changing the frequency selection
 | 
			
		||||
 | 
			
		||||
\class SelectTracksCommand
 | 
			
		||||
\brief Command for changing the selection of tracks
 | 
			
		||||
 | 
			
		||||
\class SelectCommand
 | 
			
		||||
\brief Command for changing both time and track selection.
 | 
			
		||||
\brief Command for changing time, frequency and track selection. This
 | 
			
		||||
class is a little baroque, as it uses the SelectTimeCommand, 
 | 
			
		||||
SelectFrequenciesCommand and SelectTracksCommand, when it could just
 | 
			
		||||
explicitly code all three.
 | 
			
		||||
 | 
			
		||||
*//*******************************************************************/
 | 
			
		||||
 | 
			
		||||
@@ -74,6 +80,37 @@ bool SelectTimeCommand::Apply(const CommandContext & context){
 | 
			
		||||
   return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool SelectFrequenciesCommand::DefineParams( ShuttleParams & S ){
 | 
			
		||||
   S.Optional( bHasTop ).Define(    mTop,    wxT("High"), 0.0, 0.0, (double)FLT_MAX);
 | 
			
		||||
   S.Optional( bHasBottom ).Define( mBottom, wxT("Low"),  0.0, 0.0, (double)FLT_MAX);
 | 
			
		||||
   return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SelectFrequenciesCommand::PopulateOrExchange(ShuttleGui & S)
 | 
			
		||||
{
 | 
			
		||||
   S.AddSpace(0, 5);
 | 
			
		||||
 | 
			
		||||
   S.StartMultiColumn(3, wxALIGN_CENTER);
 | 
			
		||||
   {
 | 
			
		||||
      S.Optional( bHasTop    ).TieTextBox(_("High:"), mTop);
 | 
			
		||||
      S.Optional( bHasBottom ).TieTextBox(_("Low:"),  mBottom);
 | 
			
		||||
   }
 | 
			
		||||
   S.EndMultiColumn();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool SelectFrequenciesCommand::Apply(const CommandContext & context){
 | 
			
		||||
   if( !bHasBottom && !bHasTop )
 | 
			
		||||
      return true;
 | 
			
		||||
 | 
			
		||||
   // Count selection as a do-nothing effect.
 | 
			
		||||
   // Used to invalidate cached selection and tracks.
 | 
			
		||||
   Effect::IncEffectCounter();
 | 
			
		||||
 | 
			
		||||
   context.GetProject()->SSBL_ModifySpectralSelection(
 | 
			
		||||
      mBottom, mTop, false);// false for not done.
 | 
			
		||||
   return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const int nModes =3;
 | 
			
		||||
static const wxString kModes[nModes] =
 | 
			
		||||
{
 | 
			
		||||
@@ -82,7 +119,6 @@ static const wxString kModes[nModes] =
 | 
			
		||||
   XO("Remove")
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool SelectTracksCommand::DefineParams( ShuttleParams & S ){
 | 
			
		||||
   wxArrayString modes( nModes, kModes );
 | 
			
		||||
   S.Optional( bHasFirstTrack).Define( mFirstTrack, wxT("First"), 0, 0, 100);
 | 
			
		||||
@@ -129,19 +165,20 @@ bool SelectTracksCommand::Apply(const CommandContext &context)
 | 
			
		||||
      bool sel = mFirstTrack <= index && index <= last;
 | 
			
		||||
      if( mMode == 0 ){ // Set
 | 
			
		||||
         t->SetSelected(sel);
 | 
			
		||||
         if (sel)
 | 
			
		||||
            context.Status(wxT("Selected track '") + t->GetName() + wxT("'"));
 | 
			
		||||
//       if (sel)
 | 
			
		||||
//          context.Status(wxT("Selected track '") + t->GetName() + wxT("'"));
 | 
			
		||||
      }
 | 
			
		||||
      else if( mMode == 1 && sel ){ // Add
 | 
			
		||||
         t->SetSelected(sel);
 | 
			
		||||
         context.Status(wxT("Added track '") + t->GetName() + wxT("'"));
 | 
			
		||||
//       context.Status(wxT("Added track '") + t->GetName() + wxT("'"));
 | 
			
		||||
      }
 | 
			
		||||
      else if( mMode == 2 && sel ){ // Remove
 | 
			
		||||
         t->SetSelected(!sel);
 | 
			
		||||
         context.Status(wxT("Removed track '") + t->GetName() + wxT("'"));
 | 
			
		||||
//       context.Status(wxT("Removed track '") + t->GetName() + wxT("'"));
 | 
			
		||||
      }
 | 
			
		||||
      t = iter.Next();
 | 
			
		||||
      ++index;
 | 
			
		||||
   }
 | 
			
		||||
   return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,7 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define SELECT_TIME_PLUGIN_SYMBOL XO("Select Time")
 | 
			
		||||
#define SELECT_FREQUENCY_PLUGIN_SYMBOL XO("Select Frequency")
 | 
			
		||||
#define SELECT_TRACKS_PLUGIN_SYMBOL XO("Select Tracks")
 | 
			
		||||
#define SELECT_PLUGIN_SYMBOL XO("Select")
 | 
			
		||||
 | 
			
		||||
@@ -50,6 +51,27 @@ public:
 | 
			
		||||
   bool mFromEnd;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SelectFrequenciesCommand : public AudacityCommand
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
   // CommandDefinitionInterface overrides
 | 
			
		||||
   wxString GetSymbol() override {return SELECT_FREQUENCY_PLUGIN_SYMBOL;};
 | 
			
		||||
   wxString GetDescription() override {return _("Selects a frequency range.");};
 | 
			
		||||
   bool DefineParams( ShuttleParams & S ) override;
 | 
			
		||||
   void PopulateOrExchange(ShuttleGui & S) override;
 | 
			
		||||
   bool Apply(const CommandContext & context) override;
 | 
			
		||||
 | 
			
		||||
   // AudacityCommand overrides
 | 
			
		||||
   wxString ManualPage() override {return wxT("Spectral_Selection");};
 | 
			
		||||
 | 
			
		||||
   bool bHasBottom;
 | 
			
		||||
   bool bHasTop;
 | 
			
		||||
 | 
			
		||||
   double mBottom;
 | 
			
		||||
   double mTop;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SelectTracksCommand : public AudacityCommand
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
@@ -78,21 +100,30 @@ public:
 | 
			
		||||
   wxString GetSymbol() override {return SELECT_PLUGIN_SYMBOL;};
 | 
			
		||||
   wxString GetDescription() override {return _("Selects Audio.");};
 | 
			
		||||
   bool DefineParams( ShuttleParams & S ) override { 
 | 
			
		||||
      return mSelTime.DefineParams(S) &&  mSelTracks.DefineParams(S);
 | 
			
		||||
      return 
 | 
			
		||||
         mSelTime.DefineParams(S) &&  
 | 
			
		||||
         mSelFreq.DefineParams(S) &&
 | 
			
		||||
         mSelTracks.DefineParams(S);
 | 
			
		||||
   };
 | 
			
		||||
   void PopulateOrExchange(ShuttleGui & S) override {
 | 
			
		||||
      mSelTime.PopulateOrExchange(S);
 | 
			
		||||
      mSelFreq.PopulateOrExchange(S);
 | 
			
		||||
      mSelTracks.PopulateOrExchange(S);
 | 
			
		||||
   };
 | 
			
		||||
   bool Apply(const CommandContext & context) override {
 | 
			
		||||
      return mSelTime.Apply(context) &&  mSelTracks.Apply(context);
 | 
			
		||||
      return 
 | 
			
		||||
         mSelTime.Apply(context) &&  
 | 
			
		||||
         mSelFreq.Apply( context )&&
 | 
			
		||||
         mSelTracks.Apply(context);
 | 
			
		||||
   }
 | 
			
		||||
   // AudacityCommand overrides
 | 
			
		||||
   wxString ManualPage() override {return wxT("Audio_Selection");};
 | 
			
		||||
private:
 | 
			
		||||
   SelectTimeCommand mSelTime;
 | 
			
		||||
   SelectFrequenciesCommand mSelFreq;
 | 
			
		||||
   SelectTracksCommand mSelTracks;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* End of include guard: __SELECTCOMMAND__ */
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@
 | 
			
		||||
#include "../Track.h"
 | 
			
		||||
#include "../TrackPanel.h"
 | 
			
		||||
#include "../WaveTrack.h"
 | 
			
		||||
#include "../prefs/WaveformSettings.h"
 | 
			
		||||
#include "../prefs/SpectrogramSettings.h"
 | 
			
		||||
#include "../ShuttleGui.h"
 | 
			
		||||
#include "CommandContext.h"
 | 
			
		||||
 | 
			
		||||
@@ -47,24 +49,61 @@ static const wxString kColourStrings[nColours] =
 | 
			
		||||
   XO("Color3"),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
enum kDisplayTypes
 | 
			
		||||
{
 | 
			
		||||
   kWaveform,
 | 
			
		||||
   kSpectrogram,
 | 
			
		||||
   nDisplayTypes
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const wxString kDisplayTypeStrings[nDisplayTypes] =
 | 
			
		||||
{
 | 
			
		||||
   XO("Waveform"),
 | 
			
		||||
   XO("Spectrogram"),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum kScaleTypes
 | 
			
		||||
{
 | 
			
		||||
   kLinear,
 | 
			
		||||
   kDb,
 | 
			
		||||
   nScaleTypes
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const wxString kScaleTypeStrings[nScaleTypes] =
 | 
			
		||||
{
 | 
			
		||||
   XO("Linear"),
 | 
			
		||||
   XO("dB"),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool SetTrackCommand::DefineParams( ShuttleParams & S ){ 
 | 
			
		||||
   wxArrayString colours( nColours, kColourStrings );
 | 
			
		||||
   S.Define(   mTrackIndex,                                wxT("Track"), 0, 0, 100 );
 | 
			
		||||
   S.Optional( bHasTrackName   ).Define(     mTrackName,   wxT("Name"),       wxT("Unnamed") );
 | 
			
		||||
   S.Optional( bHasPan         ).Define(     mPan,         wxT("Pan"),        0.0, -1.0, 1.0);
 | 
			
		||||
   S.Optional( bHasGain        ).Define(     mGain,        wxT("Gain"),       1.0,  0.0, 10.0);
 | 
			
		||||
   S.Optional( bHasHeight      ).Define(     mHeight,      wxT("Height"),     120, 44, 700 );
 | 
			
		||||
   S.Optional( bHasColour      ).DefineEnum( mColour,      wxT("Color"),      kColour0, colours );
 | 
			
		||||
   S.Optional( bHasSelected    ).Define(     bSelected,    wxT("Selected"),   false );
 | 
			
		||||
   S.Optional( bHasFocused     ).Define(     bFocused,     wxT("Focused"),    false );
 | 
			
		||||
   S.Optional( bHasSolo        ).Define(     bSolo,        wxT("Solo"),       false );
 | 
			
		||||
   S.Optional( bHasMute        ).Define(     bMute,        wxT("Mute"),       false );
 | 
			
		||||
   wxArrayString colours(  nColours,      kColourStrings );
 | 
			
		||||
   wxArrayString displays( nDisplayTypes, kDisplayTypeStrings );
 | 
			
		||||
   wxArrayString scales(   nScaleTypes,   kScaleTypeStrings );
 | 
			
		||||
 | 
			
		||||
   S.Define(   mTrackIndex,                                      wxT("Track"), 0, 0, 100 );
 | 
			
		||||
   S.Optional( bHasTrackName      ).Define(     mTrackName,      wxT("Name"),       wxT("Unnamed") );
 | 
			
		||||
   S.Optional( bHasPan            ).Define(     mPan,            wxT("Pan"),        0.0, -1.0, 1.0);
 | 
			
		||||
   S.Optional( bHasGain           ).Define(     mGain,           wxT("Gain"),       1.0,  0.0, 10.0);
 | 
			
		||||
   S.Optional( bHasHeight         ).Define(     mHeight,         wxT("Height"),     120, 44, 700 );
 | 
			
		||||
   S.Optional( bHasDisplayType    ).DefineEnum( mDisplayType,    wxT("Display"),    kWaveform, displays );
 | 
			
		||||
   S.Optional( bHasScaleType      ).DefineEnum( mScaleType,      wxT("Scale"),      kLinear,   scales );
 | 
			
		||||
   S.Optional( bHasColour         ).DefineEnum( mColour,         wxT("Color"),      kColour0,  colours );
 | 
			
		||||
   S.Optional( bHasSpectralSelect ).Define(     bSpectralSelect, wxT("SpectralSel"),true );
 | 
			
		||||
   S.Optional( bHasGrayScale      ).Define(     bGrayScale,      wxT("GrayScale"),  false );
 | 
			
		||||
   S.Optional( bHasSelected       ).Define(     bSelected,       wxT("Selected"),   false );
 | 
			
		||||
   S.Optional( bHasFocused        ).Define(     bFocused,        wxT("Focused"),    false );
 | 
			
		||||
   S.Optional( bHasSolo           ).Define(     bSolo,           wxT("Solo"),       false );
 | 
			
		||||
   S.Optional( bHasMute           ).Define(     bMute,           wxT("Mute"),       false );
 | 
			
		||||
   return true;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void SetTrackCommand::PopulateOrExchange(ShuttleGui & S)
 | 
			
		||||
{
 | 
			
		||||
   wxArrayString colours( nColours, kColourStrings );
 | 
			
		||||
   wxArrayString colours(  nColours,      kColourStrings );
 | 
			
		||||
   wxArrayString displays( nDisplayTypes, kDisplayTypeStrings );
 | 
			
		||||
   wxArrayString scales(   nScaleTypes,   kScaleTypeStrings );
 | 
			
		||||
 | 
			
		||||
   S.AddSpace(0, 5);
 | 
			
		||||
 | 
			
		||||
@@ -75,19 +114,23 @@ void SetTrackCommand::PopulateOrExchange(ShuttleGui & S)
 | 
			
		||||
   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.Optional( bHasHeight    ).TieNumericTextBox(  _("Height:"),   mHeight );
 | 
			
		||||
      S.Optional( bHasColour    ).TieChoice(          _("Colour:"),   mColour, &colours );
 | 
			
		||||
      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.Optional( bHasHeight      ).TieNumericTextBox(  _("Height:"),   mHeight );
 | 
			
		||||
      S.Optional( bHasColour      ).TieChoice(          _("Colour:"),   mColour,      &colours );
 | 
			
		||||
      S.Optional( bHasDisplayType ).TieChoice(          _("Display:"),  mDisplayType, &displays );
 | 
			
		||||
      S.Optional( bHasScaleType   ).TieChoice(          _("Scale:"),    mScaleType,   &scales );
 | 
			
		||||
   }
 | 
			
		||||
   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);
 | 
			
		||||
      S.Optional( bHasMute      ).TieCheckBox( _("Mute:"),     bMute);
 | 
			
		||||
      S.Optional( bHasSpectralSelect ).TieCheckBox( _("Spectral Select:"), bSpectralSelect );
 | 
			
		||||
      S.Optional( bHasGrayScale      ).TieCheckBox( _("Gray Scale:"),      bGrayScale );
 | 
			
		||||
      S.Optional( bHasSelected       ).TieCheckBox( _("Selected:"),        bSelected );
 | 
			
		||||
      S.Optional( bHasFocused        ).TieCheckBox( _("Focused:"),         bFocused);
 | 
			
		||||
      S.Optional( bHasSolo           ).TieCheckBox( _("Solo:"),            bSolo);
 | 
			
		||||
      S.Optional( bHasMute           ).TieCheckBox( _("Mute:"),            bMute);
 | 
			
		||||
   }
 | 
			
		||||
   S.EndMultiColumn();
 | 
			
		||||
}
 | 
			
		||||
@@ -124,6 +167,24 @@ bool SetTrackCommand::Apply(const CommandContext & context)
 | 
			
		||||
      wt->SetWaveColorIndex( mColour );
 | 
			
		||||
   if( t && bHasHeight )
 | 
			
		||||
      t->SetHeight( mHeight );
 | 
			
		||||
 | 
			
		||||
   if( wt && bHasDisplayType  )
 | 
			
		||||
      wt->SetDisplay(
 | 
			
		||||
         (mDisplayType == kWaveform) ? 
 | 
			
		||||
            WaveTrack::WaveTrackDisplay::Waveform
 | 
			
		||||
            : WaveTrack::WaveTrackDisplay::Spectrum
 | 
			
		||||
         );
 | 
			
		||||
   if( wt && bHasScaleType )
 | 
			
		||||
      wt->GetIndependentWaveformSettings().scaleType = 
 | 
			
		||||
         (mScaleType==kLinear) ? 
 | 
			
		||||
            WaveformSettings::stLinear
 | 
			
		||||
            : WaveformSettings::stLogarithmic;
 | 
			
		||||
   if( wt && bHasSpectralSelect )
 | 
			
		||||
      wt->GetSpectrogramSettings().spectralSelection = bSpectralSelect;
 | 
			
		||||
   if( wt && bHasGrayScale )
 | 
			
		||||
      wt->GetSpectrogramSettings().isGrayscale = bGrayScale;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   if( bHasSelected )
 | 
			
		||||
      t->SetSelected(bSelected);
 | 
			
		||||
   if( bHasFocused )
 | 
			
		||||
 
 | 
			
		||||
@@ -44,6 +44,10 @@ public:
 | 
			
		||||
   double mGain;
 | 
			
		||||
   int mColour;
 | 
			
		||||
   int mHeight;
 | 
			
		||||
   int mDisplayType;
 | 
			
		||||
   int mScaleType;
 | 
			
		||||
   bool bSpectralSelect;
 | 
			
		||||
   bool bGrayScale;
 | 
			
		||||
   bool bSelected;
 | 
			
		||||
   bool bFocused;
 | 
			
		||||
   bool bSolo;
 | 
			
		||||
@@ -55,6 +59,10 @@ public:
 | 
			
		||||
   bool bHasGain;
 | 
			
		||||
   bool bHasColour;
 | 
			
		||||
   bool bHasHeight;
 | 
			
		||||
   bool bHasDisplayType;
 | 
			
		||||
   bool bHasScaleType;
 | 
			
		||||
   bool bHasSpectralSelect;
 | 
			
		||||
   bool bHasGrayScale;
 | 
			
		||||
   bool bHasSelected;
 | 
			
		||||
   bool bHasFocused;
 | 
			
		||||
   bool bHasSolo;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user