dmusic: Keep the original instrument patch in the entry.

This commit is contained in:
Rémi Bernon 2023-09-10 23:00:56 +02:00 committed by Alexandre Julliard
parent b6f1a1a186
commit ecb38bf1c9
2 changed files with 21 additions and 7 deletions

View file

@ -25,6 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
struct instrument_entry
{
struct list entry;
DWORD patch;
DMUS_OBJECTDESC desc;
IDirectMusicInstrument *instrument;
};
@ -176,15 +177,12 @@ static HRESULT WINAPI collection_GetInstrument(IDirectMusicCollection *iface,
{
struct collection *This = impl_from_IDirectMusicCollection(iface);
struct instrument_entry *entry;
DWORD inst_patch;
HRESULT hr;
TRACE("(%p, %lu, %p)\n", iface, patch, instrument);
LIST_FOR_EACH_ENTRY(entry, &This->instruments, struct instrument_entry, entry)
{
if (FAILED(hr = IDirectMusicInstrument_GetPatch(entry->instrument, &inst_patch))) return hr;
if (patch == inst_patch)
if (patch == entry->patch)
{
*instrument = entry->instrument;
IDirectMusicInstrument_AddRef(entry->instrument);
@ -202,14 +200,13 @@ static HRESULT WINAPI collection_EnumInstrument(IDirectMusicCollection *iface,
{
struct collection *This = impl_from_IDirectMusicCollection(iface);
struct instrument_entry *entry;
HRESULT hr;
TRACE("(%p, %ld, %p, %p, %ld)\n", iface, index, patch, name, name_length);
LIST_FOR_EACH_ENTRY(entry, &This->instruments, struct instrument_entry, entry)
{
if (index--) continue;
if (FAILED(hr = IDirectMusicInstrument_GetPatch(entry->instrument, patch))) return hr;
*patch = entry->patch;
if (name) lstrcpynW(name, entry->desc.wszName, name_length);
return S_OK;
}
@ -239,6 +236,7 @@ static HRESULT parse_lins_list(struct collection *This, IStream *stream, struct
case MAKE_IDTYPE(FOURCC_LIST, FOURCC_INS):
if (!(entry = malloc(sizeof(*entry)))) return E_OUTOFMEMORY;
hr = instrument_create_from_chunk(stream, &chunk, This, &entry->desc, &entry->instrument);
if (SUCCEEDED(hr)) hr = IDirectMusicInstrument_GetPatch(entry->instrument, &entry->patch);
if (SUCCEEDED(hr)) list_add_tail(&This->instruments, &entry->entry);
else free(entry);
break;

View file

@ -1184,7 +1184,7 @@ static void test_download_instrument(void)
static const LARGE_INTEGER zero = {0};
IDirectMusicDownloadedInstrument *downloaded;
IDirectMusicCollection *collection;
IDirectMusicInstrument *instrument;
IDirectMusicInstrument *instrument, *tmp_instrument;
IPersistStream *persist;
IDirectMusicPort *port;
IDirectMusic *dmusic;
@ -1299,6 +1299,22 @@ static void test_download_instrument(void)
hr = IDirectMusicCollection_GetInstrument(collection, 0x1234, &instrument);
ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicInstrument_GetPatch(instrument, &patch);
ok(hr == S_OK, "got %#lx\n", hr);
ok(patch == 0x1234, "got %#lx\n", patch);
hr = IDirectMusicInstrument_SetPatch(instrument, 0x4321);
ok(hr == S_OK, "got %#lx\n", hr);
hr = IDirectMusicInstrument_GetPatch(instrument, &patch);
ok(hr == S_OK, "got %#lx\n", hr);
ok(patch == 0x4321, "got %#lx\n", patch);
hr = IDirectMusicCollection_GetInstrument(collection, 0x1234, &tmp_instrument);
ok(hr == S_OK, "got %#lx\n", hr);
ok(instrument == tmp_instrument, "got %p\n", tmp_instrument);
hr = IDirectMusicInstrument_GetPatch(tmp_instrument, &patch);
ok(hr == S_OK, "got %#lx\n", hr);
ok(patch == 0x4321, "got %#lx\n", patch);
IDirectMusicInstrument_Release(tmp_instrument);
check_interface(instrument, &IID_IDirectMusicObject, FALSE);
check_interface(instrument, &IID_IDirectMusicDownload, FALSE);