2 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef PBD_WINDOWS_TIMER_UTILS_H
20 #define PBD_WINDOWS_TIMER_UTILS_H
24 #include "pbd/libpbd_visibility.h"
31 * Get the minimum Multimedia Timer resolution as supported by the system
32 * @return true if getting min timer resolution was not successful
34 bool LIBPBD_API get_min_resolution (uint32_t& timer_resolution_ms);
37 * Set the minimum Multimedia Timer resolution as supported by the system
38 * @return true if setting min timer resolution was successful
40 bool LIBPBD_API set_min_resolution ();
43 * Set current Multimedia Timer resolution. If the timer resolution has already
44 * been set then reset_resolution() must be called before set_resolution will
46 * @return true if setting the timer value was successful, false if setting the
47 * timer resolution failed or the resolution has already been set.
49 bool LIBPBD_API set_resolution(uint32_t timer_resolution_ms);
52 * Reset Multimedia Timer resolution. In my testing, if the timer resolution is
53 * set below the default, then resetting the resolution will not reset the
54 * timer resolution back to 15ms. At least it does not reset immediately
55 * even after calling Sleep.
56 * @return true if setting the timer value was successful
58 bool LIBPBD_API reset_resolution();
60 } // namespace MMTIMERS
65 * Initialize the QPC timer, must be called before QPC::get_microseconds will
66 * return a valid value.
67 * @return true if QPC timer is usable, use check_timer_valid to try to check
70 bool LIBPBD_API initialize ();
73 * @return true if QueryPerformanceCounter is usable as a timer source
74 * This should always return true for systems > XP as those versions of windows
75 * have there own tests to check timer validity and will select an appropriate
76 * timer source. This check is not conclusive and there are probably conditions
77 * under which this check will return true but the timer is not monotonic.
79 bool LIBPBD_API check_timer_valid ();
82 * @return the value of the performance counter converted to microseconds
84 * If initialize returns true then get_microseconds will always return a
85 * positive value. If QPC is not supported(OS < XP) then -1 is returned but the
86 * MS docs say that this won't occur for systems >= XP.
88 int64_t LIBPBD_API get_microseconds ();
93 * The highest resolution timer source provided by the system. On Vista and
94 * above this is the value returned by QueryPerformanceCounter(QPC). On XP,
95 * this will QPC if supported or otherwise g_get_monotonic_time will be used.
97 * @return A timer value in microseconds or -1 in the event that the reading
98 * the timer source fails.
100 int64_t LIBPBD_API get_microseconds ();
104 #endif // PBD_WINDOWS_TIMER_UTILS_H