Update of /cvsroot/pywin32/pywin32/com/win32comext/directsound/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6405/com/win32comext/directsound/src
Added Files:
PyDSBCAPS.cpp PyDSBUFFERDESC.cpp PyDSCAPS.cpp
PyIDirectSound.cpp PyIDirectSound.h PyIDirectSoundBuffer.cpp
PyIDirectSoundBuffer.h PyIDirectSoundNotify.cpp
PyIDirectSoundNotify.h directsound.cpp directsound_pch.h
Log Message:
Added (some) DirectSound support.
The bulk is in com/win32comext/directsound, including a test directory with
a sample soundfile and a unittest-based test script.
Supported are:
- IDirectSound
- IDirectSoundBuffer
- IDirectSoundNotify.
Also added support for:
- WAVEFORMATEX (in PyWinTypes)
- DSBUFFERDESC
- DSBCAPS
- DSCAPS
- various constants used in these structures
Missing is:
- IDirectSoundCapture
- complete documentation
--- NEW FILE: PyIDirectSound.h ---
// This file declares the IDirectSound Interface for Python.
// ---------------------------------------------------
//
// Interface Declaration
class PyIDirectSound : public PyIUnknown
{
public:
MAKE_PYCOM_CTOR(PyIDirectSound);
static IDirectSound *GetI(PyObject *self);
static PyComTypeObject type;
// The Python methods
static PyObject *Initialize(PyObject *self, PyObject *args);
static PyObject *SetCooperativeLevel(PyObject *self, PyObject *args);
static PyObject *CreateSoundBuffer(PyObject *self, PyObject *args);
static PyObject *Compact(PyObject *self, PyObject *args);
static PyObject *GetCaps(PyObject *self, PyObject *args);
static PyObject *GetSpeakerConfig(PyObject *self, PyObject *args);
static PyObject *SetSpeakerConfig(PyObject *self, PyObject *args);
PyIDirectSound(IUnknown *pdisp);
~PyIDirectSound();
};
--- NEW FILE: PyIDirectSound.cpp ---
// This file implements the IDirectSound Interface for Python.
#include "directsound_pch.h"
#include "PySoundObjects.h"
#include "PyIDirectSound.h"
#include "PyIDirectSoundBuffer.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
// Interface Implementation
PyIDirectSound::PyIDirectSound(IUnknown *pdisp):
PyIUnknown(pdisp)
{
ob_type = &type;
}
PyIDirectSound::~PyIDirectSound()
{
}
/* static */ IDirectSound *PyIDirectSound::GetI(PyObject *self)
{
return (IDirectSound *)PyIUnknown::GetI(self);
}
// @pymethod |PyIDirectSound|Initialize|Description of Initialize.
PyObject *PyIDirectSound::Initialize(PyObject *self, PyObject *args)
{
PyObject *obGUID;
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "|O:Initialize", &obGUID) )
return NULL;
GUID guid;
LPGUID pguid = NULL;
if (!obGUID && obGUID != Py_None)
{
if (!PyWinObject_AsIID(obGUID, &guid))
return NULL;
pguid = &guid;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDS->Initialize(pguid);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Initialize", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSound|SetCooperativeLevel|Description of SetCooperativeLevel.
PyObject *PyIDirectSound::SetCooperativeLevel(PyObject *self, PyObject *args)
{
int level;
PyObject *obHWND = NULL;
HWND hwnd;
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "Oi:SetCooperativeLevel", &obHWND, &level) )
return NULL;
if (obHWND == Py_None)
{
hwnd = GetForegroundWindow();
if (hwnd == NULL)
{
hwnd = GetDesktopWindow();
}
}
else if (PyInt_Check(obHWND))
{
hwnd = (HWND)PyInt_AS_LONG(obHWND);
}
else
{
PyErr_SetString(PyExc_TypeError, "argument 1 must be a window handle or None");
return NULL;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDS->SetCooperativeLevel(hwnd, level);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetCooperativeLevel", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSound|CreateSoundBuffer|Description of CreateSoundBuffer.
PyObject *PyIDirectSound::CreateSoundBuffer(PyObject *self, PyObject *args)
{
PyObject *obDSBD = NULL;
PyObject *obUnk = NULL;
IUnknown *pUnkIn = NULL;
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "O|O:CreateSoundBuffer", &obDSBD, &obUnk) )
return NULL;
if (!PyDSBUFFERDESC_Check(obDSBD)) {
PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type PyDSBUFFERDESC");
return NULL;
}
if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnkIn, TRUE)) {
return NULL;
}
DSBUFFERDESC *pdsbd = &((PyDSBUFFERDESC*)obDSBD)->m_dsbd;
HRESULT hr;
IDirectSoundBuffer *buffer;
PY_INTERFACE_PRECALL;
hr = pIDS->CreateSoundBuffer(pdsbd, &buffer, pUnkIn);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("CreateSoundBuffer", hr);
return NULL;
}
PyIDirectSoundBuffer *rc = new PyIDirectSoundBuffer(buffer);
Py_INCREF(self);
rc->m_DS = self;
return rc;
}
// @pymethod |PyIDirectSound|GetCaps|Description of GetCaps.
PyObject *PyIDirectSound::GetCaps(PyObject *self, PyObject *args)
{
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCaps") )
return NULL;
HRESULT hr;
PyDSCAPS *caps = new PyDSCAPS();
PY_INTERFACE_PRECALL;
hr = pIDS->GetCaps(caps->GetCAPS());
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCaps", hr);
return NULL;
}
Py_INCREF(caps);
return caps;
}
// @pymethod |PyIDirectSound|Compact|Description of Compact.
PyObject *PyIDirectSound::Compact(PyObject *self, PyObject *args)
{
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":Compact") )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDS->Compact();
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCaps", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSound|GetSpeakerConfig|Description of GetSpeakerConfig.
PyObject *PyIDirectSound::GetSpeakerConfig(PyObject *self, PyObject *args)
{
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetSpeakerConfig") )
return NULL;
HRESULT hr;
DWORD config;
PY_INTERFACE_PRECALL;
hr = pIDS->GetSpeakerConfig(&config);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetSpeakerConfig", hr);
return NULL;
}
return PyInt_FromLong(config);
}
// @pymethod |PyIDirectSound|SetSpeakerConfig|Description of SetSpeakerConfig.
PyObject *PyIDirectSound::SetSpeakerConfig(PyObject *self, PyObject *args)
{
DWORD config;
IDirectSound *pIDS = GetI(self);
if ( pIDS == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:SetSpeakerConfig", &config) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDS->SetSpeakerConfig(config);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetSpeakerConfig", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @object PyIDirectSound|Description of the interface
static struct PyMethodDef PyIDirectSound_methods[] =
{
{ "Initialize", PyIDirectSound::Initialize, 1 }, // @pymeth Initialize|Description of Initialize.
{ "SetCooperativeLevel", PyIDirectSound::SetCooperativeLevel, 1 }, // @pymeth SetCooperativeLevel|Description of SetCooperativeLevel.
{ "CreateSoundBuffer", PyIDirectSound::CreateSoundBuffer, 1 }, // @pymeth CreateSoundBuffer|Description of CreateSoundBuffer.
{ "GetCaps", PyIDirectSound::GetCaps, 1 }, // @pymeth GetCaps|Description of GetCaps.
{ "Compact", PyIDirectSound::Compact, 1 }, // @pymeth Compact|Description of Compact.
{ NULL }
};
PyComTypeObject PyIDirectSound::type("PyIDirectSound",
&PyIUnknown::type,
sizeof(PyIDirectSound),
PyIDirectSound_methods,
GET_PYCOM_CTOR(PyIDirectSound));
--- NEW FILE: PyIDirectSoundBuffer.cpp ---
// This file implements the IDirectSound Interface for Python.
#include "directsound_pch.h"
#include "PySoundObjects.h"
#include "PyIDirectSoundBuffer.h"
#include "PyIDirectSoundNotify.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
// Interface Implementation
PyIDirectSoundBuffer::PyIDirectSoundBuffer(IUnknown *pdisp):
PyIUnknown(pdisp), m_DS(NULL)
{
ob_type = &type;
}
PyIDirectSoundBuffer::~PyIDirectSoundBuffer()
{
if (m_DS)
Py_DECREF(m_DS);
}
/* static */ IDirectSoundBuffer *PyIDirectSoundBuffer::GetI(PyObject *self)
{
return (IDirectSoundBuffer*)PyIUnknown::GetI(self);
}
/* static */ PyObject *PyIDirectSoundBuffer::QueryInterface(PyObject *self, PyObject *args)
{
PyObject *obiid;
PyObject *obUseIID = NULL;
if (!PyArg_ParseTuple(args, "O|O:QueryInterface", &obiid, &obUseIID ))
return NULL;
PyObject *rc = PyIUnknown::QueryInterface(self, args);
// Special treatment for PyIDirectSoundNotify
// This is a workaround for a reference counting bug in IDirectSound:
// If IDirectSound->Release() is called before IDirectSoundBuffer->Release()
// or IDirectSoundNotify->->Release(), we will get an Access Violation
// We work around this by manipulating the reference count on the Python objects
// that encapsulate them
if (PyIBase::is_object(rc, &PyIDirectSoundNotify::type))
{
PyIDirectSoundNotify *notify = (PyIDirectSoundNotify*)rc;
PyIDirectSoundBuffer *me = (PyIDirectSoundBuffer*)self;
Py_INCREF(me->m_DS);
notify->m_DS = me->m_DS;
}
return rc;
}
// @pymethod |PyIDirectSoundBuffer|GetCaps|Description of GetCaps.
PyObject *PyIDirectSoundBuffer::GetCaps(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCaps") )
return NULL;
HRESULT hr;
PyDSBCAPS *caps = new PyDSBCAPS();
PY_INTERFACE_PRECALL;
hr = pIDSB->GetCaps(caps->GetCAPS());
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCaps", hr);
return NULL;
}
Py_INCREF(caps);
return caps;
}
// @pymethod |PyIDirectSoundBuffer|GetFormat|Description of GetFormat.
PyObject *PyIDirectSoundBuffer::GetFormat(PyObject *self, PyObject *args)
{
int level;
HWND hwnd;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetFormat", &hwnd, &level) )
return NULL;
HRESULT hr;
PyWAVEFORMATEX *wfx = new PyWAVEFORMATEX();
PY_INTERFACE_PRECALL;
// We don't support getting more than standard wave headers
hr = pIDSB->GetFormat(&wfx->m_wfx, sizeof(WAVEFORMATEX), NULL);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetFormat", hr);
return NULL;
}
Py_INCREF(wfx);
return wfx;
}
// @pymethod |PyIDirectSoundBuffer|GetStatus|Description of GetStatus.
PyObject *PyIDirectSoundBuffer::GetStatus(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetStatus") )
return NULL;
HRESULT hr;
DWORD dwStatus;
PY_INTERFACE_PRECALL;
hr = pIDSB->GetStatus(&dwStatus);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetStatus", hr);
return NULL;
}
return PyInt_FromLong(dwStatus);
}
// @pymethod |PyIDirectSoundBuffer|SetFormat|Description of SetFormat.
PyObject *PyIDirectSoundBuffer::SetFormat(PyObject *self, PyObject *args)
{
PyObject *obWfx;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "O:SetFormat", &obWfx) )
return NULL;
if (!PyWAVEFORMATEX_Check(obWfx)) {
PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type PyWAVEFORMATEX");
return NULL;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->SetFormat(&((PyWAVEFORMATEX*)obWfx)->m_wfx);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetFormat", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|Initialize|Description of Initialize.
PyObject *PyIDirectSoundBuffer::Initialize(PyObject *self, PyObject *args)
{
PyObject *obDSBD = NULL;
PyObject *obDS = NULL;
IDirectSound *pIDS = NULL;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "OO:Initialize", &obDS, &obDSBD) )
return NULL;
// Todo - check and initialize pIDS
if (!PyDSBUFFERDESC_Check(obDSBD)) {
PyErr_SetString(PyExc_TypeError, "Argument 2 must be of type PyDSBUFFERDESC");
return NULL;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->Initialize(pIDS, &((PyDSBUFFERDESC*)obDSBD)->m_dsbd);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Initialize", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|Restore|Description of Initialize.
PyObject *PyIDirectSoundBuffer::Restore(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":Restore") )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->Restore();
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Restore", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|GetCurrentPosition|Description of GetCurrentPosition.
PyObject *PyIDirectSoundBuffer::GetCurrentPosition(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCurrentPosition") )
return NULL;
HRESULT hr;
DWORD dwPlay = 0, dwWrite = 0;
PY_INTERFACE_PRECALL;
hr = pIDSB->GetCurrentPosition(&dwPlay, &dwWrite);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCurrentPosition", hr);
return NULL;
}
PyObject *result = PyTuple_New(2);
if (!result)
return NULL;
PyTuple_SetItem(result, 0, PyInt_FromLong(dwPlay));
PyTuple_SetItem(result, 1, PyInt_FromLong(dwWrite));
return result;
}
// @pymethod |PyIDirectSoundBuffer|Play|Description of Play.
PyObject *PyIDirectSoundBuffer::Play(PyObject *self, PyObject *args)
{
DWORD dwFlags;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:Play", &dwFlags) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->Play(0, 0, dwFlags);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Play", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|SetCurrentPosition|Description of SetCurrentPosition.
PyObject *PyIDirectSoundBuffer::SetCurrentPosition(PyObject *self, PyObject *args)
{
DWORD dwNewPosition;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:SetCurrentPosition", &dwNewPosition) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->SetCurrentPosition(dwNewPosition);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetCurrentPosition", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|Stop|Description of Stop.
PyObject *PyIDirectSoundBuffer::Stop(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":Stop") )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->Stop();
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Stop", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|Update|Description of Update.
PyObject *PyIDirectSoundBuffer::Update(PyObject *self, PyObject *args)
{
DWORD dwWriteCursor = 0;
DWORD dwFlags = 0;
PyObject *obData = NULL;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "iS|i:Update", &dwWriteCursor, &obData, &dwFlags) )
return NULL;
HRESULT hr;
LPVOID lpAudioPtr1 = NULL;
DWORD dwAudioBytes1 = 0;
LPVOID lpAudioPtr2 = NULL;
DWORD dwAudioBytes2 = 0;
PY_INTERFACE_PRECALL;
hr = pIDSB->Lock(dwWriteCursor, PyString_Size(obData), &lpAudioPtr1, &dwAudioBytes1,
&lpAudioPtr2, &dwAudioBytes2, dwFlags);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Update(Lock)", hr);
return NULL;
}
// The play buffer is circular, so we may get two pointers and have to
// do the wrap-around ourselves.
// Raise error if assumption isn't met
if (dwAudioBytes1 + dwAudioBytes2 != PyString_Size(obData)) {
PY_INTERFACE_PRECALL;
hr = pIDSB->Unlock(lpAudioPtr1, dwAudioBytes1, lpAudioPtr2, dwAudioBytes2);
PY_INTERFACE_POSTCALL;
PyErr_SetString(PyExc_RuntimeError, "Size mismatch from Unlock");
return NULL;
}
memcpy(lpAudioPtr1, PyString_AsString(obData), dwAudioBytes1);
if (dwAudioBytes2) {
memcpy(lpAudioPtr2, PyString_AsString(obData) + dwAudioBytes1, dwAudioBytes2);
}
{
// need extra block for local variables from PY_INTERFACE_UPCALL macro
PY_INTERFACE_PRECALL;
hr = pIDSB->Unlock(lpAudioPtr1, dwAudioBytes1, lpAudioPtr2, dwAudioBytes2);
PY_INTERFACE_POSTCALL;
}
if (FAILED(hr)) {
PyWin_SetAPIError("Update(Unlock)", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|GetFrequency|Description of GetFrequency.
PyObject *PyIDirectSoundBuffer::GetFrequency(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetFrequency") )
return NULL;
HRESULT hr;
DWORD dwFrequency;
PY_INTERFACE_PRECALL;
hr = pIDSB->GetFrequency(&dwFrequency);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetFrequency", hr);
return NULL;
}
return PyInt_FromLong(dwFrequency);
}
// @pymethod |PyIDirectSoundBuffer|GetPan|Description of GetPan.
PyObject *PyIDirectSoundBuffer::GetPan(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetPan") )
return NULL;
HRESULT hr;
LONG pan;
PY_INTERFACE_PRECALL;
hr = pIDSB->GetPan(&pan);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetPan", hr);
return NULL;
}
return PyInt_FromLong(pan);
}
// @pymethod |PyIDirectSoundBuffer|GetVolume|Description of GetVolume.
PyObject *PyIDirectSoundBuffer::GetVolume(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetVolume") )
return NULL;
HRESULT hr;
LONG pan;
PY_INTERFACE_PRECALL;
hr = pIDSB->GetVolume(&pan);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetVolume", hr);
return NULL;
}
return PyInt_FromLong(pan);
}
// @pymethod |PyIDirectSoundBuffer|SetFrequency|Description of SetFrequency.
PyObject *PyIDirectSoundBuffer::SetFrequency(PyObject *self, PyObject *args)
{
DWORD dwNewFrequency;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:SetFrequency", &dwNewFrequency) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->SetFrequency(dwNewFrequency);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetFrequency", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|SetPan|Description of SetPan.
PyObject *PyIDirectSoundBuffer::SetPan(PyObject *self, PyObject *args)
{
LONG dwNewPan;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:SetPan", &dwNewPan) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->SetPan(dwNewPan);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetPan", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundBuffer|SetVolume|Description of SetVolume.
PyObject *PyIDirectSoundBuffer::SetVolume(PyObject *self, PyObject *args)
{
LONG dwNewVolume;
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:SetVolume", &dwNewVolume) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSB->SetVolume(dwNewVolume);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("SetVolume", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @object PyIDirectSoundBuffer|Description of the interface
static struct PyMethodDef PyIDirectSoundBuffer_methods[] =
{
{ "QueryInterface", PyIDirectSoundBuffer::QueryInterface, 1 },
{ "GetCaps", PyIDirectSoundBuffer::GetCaps, 1 }, // @pymeth Initialize|Description of Initialize.
{ "GetFormat", PyIDirectSoundBuffer::GetFormat, 1 }, // @pymeth SetCooperativeLevel|Description of SetCooperativeLevel.
{ "GetStatus", PyIDirectSoundBuffer::GetStatus, 1 }, // @pymeth GetStatus|Description of GetStatus.
{ "SetFormat", PyIDirectSoundBuffer::SetFormat, 1 }, // @pymeth GetCaps|Description of GetCaps.
{ "Initialize", PyIDirectSoundBuffer::Initialize, 1 }, // @pymeth Initialize|Description of GetCaps.
{ "Restore", PyIDirectSoundBuffer::Restore, 1 }, // @pymeth Restore|Description of Restore.
{ "GetCurrentPosition", PyIDirectSoundBuffer::GetCurrentPosition, 1 }, // @pymeth GetCurrentPosition|Description of GetCaps.
{ "Play", PyIDirectSoundBuffer::Play, 1 }, // @pymeth Play|Description of GetCaps.
{ "SetCurrentPosition", PyIDirectSoundBuffer::SetCurrentPosition, 1 }, // @pymeth SetCurrentPosition|Description of GetCaps.
{ "Stop", PyIDirectSoundBuffer::Stop, 1 }, // @pymeth Stop|Description of GetCaps.
{ "Update", PyIDirectSoundBuffer::Update, 1 }, // @pymeth Unlock|Description of Unlock.
{ "GetFrequency", PyIDirectSoundBuffer::GetFrequency, 1 }, // @pymeth GetFrequency|Description of GetCaps.
{ "GetPan", PyIDirectSoundBuffer::GetPan, 1 }, // @pymeth GetPan|Description of GetCaps.
{ "GetVolume", PyIDirectSoundBuffer::GetVolume, 1 }, // @pymeth GetVolume|Description of GetCaps.
{ "SetFrequency", PyIDirectSoundBuffer::SetFrequency, 1 }, // @pymeth SetFrequency|Description of GetCaps.
{ "SetPan", PyIDirectSoundBuffer::SetPan, 1 }, // @pymeth SetPan|Description of GetCaps.
{ "SetVolume", PyIDirectSoundBuffer::SetVolume, 1 }, // @pymeth SetVolume|Description of GetCaps.
{ NULL }
};
PyComTypeObject PyIDirectSoundBuffer::type("PyIDirectSoundBuffer",
&PyIUnknown::type,
sizeof(PyIDirectSoundBuffer),
PyIDirectSoundBuffer_methods,
GET_PYCOM_CTOR(PyIDirectSoundBuffer));
--- NEW FILE: PyDSCAPS.cpp ---
//
// @doc
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "PySoundObjects.h"
#include "structmember.h"
#include "directsound_pch.h"
// @pymethod <o PyDSCAPS>|pywintypes|DSCAPS|Creates a new DSCAPS object
PyObject *PyWinMethod_NewDSCAPS(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":DSCAPS"))
return NULL;
return new PyDSCAPS();
}
PyObject *PyWinObject_FromDSCAPS(const DSCAPS &caps)
{
return new PyDSCAPS(caps);
}
BOOL PyWinObject_AsDSCAPS(PyObject *ob, DSCAPS **ppDSCAPS, BOOL bNoneOK /*= TRUE*/)
{
if (bNoneOK && ob==Py_None) {
*ppDSCAPS = NULL;
} else if (!PyDSCAPS_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "The object is not a PyDSCAPS object");
return FALSE;
} else {
PyDSCAPS *pycaps= (PyDSCAPS *)ob;
*ppDSCAPS = pycaps->GetCAPS();
}
return TRUE;
}
// @object PyDSCAPS|A Python object, representing a DSCAPS structure
static struct PyMethodDef PyDSCAPS_methods[] = {
{NULL}
};
PyTypeObject PyDSCAPSType =
{
PyObject_HEAD_INIT(&PyType_Type)
0,
"PyDSCAPSType",
sizeof(PyDSCAPSType),
0,
PyDSCAPS::deallocFunc,
0, // tp_print;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0,
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr,
PyObject_GenericSetAttr,
0, // tp_as_buffer;
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags;
0, // tp_doc; /* Documentation string */
0, // traverseproc tp_traverse;
0, // tp_clear;
0, // tp_richcompare;
0, // tp_weaklistoffset;
0, // tp_iter
0, // iternextfunc tp_iternext
0, // methods
PyDSCAPS::members,
0, // tp_getset;
0, // tp_base;
0, // tp_dict;
0, // tp_descr_get;
0, // tp_descr_set;
0, // tp_dictoffset;
0, // tp_init;
0, // tp_alloc;
0 // newfunc tp_new;
};
#define OFF(e) offsetof(PyDSCAPS, e)
/*static*/ struct PyMemberDef PyDSCAPS::members[] = {
{"dwFlags", T_INT, OFF(m_caps.dwFlags), 0, "Specifies device capabilities."},
// @prop integer|dwFlags|Specifies device capabilities.
{"dwMinSecondarySampleRate", T_INT, OFF(m_caps.dwMinSecondarySampleRate), 0, "Minimum sample rate supported by this device's hardware secondary sound buffers."},
// @prop integer|dwMinSecondarySampleRate|Minimum sample rate supported by this device's hardware secondary sound buffers.
{"dwMaxSecondarySampleRate", T_INT, OFF(m_caps.dwMaxSecondarySampleRate), 0, "Maximum sample rate supported by this device's hardware secondary sound buffers."},
// @prop integer|dwMaxSecondarySampleRate|Maximum sample rate supported by this device's hardware secondary sound buffers.
{"dwPrimaryBuffers", T_INT, OFF(m_caps.dwPrimaryBuffers), 0, "Number of primary buffers supported. This value will always be 1."},
// @prop integer|dwPrimaryBuffers|Number of primary buffers supported. This value will always be 1.
{"dwMaxHwMixingAllBuffers", T_INT, OFF(m_caps.dwMaxHwMixingAllBuffers), 0, "Specifies the total number of buffers that can be mixed in hardware. This member can be less than the sum of dwMaxHwMixingStaticBuffers and dwMaxHwMixingStreamingBuffers. Resource tradeoffs frequently occur."},
// @prop integer|dwMaxHwMixingAllBuffers|Specifies the total number of buffers that can be mixed in hardware. This member can be less than the sum of dwMaxHwMixingStaticBuffers and dwMaxHwMixingStreamingBuffers. Resource tradeoffs frequently occur.
{"dwMaxHwMixingStaticBuffers", T_INT, OFF(m_caps.dwMaxHwMixingStaticBuffers), 0, "Specifies the maximum number of static sound buffers."},
// @prop integer|dwMaxHwMixingStaticBuffers|Specifies the maximum number of static sound buffers.
{"dwMaxHwMixingStreamingBuffers", T_INT, OFF(m_caps.dwMaxHwMixingStreamingBuffers), 0, "Specifies the maximum number of streaming sound buffers."},
// @prop integer|dwMaxHwMixingStreamingBuffers|Specifies the maximum number of streaming sound buffers.
{"dwFreeHwMixingAllBuffers", T_INT, OFF(m_caps.dwFreeHwMixingAllBuffers), 0, "Description of the free mixing hardware capabilities of the device. An application can use these values to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing this value to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined. "},
// @prop integer|dwFreeHwMixingAllBuffers|Description of the free hardware mixing capabilities of the device. An application can use this value to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing these values to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined.
{"dwFreeHwMixingStaticBuffers", T_INT, OFF(m_caps.dwFreeHwMixingStaticBuffers), 0, "Description of the free hardware mixing capabilities of the device. An application can use this value to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing these values to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined."},
// @prop integer|dwFreeHwMixingStaticBuffers|Description of the free hardware mixing capabilities of the device. An application can use this value to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing these values to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined.
{"dwFreeHwMixingStreamingBuffers", T_INT, OFF(m_caps.dwFreeHwMixingStreamingBuffers), 0, "Description of the free hardware mixing capabilities of the device. An application can use this value to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing these values to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined."},
// @prop integer|dwFreeHwMixingStreamingBuffers|Description of the free hardware mixing capabilities of the device. An application can use this value to determine whether hardware resources are available for allocation to a secondary sound buffer. Also, by comparing these values to the members that specify maximum mixing capabilities, the resources that are already allocated can be determined.
{"dwMaxHw3DAllBuffers", T_INT, OFF(m_caps.dwMaxHw3DAllBuffers), 0, "Description of the hardware 3-D positional capabilities of the device."},
// @prop integer|dwMaxHw3DAllBuffers|Description of the hardware 3-D positional capabilities of the device.
{"dwMaxHw3DStaticBuffers", T_INT, OFF(m_caps.dwMaxHw3DStaticBuffers), 0, "Description of the hardware 3-D positional capabilities of the device. "},
// @prop integer|dwMaxHw3DStaticBuffers|Description of the hardware 3-D positional capabilities of the device.
{"dwMaxHw3DStreamingBuffers", T_INT, OFF(m_caps.dwMaxHw3DStreamingBuffers), 0, "Description of the hardware 3-D positional capabilities of the device."},
// @prop integer|dwMaxHw3DStreamingBuffers|Description of the hardware 3-D positional capabilities of the device.
{"dwFreeHw3DAllBuffers", T_INT, OFF(m_caps.dwFreeHw3DAllBuffers), 0, "Description of the free, or unallocated, hardware 3-D positional capabilities of the device."},
// @prop integer|dwFreeHw3DAllBuffers|Description of the free, or unallocated, hardware 3-D positional capabilities of the device.
{"dwFreeHw3DStaticBuffers", T_INT, OFF(m_caps.dwFreeHw3DStaticBuffers), 0, "Description of the free, or unallocated, hardware 3-D positional capabilities of the device."},
// @prop integer|dwFreeHw3DStaticBuffers|Description of the free, or unallocated, hardware 3-D positional capabilities of the device.
{"dwFreeHw3DStreamingBuffers", T_INT, OFF(m_caps.dwFreeHw3DStreamingBuffers), 0, "Description of ...
[truncated message content] |