-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCuckoo.c
85 lines (69 loc) · 1.69 KB
/
Cuckoo.c
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
/*
Cuckoo clock
*/
#include "sunclock.h"
/* CUCKOO -- Play the cuckoo sound resource a given number of times. */
static void cuckoo(int tweets)
{
HANDLE hResInfo, hRes;
LPSTR lpRes;
hResInfo = FindResource(hInst, "cuckoo", "WAVE");
if (hResInfo != NULL) {
hRes = LoadResource(hInst, hResInfo);
if (hRes != NULL) {
lpRes = LockResource(hRes);
if (lpRes != NULL) {
int i;
for (i = 0; i < tweets; i++) {
sndPlaySound(lpRes, SND_MEMORY | SND_SYNC | SND_NODEFAULT);
/* If we're doing multiple tweets, let other applications sneak in
between chirps. */
if (tweets > 1) {
MSG dmsg;
PeekMessage(&dmsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
}
}
UnlockResource(hRes);
}
}
FreeResource(hRes);
}
}
/* UPDATECUCKOO -- Check if it's time and give the user the bird if appropriate. */
void updateCuckoo(void)
{
// #define DEBUG_BOID
if (cuckooEnable && cuckooClock && waveAudioAvailable) {
static int oldhh = -1, oldmm = -1;
int newhh, newmm;
struct tm lt;
set_tm_time(<, TRUE);
newhh = lt.tm_hour % 12;
newmm = lt.tm_min;
#ifdef DEBUG_BOID
if (animate || !runmode) {
int hh, mmm, ss;
jhms(faketime, &hh, &mmm, &ss);
newhh = hh % 12;
newmm = mmm;
}
#endif
if (newhh == 0) {
newhh = 12;
}
// If the hour's changed, chirp the civil hour, 1 to 12.
if (oldhh != newhh) {
if (oldhh != -1) {
cuckoo(newhh);
}
oldhh = newhh;
}
// If we've just passed the half-hour mark, chirp once.
if (newmm >= 30 && oldmm < 30) {
if (oldmm != -1) {
cuckoo(1);
}
}
oldmm = newmm;
}
}