1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-05 00:23:56 +01:00

Support Spectral Selection and Spectrogram mode in Automation.

This commit is contained in:
James Crook
2018-02-15 15:20:04 +00:00
committed by Paul Licameli
parent a137885769
commit 4274ba7d01
4 changed files with 166 additions and 29 deletions

View File

@@ -15,11 +15,17 @@
\class SelectTimeCommand \class SelectTimeCommand
\brief Command for changing the time selection \brief Command for changing the time selection
\class SelectFrequenciesCommand
\brief Command for changing the frequency selection
\class SelectTracksCommand \class SelectTracksCommand
\brief Command for changing the selection of tracks \brief Command for changing the selection of tracks
\class SelectCommand \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; 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; const int nModes =3;
static const wxString kModes[nModes] = static const wxString kModes[nModes] =
{ {
@@ -82,7 +119,6 @@ static const wxString kModes[nModes] =
XO("Remove") XO("Remove")
}; };
bool SelectTracksCommand::DefineParams( ShuttleParams & S ){ bool SelectTracksCommand::DefineParams( ShuttleParams & S ){
wxArrayString modes( nModes, kModes ); wxArrayString modes( nModes, kModes );
S.Optional( bHasFirstTrack).Define( mFirstTrack, wxT("First"), 0, 0, 100); 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; bool sel = mFirstTrack <= index && index <= last;
if( mMode == 0 ){ // Set if( mMode == 0 ){ // Set
t->SetSelected(sel); t->SetSelected(sel);
if (sel) // if (sel)
context.Status(wxT("Selected track '") + t->GetName() + wxT("'")); // context.Status(wxT("Selected track '") + t->GetName() + wxT("'"));
} }
else if( mMode == 1 && sel ){ // Add else if( mMode == 1 && sel ){ // Add
t->SetSelected(sel); 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 else if( mMode == 2 && sel ){ // Remove
t->SetSelected(!sel); t->SetSelected(!sel);
context.Status(wxT("Removed track '") + t->GetName() + wxT("'")); // context.Status(wxT("Removed track '") + t->GetName() + wxT("'"));
} }
t = iter.Next(); t = iter.Next();
++index; ++index;
} }
return true; return true;
} }

View File

