shell32/tests: Add verification of FOLDERID_ProgramFilesX64 and FOLDERID_ProgramFiles...
[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     ERR(": no more memory\n");
118     return E_OUTOFMEMORY;
119   }
120   /** TODO real fill useful data */
121   pState->dummy = 0;
122   *ppStateData = pState;
123   return S_OK;
124 }
125
126 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
127 {
128   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
129
130   LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = pStateData;
131
132   FIXME("(%p, %p): semi-stub\n", This, pStateData);
133
134   if (NULL == pStateData) {
135     return E_POINTER;
136   }
137   /** TODO real clean up */
138   HeapFree(GetProcessHeap(), 0, pState);
139   return S_OK;
140 }
141
142 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)
143 {
144   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
145   FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
146   /** should use IDirectMusicPerformance_SendPMsg here */
147   return S_OK;
148 }
149
150 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
151   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
152
153   HRESULT hr = S_OK;
154   struct list* pEntry = NULL;
155   LPDMUS_PRIVATE_TEMPO_ITEM pIt = NULL;
156   DMUS_TEMPO_PARAM* prm = pParam;
157
158   FIXME("(%p, %s, %d, %p, %p): almost stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
159
160   if (NULL == pParam) {
161     return E_POINTER;
162   }
163
164   hr = IDirectMusicTrack_IsParamSupported (iface, rguidType);
165   if (FAILED(hr)) {
166     return hr;
167   }
168   if (FALSE == This->enabled) {
169     return DMUS_E_TYPE_DISABLED;
170   }
171
172   if (NULL != pmtNext) *pmtNext = 0;
173   prm->mtTime = 0;
174   prm->dblTempo = 0.123456;
175
176   LIST_FOR_EACH (pEntry, &This->Items) {
177     pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_TEMPO_ITEM, entry);
178     /*TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->item.lTime, pIt->item.dblTempo);*/
179     if (pIt->item.lTime <= mtTime) {
180       MUSIC_TIME ofs = pIt->item.lTime - mtTime;
181       if (ofs > prm->mtTime) {
182         prm->mtTime = ofs;
183         prm->dblTempo = pIt->item.dblTempo;
184       } 
185       if (NULL != pmtNext && pIt->item.lTime > mtTime) {
186         if (pIt->item.lTime < *pmtNext) {
187           *pmtNext = pIt->item.lTime;
188         }
189       }
190     }
191   }
192   
193   if (0.123456 == prm->dblTempo) {
194     return DMUS_E_NOT_FOUND;
195   }
196   return S_OK;
197 }
198
199 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
200         ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
201         FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
202         return S_OK;
203 }
204
205 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
206   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
207
208   TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
209   if (IsEqualGUID (rguidType, &GUID_DisableTempo)
210       || IsEqualGUID (rguidType, &GUID_EnableTempo)
211       || IsEqualGUID (rguidType, &GUID_TempoParam)) {
212     TRACE("param supported\n");
213     return S_OK;
214   }
215   if (FALSE == This->enabled) {
216     return DMUS_E_TYPE_DISABLED;
217   }
218   TRACE("param unsupported\n");
219   return DMUS_E_TYPE_UNSUPPORTED;
220 }
221
222 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
223   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
224   FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
225   return S_OK;
226 }
227
228 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
229   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
230   FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
231   return S_OK;
232 }
233
234 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
235   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
236   FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
237   return S_OK;
238 }
239
240 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) {
241   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
242   FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
243       wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
244   return S_OK;
245 }
246
247 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
248   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
249   FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
250       wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
251   return S_OK;
252 }
253
254 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
255   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
256   FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
257       wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
258   return S_OK;
259 }
260
261 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
262   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
263   FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
264   return S_OK;
265 }
266
267 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
268   ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
269   FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
270   return S_OK;
271 }
272
273 static const IDirectMusicTrack8Vtbl DirectMusicTempoTrack_Track_Vtbl = {
274   IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface,
275   IDirectMusicTempoTrack_IDirectMusicTrack_AddRef,
276   IDirectMusicTempoTrack_IDirectMusicTrack_Release,
277   IDirectMusicTempoTrack_IDirectMusicTrack_Init,
278   IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay,
279   IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay,
280   IDirectMusicTempoTrack_IDirectMusicTrack_Play,
281   IDirectMusicTempoTrack_IDirectMusicTrack_GetParam,
282   IDirectMusicTempoTrack_IDirectMusicTrack_SetParam,
283   IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported,
284   IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType,
285   IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType,
286   IDirectMusicTempoTrack_IDirectMusicTrack_Clone,
287   IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx,
288   IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx,
289   IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx,
290   IDirectMusicTempoTrack_IDirectMusicTrack_Compose,
291   IDirectMusicTempoTrack_IDirectMusicTrack_Join
292 };
293
294 /* IDirectMusicTempoTrack IPersistStream part: */
295 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
296   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
297   return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
298 }
299
300 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
301   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
302   return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
303 }
304
305 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
306   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
307   return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
308 }
309
310 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
311   ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
312   TRACE("(%p, %p)\n", This, pClassID);
313   *pClassID = CLSID_DirectMusicTempoTrack;
314   return S_OK;
315 }
316
317 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
318   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
319   FIXME("(%p): stub, always S_FALSE\n", This);
320   return S_FALSE;
321 }
322
323 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
324   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
325   DMUS_PRIVATE_CHUNK Chunk;
326   DWORD StreamSize, StreamCount;
327   LARGE_INTEGER liMove;
328   DMUS_IO_TEMPO_ITEM item;
329   LPDMUS_PRIVATE_TEMPO_ITEM pNewItem = NULL;
330   DWORD nItem = 0;
331   FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
332   
333 #if 1
334   IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
335   TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
336   switch (Chunk.fccID) {        
337   case DMUS_FOURCC_TEMPO_TRACK: {
338     TRACE_(dmfile)(": Tempo track\n");
339 #if 1
340     IStream_Read (pStm, &StreamSize, sizeof(DWORD), NULL);
341     StreamSize -= sizeof(DWORD);
342     StreamCount = 0;
343     TRACE_(dmfile)(" - sizeof(DMUS_IO_TEMPO_ITEM): %u (chunkSize = %u)\n", StreamSize, Chunk.dwSize);
344     do {
345       IStream_Read (pStm, &item, sizeof(item), NULL);
346       ++nItem;
347       TRACE_(dmfile)("DMUS_IO_TEMPO_ITEM #%d\n", nItem);
348       TRACE_(dmfile)(" - lTime = %u\n", item.lTime);
349       TRACE_(dmfile)(" - dblTempo = %g\n", item.dblTempo);
350       pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_ITEM));
351       if (NULL == pNewItem) {
352         ERR(": no more memory\n");
353         return  E_OUTOFMEMORY;
354       }
355       pNewItem->item = item;
356       list_add_tail (&This->Items, &pNewItem->entry);
357       pNewItem = NULL;
358       StreamCount += sizeof(item);
359       TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
360     } while (StreamCount < StreamSize); 
361 #else    
362     liMove.QuadPart = Chunk.dwSize;
363     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
364 #endif
365     break;
366   }
367   default: {
368     TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
369     liMove.QuadPart = Chunk.dwSize;
370     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
371     return E_FAIL;
372   }
373   }
374 #endif
375
376   return S_OK;
377 }
378
379 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
380   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
381   FIXME("(%p): Saving not implemented yet\n", This);
382   return E_NOTIMPL;
383 }
384
385 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
386   ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
387   FIXME("(%p, %p): stub\n", This, pcbSize);
388   return E_NOTIMPL;
389 }
390
391 static const IPersistStreamVtbl DirectMusicTempoTrack_PersistStream_Vtbl = {
392   IDirectMusicTempoTrack_IPersistStream_QueryInterface,
393   IDirectMusicTempoTrack_IPersistStream_AddRef,
394   IDirectMusicTempoTrack_IPersistStream_Release,
395   IDirectMusicTempoTrack_IPersistStream_GetClassID,
396   IDirectMusicTempoTrack_IPersistStream_IsDirty,
397   IDirectMusicTempoTrack_IPersistStream_Load,
398   IDirectMusicTempoTrack_IPersistStream_Save,
399   IDirectMusicTempoTrack_IPersistStream_GetSizeMax
400 };
401
402 /* for ClassFactory */
403 HRESULT WINAPI DMUSIC_CreateDirectMusicTempoTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
404   IDirectMusicTempoTrack* track;
405         
406   track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicTempoTrack));
407   if (NULL == track) {
408     *ppobj = NULL;
409     return E_OUTOFMEMORY;
410   }
411   track->UnknownVtbl = &DirectMusicTempoTrack_Unknown_Vtbl;
412   track->TrackVtbl = &DirectMusicTempoTrack_Track_Vtbl;
413   track->PersistStreamVtbl = &DirectMusicTempoTrack_PersistStream_Vtbl;
414   track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
415   DM_STRUCT_INIT(track->pDesc);
416   track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
417   track->pDesc->guidClass = CLSID_DirectMusicTempoTrack;
418   track->ref = 0; /* will be inited by QueryInterface */
419   track->enabled = TRUE;
420   list_init (&track->Items);
421
422   return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);
423 }