New files for ProjectSelectionManager

This commit is contained in:
Paul Licameli 2019-06-09 07:42:40 -04:00
parent 186f2f6ac7
commit 997bf9781d
13 changed files with 365 additions and 287 deletions

View File

@ -174,6 +174,8 @@ src/ProjectHistory.cpp
src/ProjectHistory.h
src/ProjectManager.cpp
src/ProjectManager.h
src/ProjectSelectionManager.cpp
src/ProjectSelectionManager.h
src/ProjectSettings.cpp
src/ProjectSettings.h
src/ProjectWindow.cpp

View File

@ -1245,6 +1245,7 @@
5E36A0B0217FA2430068E082 /* WindowMenus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E36A0A7217FA2430068E082 /* WindowMenus.cpp */; };
5E36A0B2217FC5A10068E082 /* (null) in Sources */ = {isa = PBXBuildFile; };
5E36A0B4217FC6540068E082 /* HelpMenus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E36A0B3217FC6540068E082 /* HelpMenus.cpp */; };
5E3A530822AD277A00C4ADB8 /* ProjectSelectionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E3A530622AD277A00C4ADB8 /* ProjectSelectionManager.cpp */; };
5E3FFE721EC9032B0020F7C9 /* NoteTrackSliderHandles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E3FFE701EC9032B0020F7C9 /* NoteTrackSliderHandles.cpp */; };
5E667A601F0BEE5F00C942A5 /* WaveTrackVZoomHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E667A5E1F0BEE5F00C942A5 /* WaveTrackVZoomHandle.cpp */; };
5E667A651F0BEE8C00C942A5 /* NoteTrackButtonHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E667A611F0BEE8C00C942A5 /* NoteTrackButtonHandle.cpp */; };
@ -3237,6 +3238,8 @@
5E36A0A6217FA2430068E082 /* ViewMenus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ViewMenus.cpp; path = menus/ViewMenus.cpp; sourceTree = "<group>"; };
5E36A0A7217FA2430068E082 /* WindowMenus.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = WindowMenus.cpp; path = menus/WindowMenus.cpp; sourceTree = "<group>"; };
5E36A0B3217FC6540068E082 /* HelpMenus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HelpMenus.cpp; path = menus/HelpMenus.cpp; sourceTree = "<group>"; };
5E3A530622AD277A00C4ADB8 /* ProjectSelectionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProjectSelectionManager.cpp; sourceTree = "<group>"; };
5E3A530722AD277A00C4ADB8 /* ProjectSelectionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectSelectionManager.h; sourceTree = "<group>"; };
5E3FFE701EC9032B0020F7C9 /* NoteTrackSliderHandles.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NoteTrackSliderHandles.cpp; sourceTree = "<group>"; };
5E3FFE711EC9032B0020F7C9 /* NoteTrackSliderHandles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NoteTrackSliderHandles.h; sourceTree = "<group>"; };
5E4685F81CCA9D84008741F2 /* CommandFunctors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommandFunctors.h; sourceTree = "<group>"; };
@ -4390,6 +4393,7 @@
5ECF728C228B307E007F2A35 /* ProjectFSCK.cpp */,
5EB15A1E22A94043009FEC89 /* ProjectHistory.cpp */,
5E135A3A229EDF2E0076E983 /* ProjectManager.cpp */,
5E3A530622AD277A00C4ADB8 /* ProjectSelectionManager.cpp */,
5E135A34229EDBE80076E983 /* ProjectSettings.cpp */,
5E135A46229EE5530076E983 /* ProjectWindow.cpp */,
28DABFBC0FF19DB100AC7848 /* RealFFTf.cpp */,
@ -4513,6 +4517,7 @@
5ECF728B228B307E007F2A35 /* ProjectFSCK.h */,
5EB15A1F22A94043009FEC89 /* ProjectHistory.h */,
5E135A3B229EDF2E0076E983 /* ProjectManager.h */,
5E3A530722AD277A00C4ADB8 /* ProjectSelectionManager.h */,
5E135A35229EDBE80076E983 /* ProjectSettings.h */,
5E135A47229EE5530076E983 /* ProjectWindow.h */,
28DABFBD0FF19DB100AC7848 /* RealFFTf.h */,
@ -8547,6 +8552,7 @@
28B97B890FBF771A0076CF28 /* VSTEffect.cpp in Sources */,
284B279A0FC66864005EAC96 /* DevicePrefs.cpp in Sources */,
284B279B0FC66864005EAC96 /* ImportExportPrefs.cpp in Sources */,
5E3A530822AD277A00C4ADB8 /* ProjectSelectionManager.cpp in Sources */,
284B279C0FC66864005EAC96 /* LibraryPrefs.cpp in Sources */,
5E15126E1DB0010C00702E29 /* TrackControls.cpp in Sources */,
5EA0182A1EC7B226001F2996 /* NoteTrackVRulerControls.cpp in Sources */,

