Move class ZoomInfo to separate files

This commit is contained in:
Paul Licameli 2019-06-19 10:30:21 -04:00
parent f7dfc34de9
commit a99b746520
11 changed files with 306 additions and 257 deletions

View File

@ -272,6 +272,8 @@ src/WaveTrack.h
src/WaveTrackLocation.h
src/WrappedType.cpp
src/WrappedType.h
src/ZoomInfo.cpp
src/ZoomInfo.h
src/blockfile/LegacyAliasBlockFile.cpp
src/blockfile/LegacyAliasBlockFile.h
src/blockfile/LegacyBlockFile.cpp

View File

@ -1290,6 +1290,7 @@
5EBD35861F78D37A0084D13F /* pt_PT.po in Sources */ = {isa = PBXBuildFile; fileRef = 5EBD35851F78D37A0084D13F /* pt_PT.po */; };
5EC4257222B92383005E8AB5 /* CommonTrackControls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EC4256E22B92383005E8AB5 /* CommonTrackControls.cpp */; };
5EC4257322B92383005E8AB5 /* CommonTrackView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EC4257022B92383005E8AB5 /* CommonTrackView.cpp */; };
5EC4257922BA7CF2005E8AB5 /* ZoomInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EC4257722BA7CF2005E8AB5 /* ZoomInfo.cpp */; };
5EC7ED061E101C5C0052CAE2 /* NotYetAvailableException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EC7ED041E101C5C0052CAE2 /* NotYetAvailableException.cpp */; };
5ECF728722871A4F007F2A35 /* ShuttleGetDefinition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5ECF728522871A4F007F2A35 /* ShuttleGetDefinition.cpp */; };
5ECF728A22887B3B007F2A35 /* MissingAliasFileDialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5ECF728822887B3B007F2A35 /* MissingAliasFileDialog.cpp */; };
@ -3339,6 +3340,8 @@
5EC4256F22B92383005E8AB5 /* CommonTrackControls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonTrackControls.h; sourceTree = "<group>"; };
5EC4257022B92383005E8AB5 /* CommonTrackView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommonTrackView.cpp; sourceTree = "<group>"; };
5EC4257122B92383005E8AB5 /* CommonTrackView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonTrackView.h; sourceTree = "<group>"; };
5EC4257722BA7CF2005E8AB5 /* ZoomInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ZoomInfo.cpp; sourceTree = "<group>"; };
5EC4257822BA7CF2005E8AB5 /* ZoomInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZoomInfo.h; sourceTree = "<group>"; };
5EC7ED041E101C5C0052CAE2 /* NotYetAvailableException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotYetAvailableException.cpp; sourceTree = "<group>"; };
5EC7ED051E101C5C0052CAE2 /* NotYetAvailableException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotYetAvailableException.h; sourceTree = "<group>"; };
5ECCE7651DE49834009900E9 /* AudacityException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudacityException.h; sourceTree = "<group>"; };
@ -4455,6 +4458,7 @@
1790B0F909883BFD008A330A /* WaveClip.cpp */,
1790B0FB09883BFD008A330A /* WaveTrack.cpp */,
28FC1AF90A47762C00A188AE /* WrappedType.cpp */,
5EC4257722BA7CF2005E8AB5 /* ZoomInfo.cpp */,
1790AFC809883BFD008A330A /* AboutDialog.h */,
1790AFCA09883BFD008A330A /* AColor.h */,
5E08C7382180D460004079AE /* AdornedRulerPanel.h */,
@ -4594,6 +4598,7 @@
2844163A1B82D6BC0000574D /* WaveTrackLocation.h */,
28FC1AFA0A47762C00A188AE /* WrappedType.h */,
5ED18DB71CC290AB00FAFE95 /* wxFileNameWrapper.h */,
5EC4257822BA7CF2005E8AB5 /* ZoomInfo.h */,
5EFEAD9F2273382D0077DFF6 /* AudacityApp.mm */,
1790AFDC09883BFD008A330A /* blockfile */,
174D9025098C78AF00D5909F /* commands */,
@ -8399,6 +8404,7 @@
1790B15F09883BFD008A330A /* ExportOGG.cpp in Sources */,
1790B16009883BFD008A330A /* ExportPCM.cpp in Sources */,
5E7396691DAFDB5600BA0A4D /* LabelDefaultClickHandle.cpp in Sources */,
5EC4257922BA7CF2005E8AB5 /* ZoomInfo.cpp in Sources */,
1790B16109883BFD008A330A /* FFT.cpp in Sources */,
1790B16209883BFD008A330A /* FileFormats.cpp in Sources */,
1790B16309883BFD008A330A /* FreqWindow.cpp in Sources */,

