winsound.c.h 5.8 KB

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