Skip to content

Commit

Permalink
dmime: Rewrite segment IDirectMusicSegment_InsertTrack.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbernon authored and julliard committed Sep 19, 2023
1 parent d045eae commit f04976e
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions dlls/dmime/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,38 +252,37 @@ static HRESULT WINAPI segment_GetTrackGroup(IDirectMusicSegment8 *iface, IDirect
return DMUS_E_NOT_FOUND;
}

static HRESULT WINAPI segment_InsertTrack(IDirectMusicSegment8 *iface, IDirectMusicTrack *pTrack, DWORD group)
static HRESULT segment_append_track(struct segment *This, IDirectMusicTrack *track, DWORD group, DWORD flags)
{
struct segment *This = impl_from_IDirectMusicSegment8(iface);
DWORD i = 0;
struct list* pEntry = NULL;
struct track_entry *pIt = NULL;
struct track_entry *pNewSegTrack = NULL;
struct track_entry *entry;
HRESULT hr;

TRACE("(%p, %p, %#lx)\n", This, pTrack, group);
if (!(entry = calloc(1, sizeof(*entry)))) return E_OUTOFMEMORY;
entry->dwGroupBits = group;
entry->flags = flags;
entry->pTrack = track;
IDirectMusicTrack_AddRef(track);

if (!group)
return E_INVALIDARG;
hr = IDirectMusicTrack_Init(track, (IDirectMusicSegment *)&This->IDirectMusicSegment8_iface);
if (FAILED(hr)) track_entry_destroy(entry);
else list_add_tail(&This->tracks, &entry->entry);

LIST_FOR_EACH (pEntry, &This->tracks) {
i++;
pIt = LIST_ENTRY(pEntry, struct track_entry, entry);
TRACE(" - #%lu: %p -> %#lx, %p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
if (NULL != pIt && pIt->pTrack == pTrack) {
ERR("(%p, %p): track is already in list\n", This, pTrack);
return E_FAIL;
}
}
return hr;
}

static HRESULT WINAPI segment_InsertTrack(IDirectMusicSegment8 *iface, IDirectMusicTrack *track, DWORD group)
{
struct segment *This = impl_from_IDirectMusicSegment8(iface);
struct track_entry *entry;

TRACE("(%p, %p, %#lx)\n", This, track, group);

if (!(pNewSegTrack = calloc(1, sizeof(*pNewSegTrack)))) return E_OUTOFMEMORY;
if (!group) return E_INVALIDARG;

pNewSegTrack->dwGroupBits = group;
pNewSegTrack->pTrack = pTrack;
IDirectMusicTrack_Init(pTrack, (IDirectMusicSegment *)iface);
IDirectMusicTrack_AddRef(pTrack);
list_add_tail (&This->tracks, &pNewSegTrack->entry);
LIST_FOR_EACH_ENTRY(entry, &This->tracks, struct track_entry, entry)
if (entry->pTrack == track) return E_FAIL;

return S_OK;
return segment_append_track(This, track, group, 0);
}

static HRESULT WINAPI segment_RemoveTrack(IDirectMusicSegment8 *iface, IDirectMusicTrack *pTrack)
Expand Down

0 comments on commit f04976e

Please sign in to comment.