summaryrefslogtreecommitdiff
path: root/libs/backends/wavesaudio/portmidi/porttime.h
blob: c7b7aff218bd4b74ff5425bb3d678bd7ff0ddadd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* porttime.h -- portable interface to millisecond timer */

/* CHANGE LOG FOR PORTTIME
  10-Jun-03 Mark Nelson & RBD
    boost priority of timer thread in ptlinux.c implementation
 */

/* Should there be a way to choose the source of time here? */

#ifdef WIN32
#ifndef INT32_DEFINED
// rather than having users install a special .h file for windows,
// just put the required definitions inline here. portmidi.h uses
// these too, so the definitions are (unfortunately) duplicated there
typedef int int32_t;
typedef unsigned int uint32_t;
#define INT32_DEFINED
#endif
#else
#include <stdint.h> // needed for int32_t
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifndef PMEXPORT
#ifdef _WINDLL
#define PMEXPORT __declspec(dllexport)
#else
#define PMEXPORT
#endif
#endif

typedef enum {
    ptNoError = 0,         /* success */
    ptHostError = -10000,  /* a system-specific error occurred */
    ptAlreadyStarted,      /* cannot start timer because it is already started */
    ptAlreadyStopped,      /* cannot stop timer because it is already stopped */
    ptInsufficientMemory   /* memory could not be allocated */
} PtError;


typedef int32_t PtTimestamp;

typedef void (PtCallback)( PtTimestamp timestamp, void *userData );

/*
    Pt_Start() starts a real-time service.

    resolution is the timer resolution in ms. The time will advance every
    resolution ms.

    callback is a function pointer to be called every resolution ms.

    userData is passed to callback as a parameter.

    return value:
    Upon success, returns ptNoError. See PtError for other values.
*/
PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData);

/*
    Pt_Stop() stops the timer.

    return value:
    Upon success, returns ptNoError. See PtError for other values.
*/
PMEXPORT PtError Pt_Stop();

/*
    Pt_Started() returns true iff the timer is running.
*/
PMEXPORT int Pt_Started();

/*
    Pt_Time() returns the current time in ms.
*/
PMEXPORT PtTimestamp Pt_Time();

/*
    Pt_Sleep() pauses, allowing other threads to run.

    duration is the length of the pause in ms. The true duration
    of the pause may be rounded to the nearest or next clock tick
    as determined by resolution in Pt_Start().
*/
PMEXPORT void Pt_Sleep(int32_t duration);

#ifdef __cplusplus
}
#endif