1 /* IDirectMusicLyricsTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime
);
25 /*****************************************************************************
26 * IDirectMusicLyricsTrack implementation
28 typedef struct IDirectMusicLyricsTrack
{
29 IDirectMusicTrack8 IDirectMusicTrack8_iface
;
30 struct dmobject dmobj
; /* IPersistStream only */
32 } IDirectMusicLyricsTrack
;
34 /* IDirectMusicLyricsTrack IDirectMusicTrack8 part: */
35 static inline IDirectMusicLyricsTrack
*impl_from_IDirectMusicTrack8(IDirectMusicTrack8
*iface
)
37 return CONTAINING_RECORD(iface
, IDirectMusicLyricsTrack
, IDirectMusicTrack8_iface
);
40 static inline IDirectMusicLyricsTrack
*impl_from_IPersistStream(IPersistStream
*iface
)
42 return CONTAINING_RECORD(iface
, IDirectMusicLyricsTrack
, dmobj
.IPersistStream_iface
);
45 static HRESULT WINAPI
lyrics_track_QueryInterface(IDirectMusicTrack8
*iface
, REFIID riid
,
48 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
50 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
54 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicTrack
) ||
55 IsEqualIID(riid
, &IID_IDirectMusicTrack8
))
57 else if (IsEqualIID(riid
, &IID_IPersistStream
))
58 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
60 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
64 IUnknown_AddRef((IUnknown
*)*ret_iface
);
68 static ULONG WINAPI
lyrics_track_AddRef(IDirectMusicTrack8
*iface
)
70 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
71 LONG ref
= InterlockedIncrement(&This
->ref
);
73 TRACE("(%p) ref=%d\n", This
, ref
);
78 static ULONG WINAPI
lyrics_track_Release(IDirectMusicTrack8
*iface
)
80 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
81 LONG ref
= InterlockedDecrement(&This
->ref
);
83 TRACE("(%p) ref=%d\n", This
, ref
);
86 HeapFree(GetProcessHeap(), 0, This
);
93 static HRESULT WINAPI
lyrics_track_Init(IDirectMusicTrack8
*iface
, IDirectMusicSegment
*pSegment
)
95 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
96 FIXME("(%p, %p): stub\n", This
, pSegment
);
100 static HRESULT WINAPI
lyrics_track_InitPlay(IDirectMusicTrack8
*iface
,
101 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
102 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
104 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
105 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
109 static HRESULT WINAPI
lyrics_track_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
111 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
112 FIXME("(%p, %p): stub\n", This
, pStateData
);
116 static HRESULT WINAPI
lyrics_track_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
117 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
118 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
120 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
121 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
125 static HRESULT WINAPI
lyrics_track_GetParam(IDirectMusicTrack8
*iface
, REFGUID type
,
126 MUSIC_TIME time
, MUSIC_TIME
*next
, void *param
)
128 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
130 TRACE("(%p, %s, %d, %p, %p): not supported\n", This
, debugstr_dmguid(type
), time
, next
, param
);
131 return DMUS_E_GET_UNSUPPORTED
;
134 static HRESULT WINAPI
lyrics_track_SetParam(IDirectMusicTrack8
*iface
, REFGUID type
,
135 MUSIC_TIME time
, void *param
)
137 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
139 TRACE("(%p, %s, %d, %p): not supported\n", This
, debugstr_dmguid(type
), time
, param
);
140 return DMUS_E_SET_UNSUPPORTED
;
143 static HRESULT WINAPI
lyrics_track_IsParamSupported(IDirectMusicTrack8
*iface
, REFGUID type
)
145 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
147 TRACE("(%p, %s): param type not supported\n", This
, debugstr_dmguid(type
));
148 return DMUS_E_TYPE_UNSUPPORTED
;
151 static HRESULT WINAPI
lyrics_track_AddNotificationType(IDirectMusicTrack8
*iface
, REFGUID notiftype
)
153 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
155 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
159 static HRESULT WINAPI
lyrics_track_RemoveNotificationType(IDirectMusicTrack8
*iface
,
162 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
164 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
168 static HRESULT WINAPI
lyrics_track_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
169 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
171 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
172 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
176 static HRESULT WINAPI
lyrics_track_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
177 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
178 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
180 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
181 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
182 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
186 static HRESULT WINAPI
lyrics_track_GetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
187 REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
, void *pStateData
,
190 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
191 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
192 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
196 static HRESULT WINAPI
lyrics_track_SetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
197 REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
199 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
200 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
201 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
205 static HRESULT WINAPI
lyrics_track_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
206 DWORD trackgroup
, IDirectMusicTrack
**track
)
208 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
210 TRACE("(%p, %p, %d, %p): method not implemented\n", This
, context
, trackgroup
, track
);
214 static HRESULT WINAPI
lyrics_track_Join(IDirectMusicTrack8
*iface
, IDirectMusicTrack
*newtrack
,
215 MUSIC_TIME join
, IUnknown
*context
, DWORD trackgroup
, IDirectMusicTrack
**resulttrack
)
217 IDirectMusicLyricsTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
218 TRACE("(%p, %p, %d, %p, %d, %p): method not implemented\n", This
, newtrack
, join
, context
,
219 trackgroup
, resulttrack
);
223 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
224 lyrics_track_QueryInterface
,
226 lyrics_track_Release
,
228 lyrics_track_InitPlay
,
229 lyrics_track_EndPlay
,
231 lyrics_track_GetParam
,
232 lyrics_track_SetParam
,
233 lyrics_track_IsParamSupported
,
234 lyrics_track_AddNotificationType
,
235 lyrics_track_RemoveNotificationType
,
238 lyrics_track_GetParamEx
,
239 lyrics_track_SetParamEx
,
240 lyrics_track_Compose
,
244 static HRESULT
parse_lyrics_track_events(IDirectMusicLyricsTrack
*This
, IStream
*stream
,
245 struct chunk_entry
*lyric
)
247 struct chunk_entry chunk
= {.parent
= lyric
};
249 DMUS_IO_LYRICSTRACK_EVENTHEADER header
;
252 TRACE("Parsing segment form in %p: %s\n", stream
, debugstr_chunk(lyric
));
254 while ((hr
= stream_next_chunk(stream
, &chunk
)) == S_OK
) {
255 if (chunk
.id
== FOURCC_LIST
&& chunk
.type
== DMUS_FOURCC_LYRICSTRACKEVENT_LIST
) {
256 struct chunk_entry child
= {.parent
= &chunk
};
258 if (FAILED(hr
= stream_next_chunk(stream
, &child
)))
261 if (child
.id
!= DMUS_FOURCC_LYRICSTRACKEVENTHEADER_CHUNK
)
262 return DMUS_E_UNSUPPORTED_STREAM
;
264 if (FAILED(hr
= stream_chunk_get_data(stream
, &child
, &header
, child
.size
))) {
265 WARN("Failed to read data of %s\n", debugstr_chunk(&child
));
269 TRACE("Found DMUS_IO_LYRICSTRACK_EVENTHEADER\n");
270 TRACE(" - dwFlags 0x%08x\n", header
.dwFlags
);
271 TRACE(" - dwTimingFlags 0x%08x\n", header
.dwTimingFlags
);
272 TRACE(" - lTimeLogical %d\n", header
.lTimeLogical
);
273 TRACE(" - lTimePhysical %d\n", header
.lTimePhysical
);
275 if (FAILED(hr
= stream_next_chunk(stream
, &child
)))
278 if (child
.id
!= DMUS_FOURCC_LYRICSTRACKEVENTTEXT_CHUNK
)
279 return DMUS_E_UNSUPPORTED_STREAM
;
281 if (FAILED(hr
= stream_chunk_get_data(stream
, &child
, &name
, child
.size
))) {
282 WARN("Failed to read data of %s\n", debugstr_chunk(&child
));
286 TRACE("Found DMUS_FOURCC_LYRICSTRACKEVENTTEXT_CHUNK\n");
287 TRACE(" - name %s\n", debugstr_w(name
));
291 return SUCCEEDED(hr
) ? S_OK
: hr
;
294 static HRESULT
parse_lyricstrack_list(IDirectMusicLyricsTrack
*This
, IStream
*stream
, struct chunk_entry
*lyric
)
297 struct chunk_entry chunk
= {.parent
= lyric
};
299 TRACE("Parsing segment form in %p: %s\n", stream
, debugstr_chunk(lyric
));
301 if (FAILED(hr
= stream_next_chunk(stream
, &chunk
)))
304 if (chunk
.id
== FOURCC_LIST
&& chunk
.type
== DMUS_FOURCC_LYRICSTRACKEVENTS_LIST
)
305 hr
= parse_lyrics_track_events(This
, stream
, &chunk
);
307 hr
= DMUS_E_UNSUPPORTED_STREAM
;
309 return SUCCEEDED(hr
) ? S_OK
: hr
;
312 static HRESULT WINAPI
lyrics_IPersistStream_Load(IPersistStream
*iface
, IStream
*stream
)
314 IDirectMusicLyricsTrack
*This
= impl_from_IPersistStream(iface
);
316 struct chunk_entry chunk
= {0};
318 TRACE("%p, %p\n", This
, stream
);
323 if ((hr
= stream_get_chunk(stream
, &chunk
) != S_OK
))
326 if (chunk
.id
== FOURCC_LIST
&& chunk
.type
== DMUS_FOURCC_LYRICSTRACK_LIST
)
327 hr
= parse_lyricstrack_list(This
, stream
, &chunk
);
329 hr
= DMUS_E_UNSUPPORTED_STREAM
;
334 static const IPersistStreamVtbl persiststream_vtbl
= {
335 dmobj_IPersistStream_QueryInterface
,
336 dmobj_IPersistStream_AddRef
,
337 dmobj_IPersistStream_Release
,
338 dmobj_IPersistStream_GetClassID
,
339 unimpl_IPersistStream_IsDirty
,
340 lyrics_IPersistStream_Load
,
341 unimpl_IPersistStream_Save
,
342 unimpl_IPersistStream_GetSizeMax
345 /* for ClassFactory */
346 HRESULT WINAPI
create_dmlyricstrack(REFIID lpcGUID
, void **ppobj
)
348 IDirectMusicLyricsTrack
*track
;
351 track
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*track
));
354 return E_OUTOFMEMORY
;
356 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
358 dmobject_init(&track
->dmobj
, &CLSID_DirectMusicLyricsTrack
,
359 (IUnknown
*)&track
->IDirectMusicTrack8_iface
);
360 track
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
363 hr
= IDirectMusicTrack8_QueryInterface(&track
->IDirectMusicTrack8_iface
, lpcGUID
, ppobj
);
364 IDirectMusicTrack8_Release(&track
->IDirectMusicTrack8_iface
);