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

dmusic: Cleanup collection instrument iteration loops.

parent ff4cb785
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
WINE_DECLARE_DEBUG_CHANNEL(dmfile); WINE_DECLARE_DEBUG_CHANNEL(dmfile);
struct instrument_entry
{
struct list entry;
IDirectMusicInstrument *instrument;
};
struct collection struct collection
{ {
IDirectMusicCollection IDirectMusicCollection_iface; IDirectMusicCollection IDirectMusicCollection_iface;
...@@ -36,8 +42,8 @@ struct collection ...@@ -36,8 +42,8 @@ struct collection
/* pool table */ /* pool table */
POOLTABLE *pPoolTable; POOLTABLE *pPoolTable;
POOLCUE *pPoolCues; POOLCUE *pPoolCues;
/* instruments */
struct list Instruments; struct list instruments;
}; };
static inline struct collection *impl_from_IDirectMusicCollection(IDirectMusicCollection *iface) static inline struct collection *impl_from_IDirectMusicCollection(IDirectMusicCollection *iface)
...@@ -103,25 +109,25 @@ static HRESULT WINAPI collection_GetInstrument(IDirectMusicCollection *iface, ...@@ -103,25 +109,25 @@ static HRESULT WINAPI collection_GetInstrument(IDirectMusicCollection *iface,
DWORD patch, IDirectMusicInstrument **instrument) DWORD patch, IDirectMusicInstrument **instrument)
{ {
struct collection *This = impl_from_IDirectMusicCollection(iface); struct collection *This = impl_from_IDirectMusicCollection(iface);
DMUS_PRIVATE_INSTRUMENTENTRY *inst_entry; struct instrument_entry *entry;
struct list *list_entry;
DWORD inst_patch; DWORD inst_patch;
HRESULT hr;
TRACE("(%p, %lu, %p)\n", iface, patch, instrument); TRACE("(%p, %lu, %p)\n", iface, patch, instrument);
LIST_FOR_EACH(list_entry, &This->Instruments) { LIST_FOR_EACH_ENTRY(entry, &This->instruments, struct instrument_entry, entry)
inst_entry = LIST_ENTRY(list_entry, DMUS_PRIVATE_INSTRUMENTENTRY, entry); {
IDirectMusicInstrument_GetPatch(inst_entry->pInstrument, &inst_patch); if (FAILED(hr = IDirectMusicInstrument_GetPatch(entry->instrument, &inst_patch))) return hr;
if (patch == inst_patch) { if (patch == inst_patch)
*instrument = inst_entry->pInstrument; {
IDirectMusicInstrument_AddRef(inst_entry->pInstrument); *instrument = entry->instrument;
TRACE(": returning instrument %p\n", *instrument); IDirectMusicInstrument_AddRef(entry->instrument);
TRACE(": returning instrument %p\n", entry->instrument);
return S_OK; return S_OK;
} }
} }
TRACE(": instrument not found\n"); TRACE(": instrument not found\n");
return DMUS_E_INVALIDPATCH; return DMUS_E_INVALIDPATCH;
} }
...@@ -129,26 +135,23 @@ static HRESULT WINAPI collection_EnumInstrument(IDirectMusicCollection *iface, ...@@ -129,26 +135,23 @@ static HRESULT WINAPI collection_EnumInstrument(IDirectMusicCollection *iface,
DWORD index, DWORD *patch, LPWSTR name, DWORD name_length) DWORD index, DWORD *patch, LPWSTR name, DWORD name_length)
{ {
struct collection *This = impl_from_IDirectMusicCollection(iface); struct collection *This = impl_from_IDirectMusicCollection(iface);
DWORD i = 0; struct instrument_entry *entry;
DMUS_PRIVATE_INSTRUMENTENTRY *inst_entry; HRESULT hr;
struct list *list_entry;
DWORD length;
TRACE("(%p, %ld, %p, %p, %ld)\n", iface, index, patch, name, name_length); TRACE("(%p, %ld, %p, %p, %ld)\n", iface, index, patch, name, name_length);
LIST_FOR_EACH(list_entry, &This->Instruments) { LIST_FOR_EACH_ENTRY(entry, &This->instruments, struct instrument_entry, entry)
inst_entry = LIST_ENTRY(list_entry, DMUS_PRIVATE_INSTRUMENTENTRY, entry); {
if (i == index) { if (index--) continue;
struct instrument *instrument = impl_from_IDirectMusicInstrument(inst_entry->pInstrument); if (FAILED(hr = IDirectMusicInstrument_GetPatch(entry->instrument, patch))) return hr;
IDirectMusicInstrument_GetPatch(inst_entry->pInstrument, patch); if (name)
if (name) { {
length = min(lstrlenW(instrument->wszName), name_length - 1); struct instrument *instrument = impl_from_IDirectMusicInstrument(entry->instrument);
memcpy(name, instrument->wszName, length * sizeof(WCHAR)); DWORD length = min(lstrlenW(instrument->wszName), name_length - 1);
name[length] = '\0'; memcpy(name, instrument->wszName, length * sizeof(WCHAR));
} name[length] = '\0';
return S_OK;
} }
i++; return S_OK;
} }
return S_FALSE; return S_FALSE;
...@@ -372,12 +375,12 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface, ...@@ -372,12 +375,12 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface,
ListCount[1] = 0; ListCount[1] = 0;
switch (chunk.fccID) { switch (chunk.fccID) {
case FOURCC_INS: { case FOURCC_INS: {
DMUS_PRIVATE_INSTRUMENTENTRY *entry = calloc(1, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY)); struct instrument_entry *entry = calloc(1, sizeof(*entry));
TRACE_(dmfile)(": instrument list\n"); TRACE_(dmfile)(": instrument list\n");
liMove.QuadPart = -12; liMove.QuadPart = -12;
IStream_Seek(stream, liMove, STREAM_SEEK_CUR, NULL); IStream_Seek(stream, liMove, STREAM_SEEK_CUR, NULL);
if (FAILED(instrument_create_from_stream(stream, &entry->pInstrument))) free(entry); if (FAILED(instrument_create_from_stream(stream, &entry->instrument))) free(entry);
else list_add_tail(&This->Instruments, &entry->entry); else list_add_tail(&This->instruments, &entry->entry);
break; break;
} }
} }
...@@ -417,10 +420,10 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface, ...@@ -417,10 +420,10 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface,
/* DEBUG: dumps whole collection object tree: */ /* DEBUG: dumps whole collection object tree: */
if (TRACE_ON(dmusic)) { if (TRACE_ON(dmusic))
int r = 0; {
DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry; struct instrument_entry *entry;
struct list *listEntry; int i = 0;
TRACE("*** IDirectMusicCollection (%p) ***\n", &This->IDirectMusicCollection_iface); TRACE("*** IDirectMusicCollection (%p) ***\n", &This->IDirectMusicCollection_iface);
dump_DMUS_OBJECTDESC(&This->dmobj.desc); dump_DMUS_OBJECTDESC(&This->dmobj.desc);
...@@ -429,11 +432,8 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface, ...@@ -429,11 +432,8 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface,
TRACE(" - cInstruments: %ld\n", This->pHeader->cInstruments); TRACE(" - cInstruments: %ld\n", This->pHeader->cInstruments);
TRACE(" - Instruments:\n"); TRACE(" - Instruments:\n");
LIST_FOR_EACH(listEntry, &This->Instruments) { LIST_FOR_EACH_ENTRY(entry, &This->instruments, struct instrument_entry, entry)
tmpEntry = LIST_ENTRY( listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry ); TRACE(" - Instrument[%i]: %p\n", i++, entry->instrument);
TRACE(" - Instrument[%i]: %p\n", r, tmpEntry->pInstrument);
r++;
}
} }
return S_OK; return S_OK;
...@@ -463,8 +463,7 @@ HRESULT collection_create(IUnknown **ret_iface) ...@@ -463,8 +463,7 @@ HRESULT collection_create(IUnknown **ret_iface)
(IUnknown *)&collection->IDirectMusicCollection_iface); (IUnknown *)&collection->IDirectMusicCollection_iface);
collection->dmobj.IDirectMusicObject_iface.lpVtbl = &collection_object_vtbl; collection->dmobj.IDirectMusicObject_iface.lpVtbl = &collection_object_vtbl;
collection->dmobj.IPersistStream_iface.lpVtbl = &collection_stream_vtbl; collection->dmobj.IPersistStream_iface.lpVtbl = &collection_stream_vtbl;
list_init(&collection->instruments);
list_init(&collection->Instruments);
TRACE("Created DirectMusicCollection %p\n", collection); TRACE("Created DirectMusicCollection %p\n", collection);
*ret_iface = (IUnknown *)&collection->IDirectMusicCollection_iface; *ret_iface = (IUnknown *)&collection->IDirectMusicCollection_iface;
......
...@@ -161,11 +161,6 @@ struct IReferenceClockImpl { ...@@ -161,11 +161,6 @@ struct IReferenceClockImpl {
DMUS_CLOCKINFO pClockInfo; DMUS_CLOCKINFO pClockInfo;
}; };
typedef struct _DMUS_PRIVATE_INSTRUMENT_ENTRY {
struct list entry; /* for listing elements */
IDirectMusicInstrument* pInstrument;
} DMUS_PRIVATE_INSTRUMENTENTRY, *LPDMUS_PRIVATE_INSTRUMENTENTRY;
typedef struct _DMUS_PRIVATE_POOLCUE { typedef struct _DMUS_PRIVATE_POOLCUE {
struct list entry; /* for listing elements */ struct list entry; /* for listing elements */
} DMUS_PRIVATE_POOLCUE, *LPDMUS_PRIVATE_POOLCUE; } DMUS_PRIVATE_POOLCUE, *LPDMUS_PRIVATE_POOLCUE;
......
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