blob: b37db4c6cbc49261dbab5de30f8489025afbec52 [file] [log] [blame]
Zachary Ware73f8cfb2015-05-13 01:21:21 -05001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(winsound_PlaySound__doc__,
Zachary Warec4018812016-09-06 16:32:43 -05006"PlaySound($module, /, sound, flags)\n"
Zachary Ware73f8cfb2015-05-13 01:21:21 -05007"--\n"
8"\n"
9"A wrapper around the Windows PlaySound API.\n"
10"\n"
11" sound\n"
12" The sound to play; a filename, data, or None.\n"
13" flags\n"
14" Flag values, ored together. See module documentation.");
15
16#define WINSOUND_PLAYSOUND_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020017 {"PlaySound", (PyCFunction)(void(*)(void))winsound_PlaySound, METH_FASTCALL|METH_KEYWORDS, winsound_PlaySound__doc__},
Zachary Ware73f8cfb2015-05-13 01:21:21 -050018
19static PyObject *
Zachary Wareae8298b2016-09-05 16:31:21 -050020winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags);
Zachary Ware73f8cfb2015-05-13 01:21:21 -050021
22static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020023winsound_PlaySound(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Ware73f8cfb2015-05-13 01:21:21 -050024{
25 PyObject *return_value = NULL;
Zachary Warec4018812016-09-06 16:32:43 -050026 static const char * const _keywords[] = {"sound", "flags", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020027 static _PyArg_Parser _parser = {NULL, _keywords, "PlaySound", 0};
28 PyObject *argsbuf[2];
Zachary Wareae8298b2016-09-05 16:31:21 -050029 PyObject *sound;
Zachary Ware73f8cfb2015-05-13 01:21:21 -050030 int flags;
31
Serhiy Storchaka31913912019-03-14 10:32:22 +020032 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
33 if (!args) {
34 goto exit;
35 }
36 sound = args[0];
37 if (PyFloat_Check(args[1])) {
38 PyErr_SetString(PyExc_TypeError,
39 "integer argument expected, got float" );
40 goto exit;
41 }
42 flags = _PyLong_AsInt(args[1]);
43 if (flags == -1 && PyErr_Occurred()) {
Zachary Ware73f8cfb2015-05-13 01:21:21 -050044 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030045 }
Zachary Ware73f8cfb2015-05-13 01:21:21 -050046 return_value = winsound_PlaySound_impl(module, sound, flags);
47
48exit:
49 return return_value;
50}
51
52PyDoc_STRVAR(winsound_Beep__doc__,
Zachary Warec4018812016-09-06 16:32:43 -050053"Beep($module, /, frequency, duration)\n"
Zachary Ware73f8cfb2015-05-13 01:21:21 -050054"--\n"
55"\n"
56"A wrapper around the Windows Beep API.\n"
57"\n"
58" frequency\n"
59" Frequency of the sound in hertz.\n"
60" Must be in the range 37 through 32,767.\n"
61" duration\n"
62" How long the sound should play, in milliseconds.");
63
64#define WINSOUND_BEEP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020065 {"Beep", (PyCFunction)(void(*)(void))winsound_Beep, METH_FASTCALL|METH_KEYWORDS, winsound_Beep__doc__},
Zachary Ware73f8cfb2015-05-13 01:21:21 -050066
67static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030068winsound_Beep_impl(PyObject *module, int frequency, int duration);
Zachary Ware73f8cfb2015-05-13 01:21:21 -050069
70static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020071winsound_Beep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Ware73f8cfb2015-05-13 01:21:21 -050072{
73 PyObject *return_value = NULL;
Zachary Warec4018812016-09-06 16:32:43 -050074 static const char * const _keywords[] = {"frequency", "duration", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020075 static _PyArg_Parser _parser = {NULL, _keywords, "Beep", 0};
76 PyObject *argsbuf[2];
Zachary Ware73f8cfb2015-05-13 01:21:21 -050077 int frequency;
78 int duration;
79
Serhiy Storchaka31913912019-03-14 10:32:22 +020080 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
81 if (!args) {
82 goto exit;
83 }
84 if (PyFloat_Check(args[0])) {
85 PyErr_SetString(PyExc_TypeError,
86 "integer argument expected, got float" );
87 goto exit;
88 }
89 frequency = _PyLong_AsInt(args[0]);
90 if (frequency == -1 && PyErr_Occurred()) {
91 goto exit;
92 }
93 if (PyFloat_Check(args[1])) {
94 PyErr_SetString(PyExc_TypeError,
95 "integer argument expected, got float" );
96 goto exit;
97 }
98 duration = _PyLong_AsInt(args[1]);
99 if (duration == -1 && PyErr_Occurred()) {
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500100 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300101 }
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500102 return_value = winsound_Beep_impl(module, frequency, duration);
103
104exit:
105 return return_value;
106}
107
108PyDoc_STRVAR(winsound_MessageBeep__doc__,
Zachary Warec4018812016-09-06 16:32:43 -0500109"MessageBeep($module, /, type=MB_OK)\n"
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500110"--\n"
111"\n"
112"Call Windows MessageBeep(x).\n"
113"\n"
114"x defaults to MB_OK.");
115
116#define WINSOUND_MESSAGEBEEP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200117 {"MessageBeep", (PyCFunction)(void(*)(void))winsound_MessageBeep, METH_FASTCALL|METH_KEYWORDS, winsound_MessageBeep__doc__},
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500118
119static PyObject *
Zachary Warec4018812016-09-06 16:32:43 -0500120winsound_MessageBeep_impl(PyObject *module, int type);
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500121
122static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200123winsound_MessageBeep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500124{
125 PyObject *return_value = NULL;
Zachary Warec4018812016-09-06 16:32:43 -0500126 static const char * const _keywords[] = {"type", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200127 static _PyArg_Parser _parser = {NULL, _keywords, "MessageBeep", 0};
128 PyObject *argsbuf[1];
129 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Zachary Warec4018812016-09-06 16:32:43 -0500130 int type = MB_OK;
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500131
Serhiy Storchaka31913912019-03-14 10:32:22 +0200132 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
133 if (!args) {
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300135 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200136 if (!noptargs) {
137 goto skip_optional_pos;
138 }
139 if (PyFloat_Check(args[0])) {
140 PyErr_SetString(PyExc_TypeError,
141 "integer argument expected, got float" );
142 goto exit;
143 }
144 type = _PyLong_AsInt(args[0]);
145 if (type == -1 && PyErr_Occurred()) {
146 goto exit;
147 }
148skip_optional_pos:
Zachary Warec4018812016-09-06 16:32:43 -0500149 return_value = winsound_MessageBeep_impl(module, type);
Zachary Ware73f8cfb2015-05-13 01:21:21 -0500150
151exit:
152 return return_value;
153}
Serhiy Storchaka31913912019-03-14 10:32:22 +0200154/*[clinic end generated code: output=28d1cd033282723d input=a9049054013a1b77]*/