Commit d8bce981 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmime: Rewrite IDirectMusicGraph tools iteration.

parent 1e70dbcf
...@@ -86,12 +86,6 @@ typedef struct _DMUS_PRIVATE_TEMPO_ITEM { ...@@ -86,12 +86,6 @@ typedef struct _DMUS_PRIVATE_TEMPO_ITEM {
DMUS_IO_TEMPO_ITEM item; DMUS_IO_TEMPO_ITEM item;
} DMUS_PRIVATE_TEMPO_ITEM, *LPDMUS_PRIVATE_TEMPO_ITEM; } DMUS_PRIVATE_TEMPO_ITEM, *LPDMUS_PRIVATE_TEMPO_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 { typedef struct _DMUS_PRIVATE_TEMPO_PLAY_STATE {
DWORD dummy; DWORD dummy;
} DMUS_PRIVATE_TEMPO_PLAY_STATE, *LPDMUS_PRIVATE_TEMPO_PLAY_STATE; } DMUS_PRIVATE_TEMPO_PLAY_STATE, *LPDMUS_PRIVATE_TEMPO_PLAY_STATE;
......
...@@ -22,12 +22,18 @@ ...@@ -22,12 +22,18 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmime); WINE_DEFAULT_DEBUG_CHANNEL(dmime);
struct tool_entry
{
struct list entry;
IDirectMusicTool *tool;
};
struct IDirectMusicGraphImpl { struct IDirectMusicGraphImpl {
IDirectMusicGraph IDirectMusicGraph_iface; IDirectMusicGraph IDirectMusicGraph_iface;
struct dmobject dmobj; struct dmobject dmobj;
LONG ref; LONG ref;
WORD num_tools;
struct list Tools; struct list tools;
}; };
static inline IDirectMusicGraphImpl *impl_from_IDirectMusicGraph(IDirectMusicGraph *iface) static inline IDirectMusicGraphImpl *impl_from_IDirectMusicGraph(IDirectMusicGraph *iface)
...@@ -85,7 +91,19 @@ static ULONG WINAPI DirectMusicGraph_Release(IDirectMusicGraph *iface) ...@@ -85,7 +91,19 @@ static ULONG WINAPI DirectMusicGraph_Release(IDirectMusicGraph *iface)
TRACE("(%p): %ld\n", This, ref); TRACE("(%p): %ld\n", This, ref);
if (!ref) free(This); if (!ref)
{
struct tool_entry *entry, *next;
LIST_FOR_EACH_ENTRY_SAFE(entry, next, &This->tools, struct tool_entry, entry)
{
list_remove(&entry->entry);
IDirectMusicTool_Release(entry->tool);
free(entry);
}
free(This);
}
return ref; return ref;
} }
...@@ -97,80 +115,74 @@ static HRESULT WINAPI DirectMusicGraph_StampPMsg(IDirectMusicGraph *iface, DMUS_ ...@@ -97,80 +115,74 @@ static HRESULT WINAPI DirectMusicGraph_StampPMsg(IDirectMusicGraph *iface, DMUS_
return S_OK; return S_OK;
} }
static HRESULT WINAPI DirectMusicGraph_InsertTool(IDirectMusicGraph *iface, IDirectMusicTool* pTool, DWORD* pdwPChannels, DWORD cPChannels, LONG lIndex) static HRESULT WINAPI DirectMusicGraph_InsertTool(IDirectMusicGraph *iface, IDirectMusicTool *tool,
DWORD *channels, DWORD channel_count, LONG index)
{ {
IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface); IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface);
struct list* pEntry = NULL; struct tool_entry *entry, *next;
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 (!pTool)
return E_POINTER;
if (lIndex < 0) TRACE("(%p, %p, %p, %ld, %li)\n", This, tool, channels, channel_count, index);
lIndex = This->num_tools + lIndex;
pPrevEntry = &This->Tools; if (!tool) return E_POINTER;
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) LIST_FOR_EACH_ENTRY(next, &This->tools, struct tool_entry, entry)
break ; {
pPrevEntry = pEntry; if (next->tool == tool) return DMUS_E_ALREADY_EXISTS;
if (index-- <= 0) break;
} }
++This->num_tools; if (!(entry = calloc(1, sizeof(*entry)))) return E_OUTOFMEMORY;
pNewTool = calloc(1, sizeof(*pNewTool)); entry->tool = tool;
pNewTool->pTool = pTool; IDirectMusicTool_AddRef(tool);
pNewTool->dwIndex = lIndex; IDirectMusicTool_Init(tool, iface);
IDirectMusicTool_AddRef(pTool); list_add_before(&next->entry, &entry->entry);
IDirectMusicTool_Init(pTool, iface);
list_add_tail (pPrevEntry->next, &pNewTool->entry);
#if 0
DWORD dwNum = 0;
IDirectMusicTool8_GetMediaTypes(pTool, &dwNum);
#endif
return DS_OK; return S_OK;
} }
static HRESULT WINAPI DirectMusicGraph_GetTool(IDirectMusicGraph *iface, DWORD dwIndex, IDirectMusicTool** ppTool) static HRESULT WINAPI DirectMusicGraph_GetTool(IDirectMusicGraph *iface, DWORD index, IDirectMusicTool **ret_tool)
{ {
IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface); IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface);
struct list* pEntry = NULL; struct tool_entry *entry;
LPDMUS_PRIVATE_GRAPH_TOOL pIt = NULL;
TRACE("(%p, %ld, %p)\n", This, index, ret_tool);
TRACE("(%p, %ld, %p)\n", This, dwIndex, ppTool); if (!ret_tool) return E_POINTER;
LIST_FOR_EACH (pEntry, &This->Tools) LIST_FOR_EACH_ENTRY(entry, &This->tools, struct tool_entry, entry)
{ {
pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_GRAPH_TOOL, entry); if (!index--)
if (pIt->dwIndex == dwIndex)
{ {
*ppTool = pIt->pTool; *ret_tool = entry->tool;
if (*ppTool) IDirectMusicTool_AddRef(entry->tool);
IDirectMusicTool_AddRef(*ppTool);
return S_OK; return S_OK;
} }
if (pIt->dwIndex > dwIndex)
break ;
} }
return DMUS_E_NOT_FOUND; return DMUS_E_NOT_FOUND;
} }
static HRESULT WINAPI DirectMusicGraph_RemoveTool(IDirectMusicGraph *iface, IDirectMusicTool* pTool) static HRESULT WINAPI DirectMusicGraph_RemoveTool(IDirectMusicGraph *iface, IDirectMusicTool *tool)
{ {
IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface); IDirectMusicGraphImpl *This = impl_from_IDirectMusicGraph(iface);
FIXME("(%p, %p): stub\n", This, pTool); struct tool_entry *entry;
return S_OK;
TRACE("(%p, %p)\n", This, tool);
if (!tool) return E_POINTER;
LIST_FOR_EACH_ENTRY(entry, &This->tools, struct tool_entry, entry)
{
if (entry->tool == tool)
{
list_remove(&entry->entry);
IDirectMusicTool_Release(entry->tool);
free(entry);
return S_OK;
}
}
return DMUS_E_NOT_FOUND;
} }
static const IDirectMusicGraphVtbl DirectMusicGraphVtbl = static const IDirectMusicGraphVtbl DirectMusicGraphVtbl =
...@@ -260,7 +272,7 @@ HRESULT create_dmgraph(REFIID riid, void **ret_iface) ...@@ -260,7 +272,7 @@ HRESULT create_dmgraph(REFIID riid, void **ret_iface)
dmobject_init(&obj->dmobj, &CLSID_DirectMusicGraph, (IUnknown *)&obj->IDirectMusicGraph_iface); dmobject_init(&obj->dmobj, &CLSID_DirectMusicGraph, (IUnknown *)&obj->IDirectMusicGraph_iface);
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl; obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
list_init(&obj->Tools); list_init(&obj->tools);
hr = IDirectMusicGraph_QueryInterface(&obj->IDirectMusicGraph_iface, riid, ret_iface); hr = IDirectMusicGraph_QueryInterface(&obj->IDirectMusicGraph_iface, riid, ret_iface);
IDirectMusicGraph_Release(&obj->IDirectMusicGraph_iface); IDirectMusicGraph_Release(&obj->IDirectMusicGraph_iface);
......
...@@ -705,10 +705,10 @@ static void test_graph(void) ...@@ -705,10 +705,10 @@ static void test_graph(void)
ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicGraph_GetTool(graph, 0, NULL); hr = IDirectMusicGraph_GetTool(graph, 0, NULL);
todo_wine ok(hr == E_POINTER, "got %#lx\n", hr); ok(hr == E_POINTER, "got %#lx\n", hr);
hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool); hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool);
todo_wine ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
todo_wine ok(tool1 == tmp_tool, "got %p\n", tmp_tool); ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
if (hr == S_OK) IDirectMusicTool_Release(tmp_tool); if (hr == S_OK) IDirectMusicTool_Release(tmp_tool);
hr = IDirectMusicGraph_GetTool(graph, 1, &tmp_tool); hr = IDirectMusicGraph_GetTool(graph, 1, &tmp_tool);
ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
...@@ -723,24 +723,24 @@ static void test_graph(void) ...@@ -723,24 +723,24 @@ static void test_graph(void)
/* test removing the first tool */ /* test removing the first tool */
hr = IDirectMusicGraph_RemoveTool(graph, NULL); hr = IDirectMusicGraph_RemoveTool(graph, NULL);
todo_wine ok(hr == E_POINTER, "got %#lx\n", hr); ok(hr == E_POINTER, "got %#lx\n", hr);
hr = IDirectMusicGraph_RemoveTool(graph, tool1); hr = IDirectMusicGraph_RemoveTool(graph, tool1);
ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicGraph_RemoveTool(graph, tool1); hr = IDirectMusicGraph_RemoveTool(graph, tool1);
todo_wine ok(hr == DMUS_E_NOT_FOUND, "got %#lx\n", hr); ok(hr == DMUS_E_NOT_FOUND, "got %#lx\n", hr);
hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool); hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool);
todo_wine ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
ok(tool2 == tmp_tool, "got %p\n", tmp_tool); ok(tool2 == tmp_tool, "got %p\n", tmp_tool);
if (hr == S_OK) IDirectMusicTool_Release(tmp_tool); if (hr == S_OK) IDirectMusicTool_Release(tmp_tool);
hr = IDirectMusicGraph_GetTool(graph, 1, &tmp_tool); hr = IDirectMusicGraph_GetTool(graph, 1, &tmp_tool);
todo_wine ok(hr == DMUS_E_NOT_FOUND, "got %#lx\n", hr); ok(hr == DMUS_E_NOT_FOUND, "got %#lx\n", hr);
hr = IDirectMusicGraph_InsertTool(graph, tool1, NULL, 0, -1); hr = IDirectMusicGraph_InsertTool(graph, tool1, NULL, 0, -1);
todo_wine ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool); hr = IDirectMusicGraph_GetTool(graph, 0, &tmp_tool);
todo_wine ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
todo_wine ok(tool1 == tmp_tool, "got %p\n", tmp_tool); ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
if (hr == S_OK) IDirectMusicTool_Release(tmp_tool); if (hr == S_OK) IDirectMusicTool_Release(tmp_tool);
...@@ -810,7 +810,7 @@ static void test_graph(void) ...@@ -810,7 +810,7 @@ static void test_graph(void)
hr = IDirectMusicGraph_InsertTool(tmp_graph, tool1, NULL, 0, 0); hr = IDirectMusicGraph_InsertTool(tmp_graph, tool1, NULL, 0, 0);
ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicGraph_InsertTool(tmp_graph, tool2, NULL, 0, 0); hr = IDirectMusicGraph_InsertTool(tmp_graph, tool2, NULL, 0, 0);
todo_wine ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicGraph_StampPMsg(tmp_graph, &msg); hr = IDirectMusicGraph_StampPMsg(tmp_graph, &msg);
ok(hr == S_OK, "got %#lx\n", hr); ok(hr == S_OK, "got %#lx\n", hr);
ok(msg.pGraph == graph, "got %p\n", msg.pGraph); ok(msg.pGraph == graph, "got %p\n", msg.pGraph);
......
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