aboutsummaryrefslogtreecommitdiff
path: root/pd/portmidi/porttime/ptwinmm.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-12-15 00:57:02 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-12-15 00:57:02 +0000
commit90d5b8b4a064420d74678654e94ea4755b377f21 (patch)
tree5d49b9f6ae17b75c98ad1a8302a0d84f1d99f75b /pd/portmidi/porttime/ptwinmm.c
parent59ad9e9cf0a72b31f8bfd371cb97536ed4d4fe61 (diff)
checking in missing files on behalf of Miller (cleared it with him first). The files are from portmidi17nov04.zip
svn path=/trunk/; revision=4216
Diffstat (limited to 'pd/portmidi/porttime/ptwinmm.c')
-rw-r--r--pd/portmidi/porttime/ptwinmm.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/pd/portmidi/porttime/ptwinmm.c b/pd/portmidi/porttime/ptwinmm.c
new file mode 100644
index 00000000..bbfebb0e
--- /dev/null
+++ b/pd/portmidi/porttime/ptwinmm.c
@@ -0,0 +1,65 @@
+/* ptwinmm.c -- portable timer implementation for win32 */
+
+
+#include "porttime.h"
+#include "windows.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 dwUser,
+ DWORD dw1, DWORD dw2)
+{
+ (*time_callback)(Pt_Time(), (void *) dwUser);
+}
+
+
+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) userData, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
+ if (!timer_id) return ptHostError;
+ }
+ return ptNoError;
+}
+
+
+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;
+}
+
+
+int Pt_Started()
+{
+ return time_started_flag;
+}
+
+
+PtTimestamp Pt_Time()
+{
+ return timeGetTime() - time_offset;
+}
+