~ubuntu-branches/ubuntu/precise/puredata/precise

« back to all changes in this revision

Viewing changes to portmidi/porttime/ptwinmm.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Brossier
  • Date: 2009-12-22 21:29:31 UTC
  • mfrom: (1.2.6 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091222212931-nhwkzapjwsmjao1l
Tags: 0.42.5-3
* debian/control:
  - add community site to homepage field
  - improve long description
  - remove Replaces and Conflicts fields
  - add Suggests on pd-csound, pd-pdp, pd-zexy, pd-aubio
* debian/rules: add per-arch configuration flags
* debian/patches/02_kfreebsd.diff:
  - also define pd_tilde_dllextent on FreeBSD
  - fix typo (really closing #414414 this time)
  - also add hurd glue
* debian/patches/04_hurd.diff:
  - add hurd glue and s_midi_dummy.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ptwinmm.c -- portable timer implementation for win32 */
 
2
 
 
3
 
 
4
#include "porttime.h"
 
5
#include "windows.h"
 
6
#include "time.h"
 
7
 
 
8
 
 
9
TIMECAPS caps;
 
10
 
 
11
static long time_offset = 0;
 
12
static int time_started_flag = FALSE;
 
13
static long time_resolution;
 
14
static MMRESULT timer_id;
 
15
static PtCallback *time_callback;
 
16
 
 
17
void CALLBACK winmm_time_callback(UINT uID, UINT uMsg, DWORD dwUser, 
 
18
                                  DWORD dw1, DWORD dw2)
 
19
{
 
20
    (*time_callback)(Pt_Time(), (void *) dwUser);
 
21
}
 
22
 
 
23
 
 
24
PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
 
25
{
 
26
    if (time_started_flag) return ptAlreadyStarted;
 
27
    timeBeginPeriod(resolution);
 
28
    time_resolution = resolution;
 
29
    time_offset = timeGetTime();
 
30
    time_started_flag = TRUE;
 
31
    time_callback = callback;
 
32
    if (callback) {
 
33
        timer_id = timeSetEvent(resolution, 1, winmm_time_callback, 
 
34
            (DWORD) userData, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
 
35
        if (!timer_id) return ptHostError;
 
36
    }
 
37
    return ptNoError;
 
38
}
 
39
 
 
40
 
 
41
PtError Pt_Stop()
 
42
{
 
43
    if (!time_started_flag) return ptAlreadyStopped;
 
44
    if (time_callback && timer_id) {
 
45
        timeKillEvent(timer_id);
 
46
        time_callback = NULL;
 
47
        timer_id = 0;
 
48
    }
 
49
    time_started_flag = FALSE;
 
50
    timeEndPeriod(time_resolution);
 
51
    return ptNoError;
 
52
}
 
53
 
 
54
 
 
55
int Pt_Started()
 
56
{
 
57
    return time_started_flag;
 
58
}
 
59
 
 
60
 
 
61
PtTimestamp Pt_Time()
 
62
{
 
63
    return timeGetTime() - time_offset;
 
64
}
 
65