Skip to content

Commit

Permalink
Don't make assumptions about types of timer interval constants ...
Browse files Browse the repository at this point in the history
... where they must mix with un-typed numbers, including calls to wxTimer
methods.  Change the name of one so it doesn't mention the period.

Do not use duration_cast, but use other conversions that check for non-lossiness
at compile time.
  • Loading branch information
Paul-Licameli committed Jan 11, 2022
1 parent 0b9e8d8 commit c814e58
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ScrubState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ bool ScrubbingPlaybackPolicy::Done(
std::chrono::milliseconds
ScrubbingPlaybackPolicy::SleepInterval( PlaybackSchedule & )
{
return ScrubPollInterval_ms;
return ScrubPollInterval;
}

PlaybackSlice ScrubbingPlaybackPolicy::GetPlaybackSlice(
Expand Down
2 changes: 1 addition & 1 deletion src/ScrubState.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ struct ScrubState
static double GetLastScrubTime();
};

static constexpr auto ScrubPollInterval_ms = std::chrono::milliseconds{50};
static constexpr auto ScrubPollInterval = std::chrono::milliseconds{50};

#endif
4 changes: 2 additions & 2 deletions src/TrackPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void TrackPanel::OnIdle(wxIdleEvent& event)
// The window must be ready when the timer fires (#1401)
if (IsShownOnScreen())
{
mTimer.Start(kTimerInterval.count(), FALSE);
mTimer.Start(std::chrono::milliseconds{kTimerInterval}.count(), FALSE);

// Timer is started, we don't need the event anymore
GetProjectFrame( *GetProject() ).Unbind(wxEVT_IDLE,
Expand Down Expand Up @@ -727,7 +727,7 @@ void TrackPanel::OnMouseEvent(wxMouseEvent & event)
// When this timer fires, we call TrackPanel::OnTimer and
// possibly update the screen for offscreen scrolling.
mTimer.Stop();
mTimer.Start(kTimerInterval.count(), FALSE);
mTimer.Start(std::chrono::milliseconds{kTimerInterval}.count(), FALSE);
}


Expand Down
4 changes: 3 additions & 1 deletion src/tracks/ui/PlayIndicatorOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)

// Use a small tolerance to avoid flicker of play head pinned all the way
// left or right
const auto tolerance = pinned ? 1.5 * kTimerInterval.count() / 1000.0 : 0;
const auto tolerance = pinned
? 1.5 * std::chrono::duration<double>{kTimerInterval}.count()
: 0;
bool onScreen = playPos >= 0.0 &&
between_incexc(viewInfo.h - tolerance,
playPos,
Expand Down
18 changes: 10 additions & 8 deletions src/tracks/ui/Scrubbing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ enum {
ScrubSpeedStepsPerOctave = 4,
#endif

kOneSecondCountdown = 1000 / ScrubPollInterval_ms.count(),
kOneSecondCountdown =
1000 / std::chrono::milliseconds{ScrubPollInterval}.count(),
};

static constexpr PlaybackPolicy::Duration MinStutter{0.2};
Expand Down Expand Up @@ -153,7 +154,7 @@ auto Scrubber::ScrubPollerThread::Entry() -> ExitCode
{
while( !TestDestroy() )
{
std::this_thread::sleep_for(ScrubPollInterval_ms);
std::this_thread::sleep_for(ScrubPollInterval);
mScrubber.ContinueScrubbingPoll();
}
return 0;
Expand Down Expand Up @@ -417,12 +418,12 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
// execute too much else
options.playbackStreamPrimer = [this](){
ContinueScrubbingPoll();
return ScrubPollInterval_ms;
return ScrubPollInterval;
};
#endif
options.playNonWaveTracks = false;
options.envelope = nullptr;
mOptions.delay = ScrubPollInterval_ms;
mOptions.delay = ScrubPollInterval;
mOptions.isKeyboardScrubbing = false;
mOptions.initSpeed = 0;
mOptions.minSpeed = 0.0;
Expand Down Expand Up @@ -518,7 +519,7 @@ bool Scrubber::StartKeyboardScrubbing(double time0, bool backwards)
// execute too much else
options.playbackStreamPrimer = [this]() {
ContinueScrubbingPoll();
return ScrubPollInterval_ms;
return ScrubPollInterval;
};
#endif

Expand All @@ -527,7 +528,7 @@ bool Scrubber::StartKeyboardScrubbing(double time0, bool backwards)

// delay and minStutterTime are used in AudioIO::AllocateBuffers() for setting the
// values of mPlaybackQueueMinimum and mPlaybackSamplesToCopy respectively.
mOptions.delay = ScrubPollInterval_ms;
mOptions.delay = ScrubPollInterval;
mOptions.minStutterTime = mOptions.delay;

mOptions.initSpeed = GetKeyboardScrubbingSpeed();
Expand Down Expand Up @@ -728,8 +729,9 @@ void Scrubber::StartPolling()
mpThread->Create(4096);
mpThread->Run();
#endif

mPoller->Start(ScrubPollInterval_ms.count() * 0.9);

mPoller->Start( 0.9 *
std::chrono::duration<double, std::milli>{ScrubPollInterval}.count());
}

void Scrubber::StopPolling()
Expand Down

0 comments on commit c814e58

Please sign in to comment.