globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / backends / wavesaudio / portmidi / src / porttime / ptwinmm.c
1 /* ptwinmm.c -- portable timer implementation for win32 */
2
3
4 #include "porttime.h"
5
6 #include <windows.h>
7 #include <mmsystem.h>
8 #include <time.h>
9
10 TIMECAPS caps;
11
12 static long time_offset = 0;
13 static int time_started_flag = FALSE;
14 static long time_resolution;
15 static MMRESULT timer_id;
16 static PtCallback *time_callback;
17
18 void CALLBACK winmm_time_callback(UINT uID, UINT uMsg, DWORD_PTR dwUser,
19                                   DWORD_PTR dw1, DWORD_PTR dw2)
20 {
21     (*time_callback)(Pt_Time(), (void *) dwUser);
22 }
23
24
25 PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
26 {
27     if (time_started_flag) return ptAlreadyStarted;
28     timeBeginPeriod(resolution);
29     time_resolution = resolution;
30     time_offset = timeGetTime();
31     time_started_flag = TRUE;
32     time_callback = callback;
33     if (callback) {
34         timer_id = timeSetEvent(resolution, 1, winmm_time_callback,
35             (DWORD_PTR) userData, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
36         if (!timer_id) return ptHostError;
37     }
38     return ptNoError;
39 }
40
41
42 PMEXPORT PtError Pt_Stop()
43 {
44     if (!time_started_flag) return ptAlreadyStopped;
45     if (time_callback && timer_id) {
46         timeKillEvent(timer_id);
47         time_callback = NULL;
48         timer_id = 0;
49     }
50     time_started_flag = FALSE;
51     timeEndPeriod(time_resolution);
52     return ptNoError;
53 }
54
55
56 PMEXPORT int Pt_Started()
57 {
58     return time_started_flag;
59 }
60
61
62 PMEXPORT PtTimestamp Pt_Time()
63 {
64     return timeGetTime() - time_offset;
65 }
66
67
68 PMEXPORT void Pt_Sleep(int32_t duration)
69 {
70     Sleep(duration);
71 }