diff options
author | John Emmas <johne53@tiscali.co.uk> | 2014-05-06 09:25:27 +0100 |
---|---|---|
committer | John Emmas <johne53@tiscali.co.uk> | 2014-05-06 09:25:27 +0100 |
commit | 41fe637e80a9b78ed0d1ff478daa1ebe3d9bca28 (patch) | |
tree | 217ed6ff664e50851d5eaf23c1eeaebf7fb3dff6 /libs | |
parent | 051ceffc5d947cc610dfa7bcc4bfd50e22fc2cac (diff) |
Add the 'porttime' source file for Windows
Diffstat (limited to 'libs')
-rw-r--r-- | libs/backends/wavesaudio/portmidi/src/porttime/ptwinmm.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libs/backends/wavesaudio/portmidi/src/porttime/ptwinmm.c b/libs/backends/wavesaudio/portmidi/src/porttime/ptwinmm.c new file mode 100644 index 0000000000..b0607ca332 --- /dev/null +++ b/libs/backends/wavesaudio/portmidi/src/porttime/ptwinmm.c @@ -0,0 +1,71 @@ +/* ptwinmm.c -- portable timer implementation for win32 */ + + +#include "porttime.h" +#include <windows.h> +#include <mmsystem.h> +#include <time.h> + + +TIMECAPS caps; + +static long time_offset = 0; +static int time_started_flag = FALSE; +static long time_resolution; +static MMRESULT timer_id; +static PtCallback *time_callback; + +void CALLBACK winmm_time_callback(UINT uID, UINT uMsg, DWORD_PTR dwUser, + DWORD_PTR dw1, DWORD_PTR dw2) +{ + (*time_callback)(Pt_Time(), (void *) dwUser); +} + + +PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData) +{ + if (time_started_flag) return ptAlreadyStarted; + timeBeginPeriod(resolution); + time_resolution = resolution; + time_offset = timeGetTime(); + time_started_flag = TRUE; + time_callback = callback; + if (callback) { + timer_id = timeSetEvent(resolution, 1, winmm_time_callback, + (DWORD_PTR) userData, TIME_PERIODIC | TIME_CALLBACK_FUNCTION); + if (!timer_id) return ptHostError; + } + return ptNoError; +} + + +PMEXPORT PtError Pt_Stop() +{ + if (!time_started_flag) return ptAlreadyStopped; + if (time_callback && timer_id) { + timeKillEvent(timer_id); + time_callback = NULL; + timer_id = 0; + } + time_started_flag = FALSE; + timeEndPeriod(time_resolution); + return ptNoError; +} + + +PMEXPORT int Pt_Started() +{ + return time_started_flag; +} + + +PMEXPORT PtTimestamp Pt_Time() +{ + return timeGetTime() - time_offset; +} + + +PMEXPORT void Pt_Sleep(int32_t duration) +{ + Sleep(duration); +} |