Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/PC/clinic/winsound.c.h
12 views
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
# include "pycore_gc.h" // PyGC_Head
7
# include "pycore_runtime.h" // _Py_ID()
8
#endif
9
10
11
PyDoc_STRVAR(winsound_PlaySound__doc__,
12
"PlaySound($module, /, sound, flags)\n"
13
"--\n"
14
"\n"
15
"A wrapper around the Windows PlaySound API.\n"
16
"\n"
17
" sound\n"
18
" The sound to play; a filename, data, or None.\n"
19
" flags\n"
20
" Flag values, ored together. See module documentation.");
21
22
#define WINSOUND_PLAYSOUND_METHODDEF \
23
{"PlaySound", _PyCFunction_CAST(winsound_PlaySound), METH_FASTCALL|METH_KEYWORDS, winsound_PlaySound__doc__},
24
25
static PyObject *
26
winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags);
27
28
static PyObject *
29
winsound_PlaySound(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
30
{
31
PyObject *return_value = NULL;
32
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
33
34
#define NUM_KEYWORDS 2
35
static struct {
36
PyGC_Head _this_is_not_used;
37
PyObject_VAR_HEAD
38
PyObject *ob_item[NUM_KEYWORDS];
39
} _kwtuple = {
40
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
41
.ob_item = { &_Py_ID(sound), &_Py_ID(flags), },
42
};
43
#undef NUM_KEYWORDS
44
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
45
46
#else // !Py_BUILD_CORE
47
# define KWTUPLE NULL
48
#endif // !Py_BUILD_CORE
49
50
static const char * const _keywords[] = {"sound", "flags", NULL};
51
static _PyArg_Parser _parser = {
52
.keywords = _keywords,
53
.fname = "PlaySound",
54
.kwtuple = KWTUPLE,
55
};
56
#undef KWTUPLE
57
PyObject *argsbuf[2];
58
PyObject *sound;
59
int flags;
60
61
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
62
if (!args) {
63
goto exit;
64
}
65
sound = args[0];
66
flags = _PyLong_AsInt(args[1]);
67
if (flags == -1 && PyErr_Occurred()) {
68
goto exit;
69
}
70
return_value = winsound_PlaySound_impl(module, sound, flags);
71
72
exit:
73
return return_value;
74
}
75
76
PyDoc_STRVAR(winsound_Beep__doc__,
77
"Beep($module, /, frequency, duration)\n"
78
"--\n"
79
"\n"
80
"A wrapper around the Windows Beep API.\n"
81
"\n"
82
" frequency\n"
83
" Frequency of the sound in hertz.\n"
84
" Must be in the range 37 through 32,767.\n"
85
" duration\n"
86
" How long the sound should play, in milliseconds.");
87
88
#define WINSOUND_BEEP_METHODDEF \
89
{"Beep", _PyCFunction_CAST(winsound_Beep), METH_FASTCALL|METH_KEYWORDS, winsound_Beep__doc__},
90
91
static PyObject *
92
winsound_Beep_impl(PyObject *module, int frequency, int duration);
93
94
static PyObject *
95
winsound_Beep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
96
{
97
PyObject *return_value = NULL;
98
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
99
100
#define NUM_KEYWORDS 2
101
static struct {
102
PyGC_Head _this_is_not_used;
103
PyObject_VAR_HEAD
104
PyObject *ob_item[NUM_KEYWORDS];
105
} _kwtuple = {
106
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
107
.ob_item = { &_Py_ID(frequency), &_Py_ID(duration), },
108
};
109
#undef NUM_KEYWORDS
110
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
111
112
#else // !Py_BUILD_CORE
113
# define KWTUPLE NULL
114
#endif // !Py_BUILD_CORE
115
116
static const char * const _keywords[] = {"frequency", "duration", NULL};
117
static _PyArg_Parser _parser = {
118
.keywords = _keywords,
119
.fname = "Beep",
120
.kwtuple = KWTUPLE,
121
};
122
#undef KWTUPLE
123
PyObject *argsbuf[2];
124
int frequency;
125
int duration;
126
127
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
128
if (!args) {
129
goto exit;
130
}
131
frequency = _PyLong_AsInt(args[0]);
132
if (frequency == -1 && PyErr_Occurred()) {
133
goto exit;
134
}
135
duration = _PyLong_AsInt(args[1]);
136
if (duration == -1 && PyErr_Occurred()) {
137
goto exit;
138
}
139
return_value = winsound_Beep_impl(module, frequency, duration);
140
141
exit:
142
return return_value;
143
}
144
145
PyDoc_STRVAR(winsound_MessageBeep__doc__,
146
"MessageBeep($module, /, type=MB_OK)\n"
147
"--\n"
148
"\n"
149
"Call Windows MessageBeep(x).\n"
150
"\n"
151
"x defaults to MB_OK.");
152
153
#define WINSOUND_MESSAGEBEEP_METHODDEF \
154
{"MessageBeep", _PyCFunction_CAST(winsound_MessageBeep), METH_FASTCALL|METH_KEYWORDS, winsound_MessageBeep__doc__},
155
156
static PyObject *
157
winsound_MessageBeep_impl(PyObject *module, int type);
158
159
static PyObject *
160
winsound_MessageBeep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
161
{
162
PyObject *return_value = NULL;
163
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
164
165
#define NUM_KEYWORDS 1
166
static struct {
167
PyGC_Head _this_is_not_used;
168
PyObject_VAR_HEAD
169
PyObject *ob_item[NUM_KEYWORDS];
170
} _kwtuple = {
171
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
172
.ob_item = { &_Py_ID(type), },
173
};
174
#undef NUM_KEYWORDS
175
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
176
177
#else // !Py_BUILD_CORE
178
# define KWTUPLE NULL
179
#endif // !Py_BUILD_CORE
180
181
static const char * const _keywords[] = {"type", NULL};
182
static _PyArg_Parser _parser = {
183
.keywords = _keywords,
184
.fname = "MessageBeep",
185
.kwtuple = KWTUPLE,
186
};
187
#undef KWTUPLE
188
PyObject *argsbuf[1];
189
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
190
int type = MB_OK;
191
192
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
193
if (!args) {
194
goto exit;
195
}
196
if (!noptargs) {
197
goto skip_optional_pos;
198
}
199
type = _PyLong_AsInt(args[0]);
200
if (type == -1 && PyErr_Occurred()) {
201
goto exit;
202
}
203
skip_optional_pos:
204
return_value = winsound_MessageBeep_impl(module, type);
205
206
exit:
207
return return_value;
208
}
209
/*[clinic end generated code: output=f70b7730127208d8 input=a9049054013a1b77]*/
210
211