1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

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.
This commit is contained in:
lllucius
2013-10-23 21:01:52 +00:00
parent 0e1614f41c
commit 71fde85bfe
13 changed files with 619 additions and 627 deletions

View File

@@ -30,25 +30,18 @@ SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
// Grab time-snapping prefs (unless otherwise requested)
mSnapToTime = false;
TimeTextCtrl *ttc = NULL;
// TODO: Switch over from using TimeTextCtrl to TimeConverter.
// This will prevent an annoying tiny toolbar appearing in top left
// every time we click the mouse left button. It's the time text
// ctrl.
//TimeConverter *pTc=NULL;
if (gPrefs->Read(wxT("/SnapTo"), 0L) != 0L && !noTimeSnap)
{
// Look up the format string
AudacityProject *p = GetActiveProject();
wxASSERT(p);
if (p) {
mConverter.SetSampleRate(p->GetRate());
mSnapToTime = true;
ttc = new TimeTextCtrl(p, wxID_ANY, wxT(""), 0.0, p->GetRate());
wxString formatName;
gPrefs->Read(wxT("/SelectionFormat"), &formatName);
mFormat = ttc->GetBuiltinFormat(formatName);
ttc->SetFormatString(mFormat);
mConverter.SetFormatString(mConverter.GetBuiltinFormat(formatName));
}
}
@@ -73,9 +66,9 @@ SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
LabelTrack *labelTrack = (LabelTrack *)track;
for(i = 0; i < labelTrack->GetNumLabels(); i++) {
const LabelStruct *label = labelTrack->GetLabel(i);
CondListAdd(label->t, labelTrack, ttc);
CondListAdd(label->t, labelTrack);
if (label->t1 != label->t) {
CondListAdd(label->t1, labelTrack, ttc);
CondListAdd(label->t1, labelTrack);
}
}
}
@@ -94,30 +87,26 @@ SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
if (skip)
continue;
}
CondListAdd(clip->GetStartTime(), waveTrack, ttc);
CondListAdd(clip->GetEndTime(), waveTrack, ttc);
CondListAdd(clip->GetStartTime(), waveTrack);
CondListAdd(clip->GetEndTime(), waveTrack);
}
}
#ifdef USE_MIDI
else if (track->GetKind() == Track::Note) {
CondListAdd(track->GetStartTime(), track, ttc);
CondListAdd(track->GetEndTime(), track, ttc);
CondListAdd(track->GetStartTime(), track);
CondListAdd(track->GetEndTime(), track);
}
#endif
track = iter.Next();
}
if (ttc)
delete ttc;
}
// Adds to mSnapPoints, filtering by ttc if it's not NULL
void SnapManager::CondListAdd(double t, Track *tr, TimeTextCtrl *ttc)
// Adds to mSnapPoints, filtering by TimeConverter
void SnapManager::CondListAdd(double t, Track *tr)
{
if (ttc)
ttc->SetTimeValue(t);
mConverter.SetTimeValue(t);
if (!ttc || ttc->GetTimeValue() == t)
if (mConverter.GetTimeValue() == t)
mSnapPoints->Add(new SnapPoint(t, tr));
}
@@ -260,27 +249,9 @@ bool SnapManager::Snap(Track *currentTrack,
}
else {
// Snap time to the grid
AudacityProject *p = GetActiveProject();
#if 0
// Old code for snapping.
// This created a new ctrl for every tiny drag.
TimeTextCtrl ttc(p, wxID_ANY, wxT(""), 0.0, p->GetRate());
ttc.SetFormatString(mFormat);
ttc.SetTimeValue(t);
*out_t = ttc.GetTimeValue();
#else
// Replacement code. It's still inefficient, since we
// repeatedly parse the format, but it now doesn't
// create a new ctrl too.
// TODO: Move Tc into being a member variable of
// SnapManager. Then we won't be repeatedly
// parsing the format string.
TimeConverter Tc;
Tc.mSampleRate = p->GetRate();
Tc.ParseFormatString( mFormat );
Tc.ValueToControls( t );
*out_t = Tc.ControlsToValue();
#endif
mConverter.ValueToControls(t, false);
mConverter.ControlsToValue();
*out_t = mConverter.GetTimeValue();
*snappedTime = true;
}
}