Exemplo n.º 1
0
static PyObject*
_context_createsources (PyObject *self, PyObject *args)
{
    unsigned int bufnum;

    ASSERT_CONTEXT_IS_CURRENT(self, NULL);
    if (!UintFromObj (args, &bufnum))
        return NULL;
    return PySources_New (self, (ALsizei) bufnum);
}
Exemplo n.º 2
0
Arquivo: base.c Projeto: Mrhjx2/pygame
static int
UintFromObjIndex (PyObject* obj, int _index, Uint32* val)
{
    int result = 0;
    PyObject* item;
    item = PySequence_GetItem (obj, _index);
    if (item)
    {
        result = UintFromObj (item, val);
        Py_DECREF (item);
    }
    return result;
}
Exemplo n.º 3
0
static PyObject*
_sources_action (PyObject *self, PyObject *args, SourcesAction action)
{
    unsigned int source;

    if (!CONTEXT_IS_CURRENT (((PySources*)self)->context))
    {
        PyErr_SetString (PyExc_PyGameError, "source context is not current");
        return NULL;
    }

    if (PySequence_Check (args))
    {
        ALuint *sources;
        Py_ssize_t i;
        Py_ssize_t len = PySequence_Size (args);

        if (len > ((PySources*)self)->count)
        {
            PyErr_SetString (PyExc_ValueError,
                             "sequence size exceeds the available sources");
            return NULL;
        }
        sources = PyMem_New (ALuint, (ALsizei) len);
        if (!sources)
            return NULL;
        for (i = 0; i < len; i++)
        {
            if (!UintFromSeqIndex (args, i, &source))
            {
                PyMem_Free (sources);
                return NULL;
            }
            sources[i] = source;
        }
        CLEAR_ALERROR_STATE ();
        switch (action)
        {
        case PLAY:
            alSourcePlayv ((ALsizei) len, sources);
            break;
        case PAUSE:
            alSourcePausev ((ALsizei) len, sources);
            break;
        case STOP:
            alSourceStopv ((ALsizei) len, sources);
            break;
        case REWIND:
            alSourceRewindv ((ALsizei) len, sources);
            break;
        default:
            break;
        }
        PyMem_Free (sources);
        if (SetALErrorException (alGetError (), 0))
            return NULL;
        Py_RETURN_NONE;
    }
    else if (UintFromObj (args, &source))
    {
        CLEAR_ALERROR_STATE ();
        switch (action)
        {
        case PLAY:
            alSourcePlay ((ALuint)source);
            break;
        case PAUSE:
            alSourcePause ((ALuint)source);
            break;
        case STOP:
            alSourceStop ((ALuint)source);
            break;
        case REWIND:
            alSourceRewind ((ALuint)source);
            break;
        }
        if (SetALErrorException (alGetError (), 0))
            return NULL;
        Py_RETURN_NONE;
    }

    PyErr_SetString (PyExc_TypeError,
                     "argument must be a sequence or positive integer");
    return NULL;
}