diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-09-14 10:29:00 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-09-16 11:22:16 +1000 |
commit | a88b2da6a90b1d6f3004333a89761d312b02cf37 (patch) | |
tree | d8537fa4d18ee6606904550913d6f54abbd03a45 /libs/pbd/windows_timer_utils.cc | |
parent | 62f75b8b162b479717bb7f9d9a8b5b65cd014512 (diff) |
Fix PBD::MMTIMER::reset_resolution and add some documentation
timeEndPeriod must be called with the same timer resolution value used in
timeBeginPeriod. When the process exits the timer resolution is restored anyway
so this is not very important.
Diffstat (limited to 'libs/pbd/windows_timer_utils.cc')
-rw-r--r-- | libs/pbd/windows_timer_utils.cc | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/libs/pbd/windows_timer_utils.cc b/libs/pbd/windows_timer_utils.cc index fcf8fa8003..d95a69e0c7 100644 --- a/libs/pbd/windows_timer_utils.cc +++ b/libs/pbd/windows_timer_utils.cc @@ -29,20 +29,20 @@ namespace { UINT& -old_timer_resolution () +timer_resolution () { static UINT timer_res_ms = 0; return timer_res_ms; } -} // anon namespace +} namespace PBD { namespace MMTIMERS { bool -set_min_resolution () +get_min_resolution (uint32_t& min_resolution_ms) { TIMECAPS caps; @@ -50,61 +50,57 @@ set_min_resolution () DEBUG_TIMING ("Could not get timer device capabilities.\n"); return false; } - return set_resolution(caps.wPeriodMin); + + min_resolution_ms = caps.wPeriodMin; + return true; } bool -set_resolution (uint32_t timer_resolution_ms) +set_min_resolution () { - TIMECAPS caps; + uint32_t min_resolution = 0; - if (timeGetDevCaps (&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) { - DEBUG_TIMING ("Could not get timer device capabilities.\n"); + if (!get_min_resolution (min_resolution)) { return false; } - UINT old_timer_res = caps.wPeriodMin; - - if (timeBeginPeriod(timer_resolution_ms) != TIMERR_NOERROR) { - DEBUG_TIMING( - string_compose("Could not set minimum timer resolution to %1(ms)\n", - timer_resolution_ms)); + if (!set_resolution (min_resolution)) { return false; } - - old_timer_resolution () = old_timer_res; - - DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n", - caps.wPeriodMin)); return true; } bool -get_resolution (uint32_t& timer_resolution_ms) +set_resolution (uint32_t timer_resolution_ms) { - TIMECAPS caps; + if (timer_resolution() != 0) { + DEBUG_TIMING( + "Timer resolution must be reset before setting new resolution.\n"); + } - if (timeGetDevCaps(&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) { - DEBUG_TIMING ("Could not get timer device capabilities.\n"); + if (timeBeginPeriod(timer_resolution_ms) != TIMERR_NOERROR) { + DEBUG_TIMING( + string_compose("Could not set timer resolution to %1(ms)\n", + timer_resolution_ms)); return false; } - timer_resolution_ms = caps.wPeriodMin; + + timer_resolution() = timer_resolution_ms; + + DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n", + timer_resolution_ms)); return true; } bool reset_resolution () { - if (old_timer_resolution ()) { - if (timeEndPeriod (old_timer_resolution ()) != TIMERR_NOERROR) { - DEBUG_TIMING ("Could not reset timer resolution.\n"); - return false; - } + // You must match calls to timeBegin/EndPeriod with the same resolution + if (timeEndPeriod(timer_resolution()) != TIMERR_NOERROR) { + DEBUG_TIMING("Could not reset the Timer resolution.\n"); + return false; } - - DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n", - old_timer_resolution ())); - + timer_resolution() = 0; return true; } |