1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-19 14:17:41 +02:00
audacity/src/Snap.h
lllucius 71fde85bfe Bug 115 - Snap-to causes spurious 'toolbar' to appear momentarily at start of dragging.
Completes James' TimeConverter work

This completes the work that James started.  It moves most of the non-GUI
related processing from TimeTextCtrl to James' TimeConverter class.

Other changes include:

1)  TimeTextCtrl now expects the format name instead of the format string to be
passed when creating a new instance.  I found that almost all cases created the
instance with a blank format string and then set the string after creation.

2)  To simplify maintenance and prevent a possible discrepancy between the two,
Increase() and Decrease() were merged into a single routine.

As a result:

1)  All cases where a TimeTextCtrl was being used to extract information and
not actually display a control have been changed to use TimeConverter instead.

2)  All cases where TimeTextCtrl was being created with an empty format and
then immediately followed by something like this:

    tt.SetFormatString(tt.GetBuiltinFormat(c->GetFormat()))

    have been changed to pass the format name instead of the format string when
creating the TimeTextCtrl instance.
2013-10-23 21:01:52 +00:00

76 lines
1.8 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
Snap.h
Dominic Mazzoni
Create one of these objects at the beginning of a click/drag.
Then, given a time corresponding to the current mouse cursor
position, it will tell you the closest place to snap to.
**********************************************************************/
#ifndef __AUDACITY_SNAP__
#define __AUDACITY_SNAP__
#include <wx/defs.h>
#include <wx/dynarray.h>
#include "Track.h"
#include "widgets/TimeTextCtrl.h"
class TrackClipArray;
class SnapPoint {
public:
SnapPoint(double t, Track *track) {
this->t = t;
this->track = track;
}
double t;
Track *track;
};
WX_DEFINE_SORTED_ARRAY(SnapPoint *, SnapPointArray);
class SnapManager {
public:
SnapManager(TrackList *tracks, TrackClipArray *exclusions,
double zoom, int pixelTolerance, bool noTimeSnap = false);
~SnapManager();
// The track may be NULL.
// Returns true if the output time is not the same as the input.
// Pass rightEdge=true if this is the right edge of a selection,
// and false if it's the left edge.
bool Snap(Track *currentTrack,
double t,
bool rightEdge,
double *out_t,
bool *snappedPoint,
bool *snappedTime);
private:
void CondListAdd(double t, Track *tr);
double Get(int index);
double Diff(double t, int index);
int Find(double t, int i0, int i1);
int Find(double t);
bool SnapToPoints(Track *currentTrack, double t, bool rightEdge,
double *out_t);
double mEpsilon;
double mTolerance;
double mZoom;
SnapPointArray *mSnapPoints;
// Info for snap-to-time
TimeConverter mConverter;
bool mSnapToTime;
};
#endif