Commit ca7ee477 authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

Better handling of User IDirectMusicTools.

parent 40dd9692
......@@ -165,6 +165,12 @@ typedef struct _DMUS_PRIVATE_SEGMENT_ITEM {
WCHAR wszName[DMUS_MAX_NAME];
} DMUS_PRIVATE_SEGMENT_ITEM, *LPDMUS_PRIVATE_SEGMENT_ITEM;
typedef struct _DMUS_PRIVATE_GRAPH_TOOL {
struct list entry; /* for listing elements */
DWORD dwIndex;
IDirectMusicTool* pTool;
} DMUS_PRIVATE_GRAPH_TOOL, *LPDMUS_PRIVATE_GRAPH_TOOL;
typedef struct _DMUS_PRIVATE_TEMPO_PLAY_STATE {
DWORD dummy;
} DMUS_PRIVATE_TEMPO_PLAY_STATE, *LPDMUS_PRIVATE_TEMPO_PLAY_STATE;
......@@ -385,9 +391,8 @@ struct IDirectMusicGraphImpl {
/* IDirectMusicGraphImpl fields */
LPDMUS_OBJECTDESC pDesc;
IDirectMusicTool8Impl* pFirst;
IDirectMusicTool8Impl* pLast;
WORD num_tools;
struct list Tools;
};
/* IUnknown: */
......@@ -478,8 +483,6 @@ struct IDirectMusicTool8Impl {
DWORD ref;
/* IDirectMusicTool8Impl fields */
IDirectMusicTool8Impl* pPrev;
IDirectMusicTool8Impl* pNext;
};
/* IUnknown: */
......
......@@ -98,65 +98,75 @@ HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicGraph_StampPMsg (LPDIRECTMUSICG
}
HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicGraph_InsertTool (LPDIRECTMUSICGRAPH iface, IDirectMusicTool* pTool, DWORD* pdwPChannels, DWORD cPChannels, LONG lIndex) {
int i;
IDirectMusicTool8Impl* p;
IDirectMusicTool8Impl* toAdd = (IDirectMusicTool8Impl*) pTool;
ICOM_THIS_MULTI(IDirectMusicGraphImpl, GraphVtbl, iface);
HRESULT hr;
struct list* pEntry = NULL;
struct list* pPrevEntry = NULL;
LPDMUS_PRIVATE_GRAPH_TOOL pIt = NULL;
LPDMUS_PRIVATE_GRAPH_TOOL pNewTool = NULL;
FIXME("(%p, %p, %p, %ld, %li): use of pdwPChannels\n", This, pTool, pdwPChannels, cPChannels, lIndex);
if (0 == This->num_tools) {
This->pFirst = This->pLast = toAdd;
toAdd->pPrev = toAdd->pNext = NULL;
} else if (lIndex == 0 || lIndex <= -This->num_tools) {
This->pFirst->pPrev = toAdd;
toAdd->pNext = This->pFirst;
toAdd->pPrev = NULL;
This->pFirst = toAdd;
} else if (lIndex < 0) {
p = This->pLast;
for (i = 0; i < -lIndex; ++i) {
p = p->pPrev;
}
toAdd->pNext = p->pNext;
if (p->pNext) p->pNext->pPrev = toAdd;
p->pNext = toAdd;
toAdd->pPrev = p;
} else if (lIndex >= This->num_tools) {
This->pLast->pNext = toAdd;
toAdd->pPrev = This->pLast;
toAdd->pNext = NULL;
This->pLast = toAdd;
} else if (lIndex > 0) {
p = This->pFirst;
for (i = 0; i < lIndex; ++i) {
p = p->pNext;
}
toAdd->pPrev = p->pPrev;
if (p->pPrev) p->pPrev->pNext = toAdd;
p->pPrev = toAdd;
toAdd->pNext = p;
if (NULL == pTool) {
return E_POINTER;
}
if (0 > lIndex) {
lIndex = This->num_tools + lIndex;
}
pPrevEntry = &This->Tools;
LIST_FOR_EACH (pEntry, &This->Tools) {
pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_GRAPH_TOOL, entry);
if (pIt->dwIndex == lIndex) {
return DMUS_E_ALREADY_EXISTS;
}
if (pIt->dwIndex > lIndex) {
break ;
}
pPrevEntry = pEntry;
}
++This->num_tools;
pNewTool = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_GRAPH_TOOL));
pNewTool->pTool = pTool;
pNewTool->dwIndex = lIndex;
IDirectMusicTool8_AddRef(pTool);
hr = IDirectMusicTool8_Init(pTool, iface);
list_add_tail (pPrevEntry->next, &pNewTool->entry);
#if 0
DWORD dwNum = 0;
hr = IDirectMusicTool8_GetMediaTypes(pTool, &dwNum);
#endif
return DS_OK;
}
HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicGraph_GetTool (LPDIRECTMUSICGRAPH iface, DWORD dwIndex, IDirectMusicTool** ppTool) {
int i;
IDirectMusicTool8Impl* p = NULL;
ICOM_THIS_MULTI(IDirectMusicGraphImpl, GraphVtbl, iface);
struct list* pEntry = NULL;
LPDMUS_PRIVATE_GRAPH_TOOL pIt = NULL;
FIXME("(%p, %ld, %p): stub\n", This, dwIndex, ppTool);
p = This->pFirst;
for (i = 0; i < dwIndex && i < This->num_tools; ++i) {
p = p->pNext;
}
*ppTool = (IDirectMusicTool*) p;
LIST_FOR_EACH (pEntry, &This->Tools) {
pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_GRAPH_TOOL, entry);
if (pIt->dwIndex == dwIndex) {
*ppTool = pIt->pTool;
if (NULL != *ppTool) {
IDirectMusicTool8Impl_AddRef((LPDIRECTMUSICTOOL8) *ppTool);
}
return S_OK;
}
if (pIt->dwIndex > dwIndex) {
break ;
}
}
return DMUS_E_NOT_FOUND;
}
HRESULT WINAPI IDirectMusicGraphImpl_IDirectMusicGraph_RemoveTool (LPDIRECTMUSICGRAPH iface, IDirectMusicTool* pTool) {
......@@ -602,6 +612,7 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicGraphImpl (LPCGUID lpcGUID, LPVOID* ppobj
obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicGraph, sizeof (CLSID));
obj->ref = 0; /* will be inited by QueryInterface */
list_init (&obj->Tools);
return IDirectMusicGraphImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment