dmime: Remove ERR() on HeapAlloc failure for small sizes known at compile time.
[wine] / dlls / dmime / tempotrack.c
1 /* IDirectMusicTempoTrack Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  * Copyright (C) 2004 Raphael Junqueira
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "dmime_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25
26 /*****************************************************************************
27  * IDirectMusicTempoTrack implementation
28  */
29 /* IDirectMusicTempoTrack IUnknown part: */
30 static HRESULT WINAPI IDirectMusicTempoTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31   ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
32   TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33   
34   if (IsEqualIID (riid, &IID_IUnknown)) {
35     *ppobj = &This->UnknownVtbl;
36     IUnknown_AddRef (iface);
37     return S_OK;
38   } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
39              || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
40     *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
41     IUnknown_AddRef (iface);
42     return S_OK;
43   } else if (IsEqualIID (riid, &IID_IPersistStream)) {
44     *ppobj = &This->PersistStreamVtbl;
45     IUnknown_AddRef (iface);
46     return S_OK;
47   }
48   
49   WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
50   return E_NOINTERFACE;
51 }
52
53 static ULONG WINAPI IDirectMusicTempoTrack_IUnknown_AddRef (LPUNKNOWN iface) {
54   ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
55   ULONG ref = InterlockedIncrement(&This->ref);
56
57   TRACE("(%p): AddRef from %d\n", This, ref - 1);
58
59   DMIME_LockModule();
60
61   return ref;
62 }
63
64 static ULONG WINAPI IDirectMusicTempoTrack_IUnknown_Release (LPUNKNOWN iface) {
65   ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
66   ULONG ref = InterlockedDecrement(&This->ref);
67   TRACE("(%p): ReleaseRef to %d\n", This, ref);
68   
69   if (ref == 0) {
70     HeapFree(GetProcessHeap(), 0, This);
71   }
72
73   DMIME_UnlockModule();
74   
75   return ref;
76 }
77
78 static const IUnknownVtbl DirectMusicTempoTrack_Unknown_Vtbl = {
79   IDirectMusicTempoTrack_IUnknown_QueryInterface,
80   IDirectMusicTempoTrack_IUnknown_AddRef,
81   IDirectMusicTempoTrack_IUnknown_Release
82 };
83
84 /* IDirectMusicTempoTrack IDirectMusicTrack8 part: */
85 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
86   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
87   return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
88 }
89
90 static ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
91   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
92   return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
93 }
94
95 static ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
96   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
97   return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
98 }
99
100 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
101 {
102   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
103   TRACE("(%p, %p): nothing to do here\n", This, pSegment);
104   return S_OK;
105 }
106
107 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
108 {
109   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
110
111   LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = NULL;
112
113   FIXME("(%p, %p, %p, %p, %d, %d): semi-stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
114
115   pState = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_PLAY_STATE));
116   if (NULL == pState)
117     return E_OUTOFMEMORY;
118
119   /** TODO real fill useful data */
120   pState->dummy = 0;
121   *ppStateData = pState;
122   return S_OK;
123 }
124
125 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
126 {
127   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
128
129   LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = pStateData;
130
131   FIXME("(%p, %p): semi-stub\n", This, pStateData);
132
133   if (NULL == pStateData) {
134     return E_POINTER;
135   }
136   /** TODO real clean up */
137   HeapFree(GetProcessHeap(), 0, pState);
138   return S_OK;
139 }
140
141 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
142 {
143   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
144   FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
145   /** should use IDirectMusicPerformance_SendPMsg here */
146   return S_OK;
147 }
148
149 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
150   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
151
152   HRESULT hr = S_OK;
153   struct list* pEntry = NULL;
154   LPDMUS_PRIVATE_TEMPO_ITEM pIt = NULL;
155   DMUS_TEMPO_PARAM* prm = pParam;
156
157   FIXME("(%p, %s, %d, %p, %p): almost stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
158
159   if (NULL == pParam) {
160     return E_POINTER;
161   }
162
163   hr = IDirectMusicTrack_IsParamSupported (iface, rguidType);
164   if (FAILED(hr)) {
165     return hr;
166   }
167   if (FALSE == This->enabled) {
168     return DMUS_E_TYPE_DISABLED;
169   }
170
171   if (NULL != pmtNext) *pmtNext = 0;
172   prm->mtTime = 0;
173   prm->dblTempo = 0.123456;
174
175   LIST_FOR_EACH (pEntry, &This->Items) {
176     pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_TEMPO_ITEM, entry);
177     /*TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->item.lTime, pIt->item.dblTempo);*/
178     if (pIt->item.lTime <= mtTime) {
179       MUSIC_TIME ofs = pIt->item.lTime - mtTime;
180       if (ofs > prm->mtTime) {
181         prm->mtTime = ofs;
182         prm->dblTempo = pIt->item.dblTempo;
183       } 
184       if (NULL != pmtNext && pIt->item.lTime > mtTime) {
185         if (pIt->item.lTime < *pmtNext) {
186           *pmtNext = pIt->item.lTime;
187         }
188       }
189     }
190   }
191   
192   if (0.123456 == prm->dblTempo) {
193     return DMUS_E_NOT_FOUND;
194   }
195   return S_OK;
196 }
197
198 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
199         ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
200         FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
201         return S_OK;
202 }
203
204 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
205   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
206
207   TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
208   if (IsEqualGUID (rguidType, &GUID_DisableTempo)
209       || IsEqualGUID (rguidType, &GUID_EnableTempo)
210       || IsEqualGUID (rguidType, &GUID_TempoParam)) {
211     TRACE("param supported\n");
212     return S_OK;
213   }
214   if (FALSE == This->enabled) {
215     return DMUS_E_TYPE_DISABLED;
216   }
217   TRACE("param unsupported\n");
218   return DMUS_E_TYPE_UNSUPPORTED;
219 }
220
221 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
222   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
223   FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
224   return S_OK;
225 }
226
227 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
228   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
229   FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
230   return S_OK;
231 }
232
233 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
234   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
235   FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
236   return S_OK;
237 }
238
239 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
240   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
241   FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
242       wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
243   return S_OK;
244 }
245
246 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
247   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
248   FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
249       wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
250   return S_OK;
251 }
252
253 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
254   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
255   FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
256       wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
257   return S_OK;
258 }
259
260 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
261   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
262   FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
263   return S_OK;
264 }
265
266 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
267   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
268   FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
269   return S_OK;
270 }
271
272 static const IDirectMusicTrack8Vtbl DirectMusicTempoTrack_Track_Vtbl = {
273   IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface,
274   IDirectMusicTempoTrack_IDirectMusicTrack_AddRef,
275   IDirectMusicTempoTrack_IDirectMusicTrack_Release,
276   IDirectMusicTempoTrack_IDirectMusicTrack_Init,
277   IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay,
278   IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay,
279   IDirectMusicTempoTrack_IDirectMusicTrack_Play,
280   IDirectMusicTempoTrack_IDirectMusicTrack_GetParam,
281   IDirectMusicTempoTrack_IDirectMusicTrack_SetParam,
282   IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported,
283   IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType,
284   IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType,
285   IDirectMusicTempoTrack_IDirectMusicTrack_Clone,
286   IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx,
287   IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx,
288   IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx,
289   IDirectMusicTempoTrack_IDirectMusicTrack_Compose,
290   IDirectMusicTempoTrack_IDirectMusicTrack_Join
291 };
292
293 /* IDirectMusicTempoTrack IPersistStream part: */
294 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
295   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
296   return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
297 }
298
299 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
300   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
301   return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
302 }
303
304 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
305   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
306   return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
307 }
308
309 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
310   ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
311   TRACE("(%p, %p)\n", This, pClassID);
312   *pClassID = CLSID_DirectMusicTempoTrack;
313   return S_OK;
314 }
315
316 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
317   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
318   FIXME("(%p): stub, always S_FALSE\n", This);
319   return S_FALSE;
320 }
321
322 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
323   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
324   DMUS_PRIVATE_CHUNK Chunk;
325   DWORD StreamSize, StreamCount;
326   LARGE_INTEGER liMove;
327   DMUS_IO_TEMPO_ITEM item;
328   LPDMUS_PRIVATE_TEMPO_ITEM pNewItem = NULL;
329   DWORD nItem = 0;
330   FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
331   
332 #if 1
333   IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
334   TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
335   switch (Chunk.fccID) {        
336   case DMUS_FOURCC_TEMPO_TRACK: {
337     TRACE_(dmfile)(": Tempo track\n");
338 #if 1
339     IStream_Read (pStm, &StreamSize, sizeof(DWORD), NULL);
340     StreamSize -= sizeof(DWORD);
341     StreamCount = 0;
342     TRACE_(dmfile)(" - sizeof(DMUS_IO_TEMPO_ITEM): %u (chunkSize = %u)\n", StreamSize, Chunk.dwSize);
343     do {
344       IStream_Read (pStm, &item, sizeof(item), NULL);
345       ++nItem;
346       TRACE_(dmfile)("DMUS_IO_TEMPO_ITEM #%d\n", nItem);
347       TRACE_(dmfile)(" - lTime = %u\n", item.lTime);
348       TRACE_(dmfile)(" - dblTempo = %g\n", item.dblTempo);
349       pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_ITEM));
350       if (NULL == pNewItem)
351         return  E_OUTOFMEMORY;
352
353       pNewItem->item = item;
354       list_add_tail (&This->Items, &pNewItem->entry);
355       pNewItem = NULL;
356       StreamCount += sizeof(item);
357       TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
358     } while (StreamCount < StreamSize); 
359 #else    
360     liMove.QuadPart = Chunk.dwSize;
361     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
362 #endif
363     break;
364   }
365   default: {
366     TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
367     liMove.QuadPart = Chunk.dwSize;
368     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
369     return E_FAIL;
370   }
371   }
372 #endif
373
374   return S_OK;
375 }
376
377 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
378   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
379   FIXME("(%p): Saving not implemented yet\n", This);
380   return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
384   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
385   FIXME("(%p, %p): stub\n", This, pcbSize);
386   return E_NOTIMPL;
387 }
388
389 static const IPersistStreamVtbl DirectMusicTempoTrack_PersistStream_Vtbl = {
390   IDirectMusicTempoTrack_IPersistStream_QueryInterface,
391   IDirectMusicTempoTrack_IPersistStream_AddRef,
392   IDirectMusicTempoTrack_IPersistStream_Release,
393   IDirectMusicTempoTrack_IPersistStream_GetClassID,
394   IDirectMusicTempoTrack_IPersistStream_IsDirty,
395   IDirectMusicTempoTrack_IPersistStream_Load,
396   IDirectMusicTempoTrack_IPersistStream_Save,
397   IDirectMusicTempoTrack_IPersistStream_GetSizeMax
398 };
399
400 /* for ClassFactory */
401 HRESULT WINAPI DMUSIC_CreateDirectMusicTempoTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
402   IDirectMusicTempoTrack* track;
403         
404   track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicTempoTrack));
405   if (NULL == track) {
406     *ppobj = NULL;
407     return E_OUTOFMEMORY;
408   }
409   track->UnknownVtbl = &DirectMusicTempoTrack_Unknown_Vtbl;
410   track->TrackVtbl = &DirectMusicTempoTrack_Track_Vtbl;
411   track->PersistStreamVtbl = &DirectMusicTempoTrack_PersistStream_Vtbl;
412   track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
413   DM_STRUCT_INIT(track->pDesc);
414   track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
415   track->pDesc->guidClass = CLSID_DirectMusicTempoTrack;
416   track->ref = 0; /* will be inited by QueryInterface */
417   track->enabled = TRUE;
418   list_init (&track->Items);
419
420   return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);
421 }