@@ -26,6 +26,7 @@
#define SELECT_TIME_PLUGIN_SYMBOL XO("Select Time") #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_TRACKS_PLUGIN_SYMBOL XO("Select Tracks")
#define SELECT_PLUGIN_SYMBOL XO("Select") #define SELECT_PLUGIN_SYMBOL XO("Select")
@@ -50,6 +51,27 @@ public:
bool mFromEnd; 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 class SelectTracksCommand : public AudacityCommand
{ {
public: public:
@@ -78,21 +100,30 @@ public:
wxString GetSymbol() override {return SELECT_PLUGIN_SYMBOL;}; wxString GetSymbol() override {return SELECT_PLUGIN_SYMBOL;};
wxString GetDescription() override {return _("Selects Audio.");}; wxString GetDescription() override {return _("Selects Audio.");};
bool DefineParams( ShuttleParams & S ) override { 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 { void PopulateOrExchange(ShuttleGui & S) override {
mSelTime.PopulateOrExchange(S); mSelTime.PopulateOrExchange(S);
mSelFreq.PopulateOrExchange(S);
mSelTracks.PopulateOrExchange(S); mSelTracks.PopulateOrExchange(S);
}; };
bool Apply(const CommandContext & context) override { 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 // AudacityCommand overrides
wxString ManualPage() override {return wxT("Audio_Selection");}; wxString ManualPage() override {return wxT("Audio_Selection");};
private: private:
SelectTimeCommand mSelTime; SelectTimeCommand mSelTime;
SelectFrequenciesCommand mSelFreq;
SelectTracksCommand mSelTracks; SelectTracksCommand mSelTracks;
}; };
#endif /* End of include guard: __SELECTCOMMAND__ */ #endif /* End of include guard: __SELECTCOMMAND__ */

View File

@@ -23,6 +23,8 @@
#include "../Track.h" #include "../Track.h"
#include "../TrackPanel.h" #include "../TrackPanel.h"
#include "../WaveTrack.h" #include "../WaveTrack.h"
#include "../prefs/WaveformSettings.h"
#include "../prefs/SpectrogramSettings.h"
#include "../ShuttleGui.h" #include "../ShuttleGui.h"
#include "CommandContext.h" #include "CommandContext.h"
@@ -47,24 +49,61 @@ static const wxString kColourStrings[nColours] =
XO("Color3"), 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 ){ bool SetTrackCommand::DefineParams( ShuttleParams & S ){
wxArrayString colours( nColours, kColourStrings ); wxArrayString colours( nColours, kColourStrings );
S.Define( mTrackIndex, wxT("Track"), 0, 0, 100 ); wxArrayString displays( nDisplayTypes, kDisplayTypeStrings );
S.Optional( bHasTrackName ).Define( mTrackName, wxT("Name"), wxT("Unnamed") ); wxArrayString scales( nScaleTypes, kScaleTypeStrings );
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.Define( mTrackIndex, wxT("Track"), 0, 0, 100 );
S.Optional( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 700 ); S.Optional( bHasTrackName ).Define( mTrackName, wxT("Name"), wxT("Unnamed") );
S.Optional( bHasColour ).DefineEnum( mColour, wxT("Color"), kColour0, colours ); S.Optional( bHasPan ).Define( mPan, wxT("Pan"), 0.0, -1.0, 1.0);
S.Optional( bHasSelected ).Define( bSelected, wxT("Selected"), false ); S.Optional( bHasGain ).Define( mGain, wxT("Gain"), 1.0, 0.0, 10.0);
S.Optional( bHasFocused ).Define( bFocused, wxT("Focused"), false ); S.Optional( bHasHeight ).Define( mHeight, wxT("Height"), 120, 44, 700 );
S.Optional( bHasSolo ).Define( bSolo, wxT("Solo"), false ); S.Optional( bHasDisplayType ).DefineEnum( mDisplayType, wxT("Display"), kWaveform, displays );
S.Optional( bHasMute ).Define( bMute, wxT("Mute"), false ); 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; return true;
}; };
void SetTrackCommand::PopulateOrExchange(ShuttleGui & S) 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); S.AddSpace(0, 5);
@@ -75,19 +114,23 @@ void SetTrackCommand::PopulateOrExchange(ShuttleGui & S)
S.EndMultiColumn(); S.EndMultiColumn();
S.StartMultiColumn(3, wxALIGN_CENTER); 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.Optional( bHasHeight ).TieNumericTextBox( _("Height:"), mHeight ); S.Optional( bHasHeight ).TieNumericTextBox( _("Height:"), mHeight );
S.Optional( bHasColour ).TieChoice( _("Colour:"), mColour, &colours ); S.Optional( bHasColour ).TieChoice( _("Colour:"), mColour, &colours );
S.Optional( bHasDisplayType ).TieChoice( _("Display:"), mDisplayType, &displays );
S.Optional( bHasScaleType ).TieChoice( _("Scale:"), mScaleType, &scales );
} }
S.EndMultiColumn(); S.EndMultiColumn();
S.StartMultiColumn(2, wxALIGN_CENTER); S.StartMultiColumn(2, wxALIGN_CENTER);
{ {
S.Optional( bHasSelected ).TieCheckBox( _("Selected:"), bSelected ); S.Optional( bHasSpectralSelect ).TieCheckBox( _("Spectral Select:"), bSpectralSelect );
S.Optional( bHasFocused ).TieCheckBox( _("Focused:"), bFocused); S.Optional( bHasGrayScale ).TieCheckBox( _("Gray Scale:"), bGrayScale );
S.Optional( bHasSolo ).TieCheckBox( _("Solo:"), bSolo); S.Optional( bHasSelected ).TieCheckBox( _("Selected:"), bSelected );
S.Optional( bHasMute ).TieCheckBox( _("Mute:"), bMute); S.Optional( bHasFocused ).TieCheckBox( _("Focused:"), bFocused);
S.Optional( bHasSolo ).TieCheckBox( _("Solo:"), bSolo);
S.Optional( bHasMute ).TieCheckBox( _("Mute:"), bMute);
} }
S.EndMultiColumn(); S.EndMultiColumn();
} }
@@ -124,6 +167,24 @@ bool SetTrackCommand::Apply(const CommandContext & context)
wt->SetWaveColorIndex( mColour ); wt->SetWaveColorIndex( mColour );
if( t && bHasHeight ) if( t && bHasHeight )
t->SetHeight( mHeight ); 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 ) if( bHasSelected )
t->SetSelected(bSelected); t->SetSelected(bSelected);
if( bHasFocused ) if( bHasFocused )

View File

@@ -44,6 +44,10 @@ public:
double mGain; double mGain;
int mColour; int mColour;
int mHeight; int mHeight;
int mDisplayType;
int mScaleType;
bool bSpectralSelect;
bool bGrayScale;
bool bSelected; bool bSelected;
bool bFocused; bool bFocused;
bool bSolo; bool bSolo;
@@ -55,6 +59,10 @@ public:
bool bHasGain; bool bHasGain;
bool bHasColour; bool bHasColour;
bool bHasHeight; bool bHasHeight;
bool bHasDisplayType;
bool bHasScaleType;
bool bHasSpectralSelect;
bool bHasGrayScale;
bool bHasSelected; bool bHasSelected;
bool bHasFocused; bool bHasFocused;
bool bHasSolo; bool bHasSolo;