Back to index

python3.2  3.2.2
Defines | Functions | Variables
winsound.c File Reference
#include <Python.h>
#include <windows.h>
#include <mmsystem.h>

Go to the source code of this file.

Defines

#define ADD_DEFINE(tok)   add_define(dict,#tok,tok)

Functions

 PyDoc_STRVAR (sound_playsound_doc,"PlaySound(sound, flags) - a wrapper around the Windows PlaySound API\n""\n""The sound argument can be a filename, data, or None.\n""For flag values, ored together, see module documentation.")
 PyDoc_STRVAR (sound_beep_doc,"Beep(frequency, duration) - a wrapper around the Windows Beep API\n""\n""The frequency argument specifies frequency, in hertz, of the sound.\n""This parameter must be in the range 37 through 32,767.\n""The duration argument specifies the number of milliseconds.\n")
 PyDoc_STRVAR (sound_msgbeep_doc,"MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK.")
 PyDoc_STRVAR (sound_module_doc,"PlaySound(sound, flags) - play a sound\n""SND_FILENAME - sound is a wav file name\n""SND_ALIAS - sound is a registry sound association name\n""SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC\n""SND_MEMORY - sound is a memory image of a wav file\n""SND_PURGE - stop all instances of the specified sound\n""SND_ASYNC - PlaySound returns immediately\n""SND_NODEFAULT - Do not play a default beep if the sound can not be found\n""SND_NOSTOP - Do not interrupt any sounds currently playing\n""SND_NOWAIT - Return immediately if the sound driver is busy\n""\n""Beep(frequency, duration) - Make a beep through the PC speaker.")
static PyObjectsound_playsound (PyObject *s, PyObject *args)
static PyObjectsound_beep (PyObject *self, PyObject *args)
static PyObjectsound_msgbeep (PyObject *self, PyObject *args)
static void add_define (PyObject *dict, const char *key, long value)
PyMODINIT_FUNC PyInit_winsound (void)

Variables

static struct PyMethodDef []
static struct PyModuleDef

Define Documentation

#define ADD_DEFINE (   tok)    add_define(dict,#tok,tok)

Definition at line 158 of file winsound.c.


Function Documentation

static void add_define ( PyObject dict,
const char *  key,
long  value 
) [static]

Definition at line 147 of file winsound.c.

Here is the call graph for this function:

PyDoc_STRVAR ( sound_playsound_doc  ,
"PlaySound(sound, flags) - a wrapper around the Windows PlaySound API\n""\n""The sound argument can be a  filename,
data  ,
or None.\n""For flag  values,
ored  together,
see module documentation."   
)
PyDoc_STRVAR ( sound_beep_doc  ,
"Beep(frequency, duration) - a wrapper around the Windows Beep API\n""\n""The frequency argument specifies  frequency,
in  hertz,
of the sound.\n""This parameter must be in the range 37 through  32,
767.\n""The duration argument specifies the number of milliseconds.\n  
)
PyDoc_STRVAR ( sound_msgbeep_doc  ,
"MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK."   
)
PyDoc_STRVAR ( sound_module_doc  ,
"PlaySound(sound, flags) - play a sound\n""SND_FILENAME - sound is a wav file name\n""SND_ALIAS - sound is a registry sound association name\n""SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC\n""SND_MEMORY - sound is a memory image of a wav file\n""SND_PURGE - stop all instances of the specified sound\n""SND_ASYNC - PlaySound returns immediately\n""SND_NODEFAULT - Do not play a default beep if the sound can not be found\n""SND_NOSTOP - Do not interrupt any sounds currently playing\n""SND_NOWAIT - Return immediately if the sound driver is busy\n""\n""Beep(frequency, duration) - Make a beep through the PC speaker."   
)

Definition at line 174 of file winsound.c.

{
    PyObject *dict;
    PyObject *module = PyModule_Create(&winsoundmodule);
    if (module == NULL)
        return NULL;
    dict = PyModule_GetDict(module);

    ADD_DEFINE(SND_ASYNC);
    ADD_DEFINE(SND_NODEFAULT);
    ADD_DEFINE(SND_NOSTOP);
    ADD_DEFINE(SND_NOWAIT);
    ADD_DEFINE(SND_ALIAS);
    ADD_DEFINE(SND_FILENAME);
    ADD_DEFINE(SND_MEMORY);
    ADD_DEFINE(SND_PURGE);
    ADD_DEFINE(SND_LOOP);
    ADD_DEFINE(SND_APPLICATION);

    ADD_DEFINE(MB_OK);
    ADD_DEFINE(MB_ICONASTERISK);
    ADD_DEFINE(MB_ICONEXCLAMATION);
    ADD_DEFINE(MB_ICONHAND);
    ADD_DEFINE(MB_ICONQUESTION);
    return module;
}

Here is the call graph for this function:

static PyObject* sound_beep ( PyObject self,
PyObject args 
) [static]

Definition at line 100 of file winsound.c.

{
    int freq;
    int dur;
    BOOL ok;

    if (!PyArg_ParseTuple(args, "ii:Beep", &freq,  &dur))
        return NULL;

    if (freq < 37 || freq > 32767) {
        PyErr_SetString(PyExc_ValueError,
                        "frequency must be in 37 thru 32767");
        return NULL;
    }

    Py_BEGIN_ALLOW_THREADS
    ok = Beep(freq, dur);
    Py_END_ALLOW_THREADS
    if (!ok) {
        PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* sound_msgbeep ( PyObject self,
PyObject args 
) [static]

Definition at line 128 of file winsound.c.

{
    int x = MB_OK;
    if (!PyArg_ParseTuple(args, "|i:MessageBeep", &x))
        return NULL;
    MessageBeep(x);
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* sound_playsound ( PyObject s,
PyObject args 
) [static]

Definition at line 73 of file winsound.c.

{
    Py_UNICODE *wsound;
    int flags;
    int ok;

    if (PyArg_ParseTuple(args, "Zi:PlaySound", &wsound, &flags)) {
        if (flags & SND_ASYNC && flags & SND_MEMORY) {
            /* Sidestep reference counting headache; unfortunately this also
               prevent SND_LOOP from memory. */
            PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory");
            return NULL;
        }
        Py_BEGIN_ALLOW_THREADS
        ok = PlaySoundW(wsound, NULL, flags);
        Py_END_ALLOW_THREADS
        if (!ok) {
            PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
            return NULL;
        }
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}

Here is the call graph for this function:


Variable Documentation

struct PyMethodDef[] [static]
Initial value:
{
    {"PlaySound", sound_playsound, METH_VARARGS, sound_playsound_doc},
    {"Beep",      sound_beep,      METH_VARARGS, sound_beep_doc},
    {"MessageBeep", sound_msgbeep, METH_VARARGS, sound_msgbeep_doc},
    {NULL,  NULL}
}

Definition at line 138 of file winsound.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "winsound",
    sound_module_doc,
    -1,
    sound_methods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 161 of file winsound.c.