View File

@ -318,6 +318,8 @@ audacity_SOURCES = \
WaveTrackLocation.h \
WrappedType.cpp \
WrappedType.h \
ZoomInfo.cpp \
ZoomInfo.h \
wxFileNameWrapper.h \
commands/AppCommandEvent.cpp \
commands/AppCommandEvent.h \

View File

@ -350,8 +350,8 @@ am__audacity_SOURCES_DIST = BlockFile.cpp BlockFile.h DirManager.cpp \
UndoManager.cpp UndoManager.h UserException.cpp \
UserException.h ViewInfo.cpp ViewInfo.h VoiceKey.cpp \
VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp WaveTrack.h \
WaveTrackLocation.h WrappedType.cpp WrappedType.h \
wxFileNameWrapper.h commands/AppCommandEvent.cpp \
WaveTrackLocation.h WrappedType.cpp WrappedType.h ZoomInfo.cpp \
ZoomInfo.h wxFileNameWrapper.h commands/AppCommandEvent.cpp \
commands/AppCommandEvent.h commands/AudacityCommand.cpp \
commands/AudacityCommand.h commands/BatchEvalCommand.cpp \
commands/BatchEvalCommand.h commands/Command.cpp \
@ -708,6 +708,7 @@ am_audacity_OBJECTS = $(am__objects_1) audacity-AboutDialog.$(OBJEXT) \
audacity-UserException.$(OBJEXT) audacity-ViewInfo.$(OBJEXT) \
audacity-VoiceKey.$(OBJEXT) audacity-WaveClip.$(OBJEXT) \
audacity-WaveTrack.$(OBJEXT) audacity-WrappedType.$(OBJEXT) \
audacity-ZoomInfo.$(OBJEXT) \
commands/audacity-AppCommandEvent.$(OBJEXT) \
commands/audacity-AudacityCommand.$(OBJEXT) \
commands/audacity-BatchEvalCommand.$(OBJEXT) \
@ -1439,8 +1440,8 @@ audacity_SOURCES = $(libaudacity_la_SOURCES) AboutDialog.cpp \
UndoManager.cpp UndoManager.h UserException.cpp \
UserException.h ViewInfo.cpp ViewInfo.h VoiceKey.cpp \
VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp WaveTrack.h \
WaveTrackLocation.h WrappedType.cpp WrappedType.h \
wxFileNameWrapper.h commands/AppCommandEvent.cpp \
WaveTrackLocation.h WrappedType.cpp WrappedType.h ZoomInfo.cpp \
ZoomInfo.h wxFileNameWrapper.h commands/AppCommandEvent.cpp \
commands/AppCommandEvent.h commands/AudacityCommand.cpp \
commands/AudacityCommand.h commands/BatchEvalCommand.cpp \
commands/BatchEvalCommand.h commands/Command.cpp \
@ -2653,6 +2654,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-WaveClip.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-WaveTrack.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-WrappedType.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audacity-ZoomInfo.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaudacity_la-BlockFile.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaudacity_la-DirManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaudacity_la-Dither.Plo@am__quote@
@ -4720,6 +4722,20 @@ audacity-WrappedType.obj: WrappedType.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-WrappedType.obj `if test -f 'WrappedType.cpp'; then $(CYGPATH_W) 'WrappedType.cpp'; else $(CYGPATH_W) '$(srcdir)/WrappedType.cpp'; fi`
audacity-ZoomInfo.o: ZoomInfo.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT audacity-ZoomInfo.o -MD -MP -MF $(DEPDIR)/audacity-ZoomInfo.Tpo -c -o audacity-ZoomInfo.o `test -f 'ZoomInfo.cpp' || echo '$(srcdir)/'`ZoomInfo.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/audacity-ZoomInfo.Tpo $(DEPDIR)/audacity-ZoomInfo.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ZoomInfo.cpp' object='audacity-ZoomInfo.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-ZoomInfo.o `test -f 'ZoomInfo.cpp' || echo '$(srcdir)/'`ZoomInfo.cpp
audacity-ZoomInfo.obj: ZoomInfo.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT audacity-ZoomInfo.obj -MD -MP -MF $(DEPDIR)/audacity-ZoomInfo.Tpo -c -o audacity-ZoomInfo.obj `if test -f 'ZoomInfo.cpp'; then $(CYGPATH_W) 'ZoomInfo.cpp'; else $(CYGPATH_W) '$(srcdir)/ZoomInfo.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/audacity-ZoomInfo.Tpo $(DEPDIR)/audacity-ZoomInfo.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ZoomInfo.cpp' object='audacity-ZoomInfo.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-ZoomInfo.obj `if test -f 'ZoomInfo.cpp'; then $(CYGPATH_W) 'ZoomInfo.cpp'; else $(CYGPATH_W) '$(srcdir)/ZoomInfo.cpp'; fi`
commands/audacity-AppCommandEvent.o: commands/AppCommandEvent.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(audacity_CPPFLAGS) $(CPPFLAGS) $(audacity_CXXFLAGS) $(CXXFLAGS) -MT commands/audacity-AppCommandEvent.o -MD -MP -MF commands/$(DEPDIR)/audacity-AppCommandEvent.Tpo -c -o commands/audacity-AppCommandEvent.o `test -f 'commands/AppCommandEvent.cpp' || echo '$(srcdir)/'`commands/AppCommandEvent.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) commands/$(DEPDIR)/audacity-AppCommandEvent.Tpo commands/$(DEPDIR)/audacity-AppCommandEvent.Po

View File

@ -15,133 +15,12 @@ Paul Licameli
#include <algorithm>
#include "AudioIOBase.h"
#include "prefs/GUISettings.h"
#include "Prefs.h"
#include "Project.h"
#include "xml/XMLWriter.h"
#include "prefs/TracksBehaviorsPrefs.h"
#include "xml/XMLWriter.h"
namespace {
static const double gMaxZoom = 6000000;
static const double gMinZoom = 0.001;
}
ZoomInfo &ZoomInfo::Get( AudacityProject &project )
{
return ViewInfo::Get( project );
}
const ZoomInfo &ZoomInfo::Get( const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
: vpos(0)
, h(start)
, zoom(pixelsPerSecond)
{
UpdatePrefs();
}
ZoomInfo::~ZoomInfo()
{
}
void ZoomInfo::UpdatePrefs()
{
dBr = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
}
/// Converts a position (mouse X coordinate) to
/// project time, in seconds. Needs the left edge of
/// the track as an additional parameter.
double ZoomInfo::PositionToTime(wxInt64 position,
wxInt64 origin
, bool // ignoreFisheye
) const
{
return h + (position - origin) / zoom;
}
/// STM: Converts a project time to screen x position.
wxInt64 ZoomInfo::TimeToPosition(double projectTime,
wxInt64 origin
, bool // ignoreFisheye
) const
{
double t = 0.5 + zoom * (projectTime - h) + origin ;
if( t < wxINT64_MIN )
return wxINT64_MIN;
if( t > wxINT64_MAX )
return wxINT64_MAX;
t = floor( t );
return t;
}
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
{
return timeRange * zoom;
}
bool ZoomInfo::ZoomInAvailable() const
{
return zoom < gMaxZoom;
}
bool ZoomInfo::ZoomOutAvailable() const
{
return zoom > gMinZoom;
}
double ZoomInfo::GetZoom( ) const { return zoom;};
double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
void ZoomInfo::SetZoom(double pixelsPerSecond)
{
zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
// DA: Avoids stuck in snap-to
#ifdef EXPERIMENTAL_DA
// Disable snapping if user zooms in a long way.
// Helps stop users be trapped in snap-to.
// The level chosen is in sample viewing range with samples
// still quite close together.
if( zoom > (gMaxZoom * 0.06 ))
{
AudacityProject * project = GetActiveProject();
if( project )
project->OnSnapToOff();
}
#endif
}
void ZoomInfo::ZoomBy(double multiplier)
{
SetZoom(zoom * multiplier);
}
void ZoomInfo::FindIntervals
(double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
{
results.clear();
results.reserve(2);
const wxInt64 rightmost(origin + (0.5 + width));
wxASSERT(origin <= rightmost);
{
results.push_back(Interval(origin, zoom, false));
}
if (origin < rightmost)
results.push_back(Interval(rightmost, 0, false));
wxASSERT(!results.empty() && results[0].position == origin);
}
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject &project ) {
auto result =

View File

@ -14,20 +14,11 @@
#include <utility>
#include <vector>
#include <wx/event.h> // inherit wxEvtHandler
#include "ClientData.h"
#include "SelectedRegion.h"
#include "MemoryX.h"
#include "Prefs.h"
#include "ZoomInfo.h" // to inherit
#ifdef __GNUC__
#define CONST
#else
#define CONST const
#endif
class AudacityProject;
// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
enum : int {
kLeftInset = 4,
@ -51,126 +42,6 @@ enum : int {
kTrackInfoSliderExtra = 5,
};
// The subset of ViewInfo information (other than selection)
// that is sufficient for purposes of TrackArtist,
// and for computing conversions between track times and pixel positions.
class AUDACITY_DLL_API ZoomInfo /* not final */
// Note that ViewInfo inherits from ZoomInfo but there are no virtual functions.
// That's okay if we pass always by reference and never copy, suffering "slicing."
: public ClientData::Base
, protected PrefsListener
{
public:
static ZoomInfo &Get( AudacityProject &project );
static const ZoomInfo &Get( const AudacityProject &project );
ZoomInfo(double start, double pixelsPerSecond);
~ZoomInfo();
// Be sure we don't slice
ZoomInfo(const ZoomInfo&) PROHIBITED;
ZoomInfo& operator= (const ZoomInfo&) PROHIBITED;
void UpdatePrefs() override;
int vpos; // vertical scroll pos
double h; // h pos in secs
protected:
double zoom; // pixels per second
public:
float dBr; // decibel scale range
// do NOT use this once to convert a pixel width to a duration!
// Instead, call twice to convert start and end times,
// and take the difference.
// origin specifies the pixel corresponding to time h
double PositionToTime(wxInt64 position,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// do NOT use this once to convert a duration to a pixel width!
// Instead, call twice to convert start and end positions,
// and take the difference.
// origin specifies the pixel corresponding to time h
wxInt64 TimeToPosition(double time,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double TimeRangeToPixelWidth(double timeRange) const;
double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye = false) const
{
return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
}
bool ZoomInAvailable() const;
bool ZoomOutAvailable() const;
static double GetDefaultZoom()
{ return 44100.0 / 512.0; }
// Limits zoom to certain bounds
void SetZoom(double pixelsPerSecond);
// This function should not be used to convert positions to times and back
// Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
double GetZoom() const;
static double GetMaxZoom( );
static double GetMinZoom( );
// Limits zoom to certain bounds
// multipliers above 1.0 zoom in, below out
void ZoomBy(double multiplier);
struct Interval {
CONST wxInt64 position; CONST double averageZoom; CONST bool inFisheye;
Interval(wxInt64 p, double z, bool i)
: position(p), averageZoom(z), inFisheye(i) {}
};
typedef std::vector<Interval> Intervals;
// Find an increasing sequence of pixel positions. Each is the start
// of an interval, or is the end position.
// Each of the disjoint intervals should be drawn
// separately.
// It is guaranteed that there is at least one entry and the position of the
// first entry equals origin.
// @param origin specifies the pixel position corresponding to time ViewInfo::h.
void FindIntervals
(double rate, Intervals &results, wxInt64 width, wxInt64 origin = 0) const;
enum FisheyeState {
HIDDEN,
PINNED,
NUM_STATES,
};
FisheyeState GetFisheyeState() const
{ return HIDDEN; } // stub
// Return true if the mouse position is anywhere in the fisheye
// origin specifies the pixel corresponding to time h
bool InFisheye(wxInt64 /*position*/, wxInt64 WXUNUSED(origin = 0)) const
{return false;} // stub
// These accessors ignore the fisheye hiding state.
// Inclusive:
wxInt64 GetFisheyeLeftBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
// Exclusive:
wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
};
class PlayRegion
{
public:

123
src/ZoomInfo.cpp Normal file
View File

@ -0,0 +1,123 @@
/**********************************************************************
Audacity: A Digital Audio Editor
ZoomInfo.cpp
Paul Licameli split from ViewInfo.cpp
**********************************************************************/
#include "ZoomInfo.h"
#include "prefs/GUISettings.h"
namespace {
static const double gMaxZoom = 6000000;
static const double gMinZoom = 0.001;
}
ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
: vpos(0)
, h(start)
, zoom(pixelsPerSecond)
{
UpdatePrefs();
}
ZoomInfo::~ZoomInfo()
{
}
void ZoomInfo::UpdatePrefs()
{
dBr = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
}
/// Converts a position (mouse X coordinate) to
/// project time, in seconds. Needs the left edge of
/// the track as an additional parameter.
double ZoomInfo::PositionToTime(wxInt64 position,
wxInt64 origin
, bool // ignoreFisheye
) const
{
return h + (position - origin) / zoom;
}
/// STM: Converts a project time to screen x position.
wxInt64 ZoomInfo::TimeToPosition(double projectTime,
wxInt64 origin
, bool // ignoreFisheye
) const
{
double t = 0.5 + zoom * (projectTime - h) + origin ;
if( t < wxINT64_MIN )
return wxINT64_MIN;
if( t > wxINT64_MAX )
return wxINT64_MAX;
t = floor( t );
return t;
}
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
{
return timeRange * zoom;
}
bool ZoomInfo::ZoomInAvailable() const
{
return zoom < gMaxZoom;
}
bool ZoomInfo::ZoomOutAvailable() const
{
return zoom > gMinZoom;
}
double ZoomInfo::GetZoom( ) const { return zoom;};
double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
void ZoomInfo::SetZoom(double pixelsPerSecond)
{
zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
// DA: Avoids stuck in snap-to
#ifdef EXPERIMENTAL_DA
// Disable snapping if user zooms in a long way.
// Helps stop users be trapped in snap-to.
// The level chosen is in sample viewing range with samples
// still quite close together.
if( zoom > (gMaxZoom * 0.06 ))
{
AudacityProject * project = GetActiveProject();
if( project )
project->OnSnapToOff();
}
#endif
}
void ZoomInfo::ZoomBy(double multiplier)
{
SetZoom(zoom * multiplier);
}
void ZoomInfo::FindIntervals
(double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
{
results.clear();
results.reserve(2);
const wxInt64 rightmost(origin + (0.5 + width));
wxASSERT(origin <= rightmost);
{
results.push_back(Interval(origin, zoom, false));
}
if (origin < rightmost)
results.push_back(Interval(rightmost, 0, false));
wxASSERT(!results.empty() && results[0].position == origin);
}

142
src/ZoomInfo.h Normal file
View File

@ -0,0 +1,142 @@
/**********************************************************************
Audacity: A Digital Audio Editor
ZoomInfo.h
Paul Licameli split from ViewInfo.h
**********************************************************************/
#ifndef __AUDACITY_ZOOM_INFO__
#define __AUDACITY_ZOOM_INFO__
#include "ClientData.h" // to inherit
#include "Prefs.h" // to inherit
#ifdef __GNUC__
#define CONST
#else
#define CONST const
#endif
class AudacityProject;
// The subset of ViewInfo information (other than selection)
// that is sufficient for purposes of TrackArtist,
// and for computing conversions between track times and pixel positions.
class AUDACITY_DLL_API ZoomInfo /* not final */
// Note that ViewInfo inherits from ZoomInfo but there are no virtual functions.
// That's okay if we pass always by reference and never copy, suffering "slicing."
: public ClientData::Base
, protected PrefsListener
{
public:
ZoomInfo(double start, double pixelsPerSecond);
~ZoomInfo();
// Be sure we don't slice
ZoomInfo(const ZoomInfo&) PROHIBITED;
ZoomInfo& operator= (const ZoomInfo&) PROHIBITED;
void UpdatePrefs() override;
int vpos; // vertical scroll pos
double h; // h pos in secs
protected:
double zoom; // pixels per second
public:
float dBr; // decibel scale range
// do NOT use this once to convert a pixel width to a duration!
// Instead, call twice to convert start and end times,
// and take the difference.
// origin specifies the pixel corresponding to time h
double PositionToTime(wxInt64 position,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// do NOT use this once to convert a duration to a pixel width!
// Instead, call twice to convert start and end positions,
// and take the difference.
// origin specifies the pixel corresponding to time h
wxInt64 TimeToPosition(double time,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double TimeRangeToPixelWidth(double timeRange) const;
double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye = false) const
{
return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
}
bool ZoomInAvailable() const;
bool ZoomOutAvailable() const;
static double GetDefaultZoom()
{ return 44100.0 / 512.0; }
// Limits zoom to certain bounds
void SetZoom(double pixelsPerSecond);
// This function should not be used to convert positions to times and back
// Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
double GetZoom() const;
static double GetMaxZoom( );
static double GetMinZoom( );
// Limits zoom to certain bounds
// multipliers above 1.0 zoom in, below out
void ZoomBy(double multiplier);
struct Interval {
CONST wxInt64 position; CONST double averageZoom; CONST bool inFisheye;
Interval(wxInt64 p, double z, bool i)
: position(p), averageZoom(z), inFisheye(i) {}
};
typedef std::vector<Interval> Intervals;
// Find an increasing sequence of pixel positions. Each is the start
// of an interval, or is the end position.
// Each of the disjoint intervals should be drawn
// separately.
// It is guaranteed that there is at least one entry and the position of the
// first entry equals origin.
// @param origin specifies the pixel position corresponding to time ViewInfo::h.
void FindIntervals
(double rate, Intervals &results, wxInt64 width, wxInt64 origin = 0) const;
enum FisheyeState {
HIDDEN,
PINNED,
NUM_STATES,
};
FisheyeState GetFisheyeState() const
{ return HIDDEN; } // stub
// Return true if the mouse position is anywhere in the fisheye
// origin specifies the pixel corresponding to time h
bool InFisheye(wxInt64 /*position*/, wxInt64 WXUNUSED(origin = 0)) const
{return false;} // stub
// These accessors ignore the fisheye hiding state.
// Inclusive:
wxInt64 GetFisheyeLeftBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
// Exclusive:
wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
};
#endif

View File

@ -61,7 +61,7 @@ std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
}
else {
mCursorTime = selection.t0();
mNewCursorX = ZoomInfo::Get( *mProject ).TimeToPosition(
mNewCursorX = ViewInfo::Get( *mProject ).TimeToPosition(
mCursorTime, TrackPanel::Get( *mProject ).GetLeftOffset());
}
@ -87,7 +87,7 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
if (mLastCursorX == -1)
return;
const auto &viewInfo = ZoomInfo::Get( *mProject );
const auto &viewInfo = ViewInfo::Get( *mProject );
auto &trackPanel = TrackPanel::Get( *mProject );
const bool

View File

@ -321,6 +321,7 @@
<ClCompile Include="..\..\..\src\VoiceKey.cpp" />
<ClCompile Include="..\..\..\src\WaveClip.cpp" />
<ClCompile Include="..\..\..\src\WaveTrack.cpp" />
<ClCompile Include="..\..\..\src\ZoomInfo.cpp" />
<ClCompile Include="..\..\..\src\widgets\BackedPanel.cpp" />
<ClCompile Include="..\..\..\src\widgets\HelpSystem.cpp" />
<ClCompile Include="..\..\..\src\widgets\NumericTextCtrl.cpp" />
@ -714,6 +715,7 @@
<ClInclude Include="..\..\..\src\WaveClip.h" />
<ClInclude Include="..\..\..\src\WaveTrack.h" />
<ClInclude Include="..\..\..\src\WrappedType.h" />
<ClInclude Include="..\..\..\src\ZoomInfo.h" />
<ClInclude Include="..\..\..\src\effects\Amplify.h" />
<ClInclude Include="..\..\..\src\effects\AutoDuck.h" />
<ClInclude Include="..\..\..\src\effects\BassTreble.h" />

View File

@ -383,6 +383,9 @@
<ClCompile Include="..\..\..\src\WrappedType.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ZoomInfo.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\effects\Amplify.cpp">
<Filter>src\effects</Filter>
</ClCompile>
@ -1495,6 +1498,9 @@
<ClInclude Include="..\..\..\src\WrappedType.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\ZoomInfo.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\effects\Amplify.h">
<Filter>src\effects</Filter>
</ClInclude>