Guido van Rossum | 2cc340d | 1999-02-02 15:14:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SOUND |
| 3 | * $Id$ |
| 4 | * |
| 5 | * play sound on a windows platform |
| 6 | * |
| 7 | * history: |
| 8 | * 99-02-02 fl created |
| 9 | * |
| 10 | * Copyright (c) 1999 by Secret Labs AB. |
| 11 | * Copyright (c) 1999 by Fredrik Lundh. |
| 12 | * |
| 13 | * fredrik@pythonware.com |
| 14 | * http://www.pythonware.com |
| 15 | * |
| 16 | * -------------------------------------------------------------------- |
| 17 | * Permission to use, copy, modify, and distribute this software and |
| 18 | * its associated documentation for any purpose and without fee is |
| 19 | * hereby granted. This software is provided as is. |
| 20 | * -------------------------------------------------------------------- |
| 21 | */ |
| 22 | |
| 23 | #include "Python.h" |
| 24 | |
| 25 | #include "windows.h" |
| 26 | #include "mmsystem.h" |
| 27 | |
| 28 | static PyObject* |
| 29 | _play(PyObject* self, PyObject* args) |
| 30 | { |
| 31 | int result; |
| 32 | |
| 33 | /* first argument is a string that should contain the contents of |
| 34 | a WAV file. second argument should be non-zero to wait for the |
| 35 | sound to complete. */ |
| 36 | |
| 37 | char *data = NULL; |
| 38 | int bytes; |
| 39 | int wait = 0; |
| 40 | if (!PyArg_ParseTuple(args, "|s#i", &data, &bytes, &wait)) |
| 41 | return NULL; |
| 42 | |
| 43 | result = PlaySound(data, NULL, (SND_MEMORY|SND_NOWAIT|SND_NODEFAULT) | |
| 44 | (wait ? 0 : SND_ASYNC)); |
| 45 | |
| 46 | return Py_BuildValue("i", result); |
| 47 | } |
| 48 | |
| 49 | static PyObject* |
| 50 | _stop(PyObject* self, PyObject* args) |
| 51 | { |
| 52 | if (!PyArg_NoArgs(args)) |
| 53 | return NULL; |
| 54 | |
| 55 | return Py_BuildValue("i", PlaySound(NULL, NULL, 0)); |
| 56 | } |
| 57 | |
| 58 | static PyMethodDef _functions[] = { |
| 59 | {"play", _play, 1}, |
| 60 | {"stop", _stop, 0}, |
| 61 | {NULL, NULL} |
| 62 | }; |
| 63 | |
| 64 | void |
| 65 | #ifdef WIN32 |
| 66 | __declspec(dllexport) |
| 67 | #endif |
| 68 | initwinsound() |
| 69 | { |
| 70 | Py_InitModule("winsound", _functions); |
| 71 | } |