View File

@ -225,6 +225,8 @@ audacity_SOURCES = \
ProjectHistory.h \
ProjectManager.cpp \
ProjectManager.h \
ProjectSelectionManager.cpp \
ProjectSelectionManager.h \
ProjectSettings.cpp \
ProjectSettings.h \
ProjectWindow.cpp \

View File

@ -325,15 +325,16 @@ am__audacity_SOURCES_DIST = BlockFile.cpp BlockFile.h DirManager.cpp \
ProjectFileIO.cpp ProjectFileIO.h ProjectFileIORegistry.cpp \
ProjectFileIORegistry.h ProjectFSCK.cpp ProjectFSCK.h \
ProjectHistory.cpp ProjectHistory.h ProjectManager.cpp \
ProjectManager.h ProjectSettings.cpp ProjectSettings.h \
ProjectWindow.cpp ProjectWindow.h RealFFTf.cpp RealFFTf.h \
RealFFTf48x.cpp RealFFTf48x.h RefreshCode.h Resample.cpp \
Resample.h RevisionIdent.h RingBuffer.cpp RingBuffer.h \
Screenshot.cpp Screenshot.h SelectedRegion.cpp \
SelectedRegion.h SelectionState.cpp SelectionState.h \
Shuttle.cpp Shuttle.h ShuttleGetDefinition.cpp \
ShuttleGetDefinition.h ShuttleGui.cpp ShuttleGui.h \
ShuttlePrefs.cpp ShuttlePrefs.h Snap.cpp Snap.h \
ProjectManager.h ProjectSelectionManager.cpp \
ProjectSelectionManager.h ProjectSettings.cpp \
ProjectSettings.h ProjectWindow.cpp ProjectWindow.h \
RealFFTf.cpp RealFFTf.h RealFFTf48x.cpp RealFFTf48x.h \
RefreshCode.h Resample.cpp Resample.h RevisionIdent.h \
RingBuffer.cpp RingBuffer.h Screenshot.cpp Screenshot.h \
SelectedRegion.cpp SelectedRegion.h SelectionState.cpp \
SelectionState.h Shuttle.cpp Shuttle.h \
ShuttleGetDefinition.cpp ShuttleGetDefinition.h ShuttleGui.cpp \
ShuttleGui.h ShuttlePrefs.cpp ShuttlePrefs.h Snap.cpp Snap.h \
SoundActivatedRecord.cpp SoundActivatedRecord.h Spectrum.cpp \
Spectrum.h SplashDialog.cpp SplashDialog.h SseMathFuncs.cpp \
SseMathFuncs.h Tags.cpp Tags.h Theme.cpp Theme.h \
@ -677,6 +678,7 @@ am_audacity_OBJECTS = $(am__objects_1) audacity-AboutDialog.$(OBJEXT) \
audacity-ProjectFSCK.$(OBJEXT) \
audacity-ProjectHistory.$(OBJEXT) \
audacity-ProjectManager.$(OBJEXT) \
audacity-ProjectSelectionManager.$(OBJEXT) \
audacity-ProjectSettings.$(OBJEXT) \
audacity-ProjectWindow.$(OBJEXT) audacity-RealFFTf.$(OBJEXT) \
audacity-RealFFTf48x.$(OBJEXT) audacity-Resample.$(OBJEXT) \
@ -1400,15 +1402,16 @@ audacity_SOURCES = $(libaudacity_la_SOURCES) AboutDialog.cpp \
ProjectFileIO.cpp ProjectFileIO.h ProjectFileIORegistry.cpp \
ProjectFileIORegistry.h ProjectFSCK.cpp ProjectFSCK.h \
ProjectHistory.cpp ProjectHistory.h ProjectManager.cpp \
ProjectManager.h ProjectSettings.cpp ProjectSettings.h \
ProjectWindow.cpp ProjectWindow.h RealFFTf.cpp RealFFTf.h \
RealFFTf48x.cpp RealFFTf48x.h RefreshCode.h Resample.cpp \
Resample.h RevisionIdent.h RingBuffer.cpp RingBuffer.h \
Screenshot.cpp Screenshot.h SelectedRegion.cpp \
SelectedRegion.h SelectionState.cpp SelectionState.h \
Shuttle.cpp Shuttle.h ShuttleGetDefinition.cpp \
ShuttleGetDefinition.h ShuttleGui.cpp ShuttleGui.h \
ShuttlePrefs.cpp ShuttlePrefs.h Snap.cpp Snap.h \
ProjectManager.h ProjectSelectionManager.cpp \
ProjectSelectionManager.h ProjectSettings.cpp \
ProjectSettings.h ProjectWindow.cpp ProjectWindow.h \
RealFFTf.cpp RealFFTf.h RealFFTf48x.cpp RealFFTf48x.h \
RefreshCode.h Resample.cpp Resample.h RevisionIdent.h \
RingBuffer.cpp RingBuffer.h Screenshot.cpp Screenshot.h \
SelectedRegion.cpp SelectedRegion.h SelectionState.cpp \
SelectionState.h Shuttle.cpp Shuttle.h \
ShuttleGetDefinition.cpp ShuttleGetDefinition.h ShuttleGui.cpp \
ShuttleGui.h ShuttlePrefs.cpp ShuttlePrefs.h Snap.cpp Snap.h \
SoundActivatedRecord.cpp SoundActivatedRecord.h Spectrum.cpp \
Spectrum.h SplashDialog.cpp SplashDialog.h SseMathFuncs.cpp \
SseMathFuncs.h Tags.cpp Tags.h Theme.cpp Theme.h \
@ -2583,6 +2586,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectFileIORegistry.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectHistory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectSelectionManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectSettings.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ProjectWindow.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-RealFFTf.Po@am__quote@
@ -4098,6 +4102,20 @@ audacity-ProjectManager.obj: ProjectManager.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -c -o audacity-ProjectManager.obj `if test -f 'ProjectManager.cpp'; then $(CYGPATH_W) 'ProjectManager.cpp'; else $(CYGPATH_W) '$(srcdir)/ProjectManager.cpp'; fi`
audacity-ProjectSelectionManager.o: ProjectSelectionManager.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT audacity-ProjectSelectionManager.o -MD -MP -MF $(DEPDIR)/audacity-ProjectSelectionManager.Tpo -c -o audacity-ProjectSelectionManager.o `test -f 'ProjectSelectionManager.cpp' || echo '$(srcdir)/'`ProjectSelectionManager.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/audacity-ProjectSelectionManager.Tpo $(DEPDIR)/audacity-ProjectSelectionManager.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ProjectSelectionManager.cpp' object='audacity-ProjectSelectionManager.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -c -o audacity-ProjectSelectionManager.o `test -f 'ProjectSelectionManager.cpp' || echo '$(srcdir)/'`ProjectSelectionManager.cpp
audacity-ProjectSelectionManager.obj: ProjectSelectionManager.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT audacity-ProjectSelectionManager.obj -MD -MP -MF $(DEPDIR)/audacity-ProjectSelectionManager.Tpo -c -o audacity-ProjectSelectionManager.obj `if test -f 'ProjectSelectionManager.cpp'; then $(CYGPATH_W) 'ProjectSelectionManager.cpp'; else $(CYGPATH_W) '$(srcdir)/ProjectSelectionManager.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/audacity-ProjectSelectionManager.Tpo $(DEPDIR)/audacity-ProjectSelectionManager.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ProjectSelectionManager.cpp' object='audacity-ProjectSelectionManager.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -c -o audacity-ProjectSelectionManager.obj `if test -f 'ProjectSelectionManager.cpp'; then $(CYGPATH_W) 'ProjectSelectionManager.cpp'; else $(CYGPATH_W) '$(srcdir)/ProjectSelectionManager.cpp'; fi`
audacity-ProjectSettings.o: ProjectSettings.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT audacity-ProjectSettings.o -MD -MP -MF $(DEPDIR)/audacity-ProjectSettings.Tpo -c -o audacity-ProjectSettings.o `test -f 'ProjectSettings.cpp' || echo '$(srcdir)/'`ProjectSettings.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/audacity-ProjectSettings.Tpo $(DEPDIR)/audacity-ProjectSettings.Po

View File

@ -31,10 +31,10 @@ Paul Licameli split from AudacityProject.cpp
#include "ProjectFileIORegistry.h"
#include "ProjectFSCK.h"
#include "ProjectHistory.h"
#include "ProjectSelectionManager.h"
#include "ProjectSettings.h"
#include "ProjectWindow.h"
#include "Sequence.h"
#include "Snap.h"
#include "Tags.h"
#include "TrackPanel.h"
#include "UndoManager.h"
@ -61,33 +61,6 @@ Paul Licameli split from AudacityProject.cpp
const int AudacityProjectTimerID = 5200;
static AudacityProject::AttachedObjects::RegisteredFactory
sProjectSelectionManagerKey {
[]( AudacityProject &project ) {
return std::make_shared< ProjectSelectionManager >( project );
}
};
ProjectSelectionManager &ProjectSelectionManager::Get(
AudacityProject &project )
{
return project.AttachedObjects::Get< ProjectSelectionManager >(
sProjectSelectionManagerKey );
}
const ProjectSelectionManager &ProjectSelectionManager::Get(
const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
ProjectSelectionManager::ProjectSelectionManager( AudacityProject &project )
: mProject{ project }
{
}
ProjectSelectionManager::~ProjectSelectionManager() = default;
static AudacityProject::AttachedObjects::RegisteredFactory sProjectManagerKey {
[]( AudacityProject &project ) {
return std::make_shared< ProjectManager >( project );
@ -447,204 +420,6 @@ AudacityProject *ProjectManager::New()
return p;
}
bool ProjectSelectionManager::SnapSelection()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &window = ProjectWindow::Get( project );
auto snapTo = settings.GetSnapTo();
if (snapTo != SNAP_OFF) {
auto &viewInfo = ViewInfo::Get( project );
SelectedRegion &selectedRegion = viewInfo.selectedRegion;
NumericConverter nc(NumericConverter::TIME,
settings.GetSelectionFormat(), 0, settings.GetRate());
const bool nearest = (snapTo == SNAP_NEAREST);
const double oldt0 = selectedRegion.t0();
const double oldt1 = selectedRegion.t1();
nc.ValueToControls(oldt0, nearest);
nc.ControlsToValue();
const double t0 = nc.GetValue();
nc.ValueToControls(oldt1, nearest);
nc.ControlsToValue();
const double t1 = nc.GetValue();
if (t0 != oldt0 || t1 != oldt1) {
selectedRegion.setTimes(t0, t1);
window.TP_DisplaySelection();
return true;
}
}
return false;
}
double ProjectSelectionManager::AS_GetRate()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetRate();
}
// Typically this came from the SelectionToolbar and does not need to
// be communicated back to it.
void ProjectSelectionManager::AS_SetRate(double rate)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetRate( rate );
}
int ProjectSelectionManager::AS_GetSnapTo()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetSnapTo();
}
void ProjectSelectionManager::AS_SetSnapTo(int snap)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &window = ProjectWindow::Get( project );
settings.SetSnapTo( snap );
// LLL: TODO - what should this be changed to???
// GetCommandManager()->Check(wxT("Snap"), mSnapTo);
gPrefs->Write(wxT("/SnapTo"), snap);
gPrefs->Flush();
SnapSelection();
window.RedrawProject();
SelectionBar::Get( project ).SetSnapTo(snap);
}
const NumericFormatSymbol & ProjectSelectionManager::AS_GetSelectionFormat()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetSelectionFormat();
}
void ProjectSelectionManager::AS_SetSelectionFormat(
const NumericFormatSymbol & format)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetSelectionFormat( format );
gPrefs->Write(wxT("/SelectionFormat"), format.Internal());
gPrefs->Flush();
if (SnapSelection())
TrackPanel::Get( project ).Refresh(false);
SelectionBar::Get( project ).SetSelectionFormat(format);
}
void ProjectSelectionManager::AS_ModifySelection(
double &start, double &end, bool done)
{
auto &project = mProject;
auto &history = ProjectHistory::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
viewInfo.selectedRegion.setTimes(start, end);
trackPanel.Refresh(false);
if (done) {
history.ModifyState(false);
}
}
double ProjectSelectionManager::SSBL_GetRate() const
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &tracks = TrackList::Get( project );
// Return maximum of project rate and all track rates.
return std::max( settings.GetRate(),
tracks.Any<const WaveTrack>().max( &WaveTrack::GetRate ) );
}
const NumericFormatSymbol &
ProjectSelectionManager::SSBL_GetFrequencySelectionFormatName()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetFrequencySelectionFormatName();
}
void ProjectSelectionManager::SSBL_SetFrequencySelectionFormatName(
const NumericFormatSymbol & formatName)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetFrequencySelectionFormatName( formatName );
gPrefs->Write(wxT("/FrequencySelectionFormatName"),
formatName.Internal());
gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetFrequencySelectionFormatName(formatName);
#endif
}
const NumericFormatSymbol &
ProjectSelectionManager::SSBL_GetBandwidthSelectionFormatName()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetBandwidthSelectionFormatName();
}
void ProjectSelectionManager::SSBL_SetBandwidthSelectionFormatName(
const NumericFormatSymbol & formatName)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetBandwidthSelectionFormatName( formatName );
gPrefs->Write(wxT("/BandwidthSelectionFormatName"),
formatName.Internal());
gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetBandwidthSelectionFormatName(formatName);
#endif
}
void ProjectSelectionManager::SSBL_ModifySpectralSelection(
double &bottom, double &top, bool done)
{
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
auto &project = mProject;
auto &history = ProjectHistory::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
double nyq = SSBL_GetRate() / 2.0;
if (bottom >= 0.0)
bottom = std::min(nyq, bottom);
if (top >= 0.0)
top = std::min(nyq, top);
viewInfo.selectedRegion.setFrequencies(bottom, top);
trackPanel.Refresh(false);
if (done) {
history.ModifyState(false);
}
#else
bottom; top; done;
#endif
}
// LL: All objects that have a reference to the DirManager should
// be deleted before the final mDirManager->Deref() in this
// routine. Failing to do so can cause unwanted recursion

View File

@ -16,8 +16,6 @@ Paul Licameli split from AudacityProject.h
#include <wx/event.h> // to inherit
#include "ClientData.h" // to inherit
#include "toolbars/SelectionBarListener.h" // to inherit
#include "toolbars/SpectralSelectionBarListener.h" // to inherit
#include "import/ImportRaw.h" // defines TrackHolders
class wxTimer;
@ -34,44 +32,6 @@ namespace ProjectFileIORegistry{ struct Entry; }
using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >;
class ProjectSelectionManager final
: public ClientData::Base
, public SelectionBarListener
, public SpectralSelectionBarListener
{
public:
static ProjectSelectionManager &Get( AudacityProject &project );
static const ProjectSelectionManager &Get( const AudacityProject &project );
explicit ProjectSelectionManager( AudacityProject &project );
~ProjectSelectionManager() override;
// SelectionBarListener callback methods
double AS_GetRate() override;
void AS_SetRate(double rate) override;
int AS_GetSnapTo() override;
void AS_SetSnapTo(int snap) override;
const NumericFormatSymbol & AS_GetSelectionFormat() override;
void AS_SetSelectionFormat(const NumericFormatSymbol & format) override;
void AS_ModifySelection(double &start, double &end, bool done) override;
// SpectralSelectionBarListener callback methods
double SSBL_GetRate() const override;
const NumericFormatSymbol & SSBL_GetFrequencySelectionFormatName() override;
void SSBL_SetFrequencySelectionFormatName(
const NumericFormatSymbol & formatName) override;
const NumericFormatSymbol & SSBL_GetBandwidthSelectionFormatName() override;
void SSBL_SetBandwidthSelectionFormatName(
const NumericFormatSymbol & formatName) override;
void SSBL_ModifySpectralSelection(
double &bottom, double &top, bool done) override;
private:
bool SnapSelection();
AudacityProject &mProject;
};
///\brief Object associated with a project for high-level management of the
/// project's lifetime, including creation, destruction, opening from file,
/// importing, pushing undo states, and reverting to saved states

View File

@ -0,0 +1,249 @@
/**********************************************************************
Audacity: A Digital Audio Editor
ProjectSelectionManager.cpp
Paul Licameli split from ProjectManager.cpp
**********************************************************************/
#include "ProjectSelectionManager.h"
#include "Experimental.h"
#include "Project.h"
#include "ProjectHistory.h"
#include "ProjectSettings.h"
#include "ProjectWindow.h"
#include "Snap.h"
#include "TrackPanel.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
#include "toolbars/SelectionBar.h"
#include "toolbars/SpectralSelectionBar.h"
static AudacityProject::AttachedObjects::RegisteredFactory
sProjectSelectionManagerKey {
[]( AudacityProject &project ) {
return std::make_shared< ProjectSelectionManager >( project );
}
};
ProjectSelectionManager &ProjectSelectionManager::Get(
AudacityProject &project )
{
return project.AttachedObjects::Get< ProjectSelectionManager >(
sProjectSelectionManagerKey );
}
const ProjectSelectionManager &ProjectSelectionManager::Get(
const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
ProjectSelectionManager::ProjectSelectionManager( AudacityProject &project )
: mProject{ project }
{
}
ProjectSelectionManager::~ProjectSelectionManager() = default;
bool ProjectSelectionManager::SnapSelection()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &window = ProjectWindow::Get( project );
auto snapTo = settings.GetSnapTo();
if (snapTo != SNAP_OFF) {
auto &viewInfo = ViewInfo::Get( project );
SelectedRegion &selectedRegion = viewInfo.selectedRegion;
NumericConverter nc(NumericConverter::TIME,
settings.GetSelectionFormat(), 0, settings.GetRate());
const bool nearest = (snapTo == SNAP_NEAREST);
const double oldt0 = selectedRegion.t0();
const double oldt1 = selectedRegion.t1();
nc.ValueToControls(oldt0, nearest);
nc.ControlsToValue();
const double t0 = nc.GetValue();
nc.ValueToControls(oldt1, nearest);
nc.ControlsToValue();
const double t1 = nc.GetValue();
if (t0 != oldt0 || t1 != oldt1) {
selectedRegion.setTimes(t0, t1);
window.TP_DisplaySelection();
return true;
}
}
return false;
}
double ProjectSelectionManager::AS_GetRate()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetRate();
}
// Typically this came from the SelectionToolbar and does not need to
// be communicated back to it.
void ProjectSelectionManager::AS_SetRate(double rate)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetRate( rate );
}
int ProjectSelectionManager::AS_GetSnapTo()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetSnapTo();
}
void ProjectSelectionManager::AS_SetSnapTo(int snap)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &window = ProjectWindow::Get( project );
settings.SetSnapTo( snap );
// LLL: TODO - what should this be changed to???
// GetCommandManager()->Check(wxT("Snap"), mSnapTo);
gPrefs->Write(wxT("/SnapTo"), snap);
gPrefs->Flush();
SnapSelection();
window.RedrawProject();
SelectionBar::Get( project ).SetSnapTo(snap);
}
const NumericFormatSymbol & ProjectSelectionManager::AS_GetSelectionFormat()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetSelectionFormat();
}
void ProjectSelectionManager::AS_SetSelectionFormat(
const NumericFormatSymbol & format)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetSelectionFormat( format );
gPrefs->Write(wxT("/SelectionFormat"), format.Internal());
gPrefs->Flush();
if (SnapSelection())
TrackPanel::Get( project ).Refresh(false);
SelectionBar::Get( project ).SetSelectionFormat(format);
}
void ProjectSelectionManager::AS_ModifySelection(
double &start, double &end, bool done)
{
auto &project = mProject;
auto &history = ProjectHistory::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
viewInfo.selectedRegion.setTimes(start, end);
trackPanel.Refresh(false);
if (done) {
history.ModifyState(false);
}
}
double ProjectSelectionManager::SSBL_GetRate() const
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
auto &tracks = TrackList::Get( project );
// Return maximum of project rate and all track rates.
return std::max( settings.GetRate(),
tracks.Any<const WaveTrack>().max( &WaveTrack::GetRate ) );
}
const NumericFormatSymbol &
ProjectSelectionManager::SSBL_GetFrequencySelectionFormatName()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetFrequencySelectionFormatName();
}
void ProjectSelectionManager::SSBL_SetFrequencySelectionFormatName(
const NumericFormatSymbol & formatName)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetFrequencySelectionFormatName( formatName );
gPrefs->Write(wxT("/FrequencySelectionFormatName"),
formatName.Internal());
gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetFrequencySelectionFormatName(formatName);
#endif
}
const NumericFormatSymbol &
ProjectSelectionManager::SSBL_GetBandwidthSelectionFormatName()
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
return settings.GetBandwidthSelectionFormatName();
}
void ProjectSelectionManager::SSBL_SetBandwidthSelectionFormatName(
const NumericFormatSymbol & formatName)
{
auto &project = mProject;
auto &settings = ProjectSettings::Get( project );
settings.SetBandwidthSelectionFormatName( formatName );
gPrefs->Write(wxT("/BandwidthSelectionFormatName"),
formatName.Internal());
gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetBandwidthSelectionFormatName(formatName);
#endif
}
void ProjectSelectionManager::SSBL_ModifySpectralSelection(
double &bottom, double &top, bool done)
{
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
auto &project = mProject;
auto &history = ProjectHistory::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
double nyq = SSBL_GetRate() / 2.0;
if (bottom >= 0.0)
bottom = std::min(nyq, bottom);
if (top >= 0.0)
top = std::min(nyq, top);
viewInfo.selectedRegion.setFrequencies(bottom, top);
trackPanel.Refresh(false);
if (done) {
history.ModifyState(false);
}
#else
bottom; top; done;
#endif
}

View File

@ -0,0 +1,58 @@
/**********************************************************************
Audacity: A Digital Audio Editor
ProjectSelectionManager.cpp
Paul Licameli split from ProjectManager.cpp
**********************************************************************/
#ifndef __AUDACITY_PROJECT_SELECTION_MANAGER__
#define __AUDACITY_PROJECT_SELECTION_MANAGER__
#include "ClientData.h" // to inherit
#include "toolbars/SelectionBarListener.h" // to inherit
#include "toolbars/SpectralSelectionBarListener.h" // to inherit
class AudacityProject;
class ProjectSelectionManager final
: public ClientData::Base
, public SelectionBarListener
, public SpectralSelectionBarListener
{
public:
static ProjectSelectionManager &Get( AudacityProject &project );
static const ProjectSelectionManager &Get( const AudacityProject &project );
explicit ProjectSelectionManager( AudacityProject &project );
~ProjectSelectionManager() override;
// SelectionBarListener callback methods
double AS_GetRate() override;
void AS_SetRate(double rate) override;
int AS_GetSnapTo() override;
void AS_SetSnapTo(int snap) override;
const NumericFormatSymbol & AS_GetSelectionFormat() override;
void AS_SetSelectionFormat(const NumericFormatSymbol & format) override;
void AS_ModifySelection(double &start, double &end, bool done) override;
// SpectralSelectionBarListener callback methods
double SSBL_GetRate() const override;
const NumericFormatSymbol & SSBL_GetFrequencySelectionFormatName() override;
void SSBL_SetFrequencySelectionFormatName(
const NumericFormatSymbol & formatName) override;
const NumericFormatSymbol & SSBL_GetBandwidthSelectionFormatName() override;
void SSBL_SetBandwidthSelectionFormatName(
const NumericFormatSymbol & formatName) override;
void SSBL_ModifySpectralSelection(
double &bottom, double &top, bool done) override;
private:
bool SnapSelection();
AudacityProject &mProject;
};
#endif

View File

@ -35,7 +35,7 @@ explicitly code all three.
#include <wx/string.h>
#include <float.h>
#include "../ProjectManager.h"
#include "../ProjectSelectionManager.h"
#include "../TrackPanel.h"
#include "../Shuttle.h"
#include "../ShuttleGui.h"

View File

@ -16,7 +16,7 @@
#include "../Menus.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectManager.h"
#include "../ProjectSelectionManager.h"
#include "../ShuttleGui.h"
#include "../SplashDialog.h"
#include "../Theme.h"

View File

@ -9,7 +9,7 @@
#include "../Project.h"
#include "../ProjectAudioIO.h"
#include "../ProjectHistory.h"
#include "../ProjectManager.h"
#include "../ProjectSelectionManager.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../SelectionState.h"

View File

@ -229,6 +229,7 @@
<ClCompile Include="..\..\..\src\ProjectFSCK.cpp" />
<ClCompile Include="..\..\..\src\ProjectHistory.cpp" />
<ClCompile Include="..\..\..\src\ProjectManager.cpp" />
<ClCompile Include="..\..\..\src\ProjectSelectionManager.cpp" />
<ClCompile Include="..\..\..\src\ProjectSettings.cpp" />
<ClCompile Include="..\..\..\src\ProjectWindow.cpp" />
<ClCompile Include="..\..\..\src\RealFFTf.cpp" />
@ -664,6 +665,7 @@
<ClInclude Include="..\..\..\src\ProjectFSCK.h" />
<ClInclude Include="..\..\..\src\ProjectHistory.h" />
<ClInclude Include="..\..\..\src\ProjectManager.h" />
<ClInclude Include="..\..\..\src\ProjectSelectionManager.h" />
<ClInclude Include="..\..\..\src\ProjectSettings.h" />
<ClInclude Include="..\..\..\src\ProjectWindow.h" />
<ClInclude Include="..\..\..\src\RealFFTf.h" />

View File

@ -284,6 +284,9 @@
<ClCompile Include="..\..\..\src\ProjectManager.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ProjectSelectionManager.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ProjectSettings.cpp">
<Filter>src</Filter>
</ClCompile>
@ -1366,6 +1369,9 @@
<ClInclude Include="..\..\..\src\ProjectManager.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\ProjectSelectionManager.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\ProjectSettings.h">
<Filter>src</Filter>
</ClInclude>