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 {
DMUS_IO_TEMPO_ITEM 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 {
DWORD dummy;
} DMUS_PRIVATE_TEMPO_PLAY_STATE, *LPDMUS_PRIVATE_TEMPO_PLAY_STATE;
......
......@@ -22,12 +22,18 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmime);
struct tool_entry
{
struct list entry;
IDirectMusicTool *tool;
};
struct IDirectMusicGraphImpl {
IDirectMusicGraph IDirectMusicGraph_iface;
struct dmobject dmobj;
LONG ref;
WORD num_tools;
struct list Tools;
struct list tools;
};
static inline IDirectMusicGraphImpl *impl_from_IDirectMusicGraph(IDirectMusicGraph *iface)
......@@ -85,7 +91,19 @@ static ULONG WINAPI DirectMusicGraph_Release(IDirectMusicGraph *iface)
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;
}
......@@ -97,80 +115,74 @@ static HRESULT WINAPI DirectMusicGraph_StampPMsg(IDirectMusicGraph *iface, DMUS_
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);
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 (!pTool)
return E_POINTER;
struct tool_entry *entry, *next;
if (lIndex < 0)
lIndex = This->num_tools + lIndex;
TRACE("(%p, %p, %p, %ld, %li)\n", This, tool, channels, channel_count, index);
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 (!tool) return E_POINTER;
if (pIt->dwIndex > lIndex)
break ;
pPrevEntry = pEntry;
LIST_FOR_EACH_ENTRY(next, &This->tools, struct tool_entry, entry)
{
if (next->tool == tool) return DMUS_E_ALREADY_EXISTS;
if (index-- <= 0) break;
}
++This->num_tools;
pNewTool = calloc(1, sizeof(*pNewTool));
pNewTool->pTool = pTool;
pNewTool->dwIndex = lIndex;
IDirectMusicTool_AddRef(pTool);
IDirectMusicTool_Init(pTool, iface);
list_add_tail (pPrevEntry->next, &pNewTool->entry);
#if 0
DWORD dwNum = 0;
IDirectMusicTool8_GetMediaTypes(pTool, &dwNum);
#endif
if (!(entry = calloc(1, sizeof(*entry)))) return E_OUTOFMEMORY;
entry->tool = tool;
IDirectMusicTool_AddRef(tool);
IDirectMusicTool_Init(tool, iface);
list_add_before(&next->entry, &entry->entry);
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);
struct list* pEntry = NULL;
LPDMUS_PRIVATE_GRAPH_TOOL pIt = NULL;
struct tool_entry *entry;
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 (pIt->dwIndex == dwIndex)
if (!index--)
{
*ppTool = pIt->pTool;
if (*ppTool)
IDirectMusicTool_AddRef(*ppTool);
*ret_tool = entry->tool;
IDirectMusicTool_AddRef(entry->tool);
return S_OK;
}
if (pIt->dwIndex > dwIndex)
break ;
}
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);
FIXME("(%p, %p): stub\n", This, pTool);
return S_OK;
struct tool_entry *entry;
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 =
......@@ -260,7 +272,7 @@ HRESULT create_dmgraph(REFIID riid, void **ret_iface)
dmobject_init(&obj->dmobj, &CLSID_DirectMusicGraph, (IUnknown *)&obj->IDirectMusicGraph_iface);
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_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);
IDirectMusicGraph_Release(&obj->IDirectMusicGraph_iface);
......
......@@ -705,10 +705,10 @@ static void test_graph(void)
ok(hr == S_OK, "got %#lx\n", hr);
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);
todo_wine ok(hr == S_OK, "got %#lx\n", hr);
todo_wine ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
ok(hr == S_OK, "got %#lx\n", hr);
ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
if (hr == S_OK) IDirectMusicTool_Release(tmp_tool);
hr = IDirectMusicGraph_GetTool(graph, 1, &tmp_tool);
ok(hr == S_OK, "got %#lx\n", hr);
......@@ -723,24 +723,24 @@ static void test_graph(void)
/* test removing the first tool */
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);
ok(hr == S_OK, "got %#lx\n", hr);
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);
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);
if (hr == S_OK) IDirectMusicTool_Release(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);
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);
todo_wine ok(hr == S_OK, "got %#lx\n", hr);
todo_wine ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
ok(hr == S_OK, "got %#lx\n", hr);
ok(tool1 == tmp_tool, "got %p\n", tmp_tool);
if (hr == S_OK) IDirectMusicTool_Release(tmp_tool);
......@@ -810,7 +810,7 @@ static void test_graph(void)
hr = IDirectMusicGraph_InsertTool(tmp_graph, tool1, NULL, 0, 0);
ok(hr == S_OK, "got %#lx\n", hr);
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);
ok(hr == S_OK, "got %#lx\n", hr);
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