Avoid excessive heap memory reallocation when generating EMF
[wine] / dlls / dmstyle / motiftrack.c
1 /* IDirectMusicMotifTrack Implementation
2  *
3  * Copyright (C) 2003 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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
13  * GNU Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27
28 #include "dmstyle_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
31 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
32
33 /*****************************************************************************
34  * IDirectMusicMotifTrack implementation
35  */
36 /* IDirectMusicMotifTrack IUnknown part: */
37 HRESULT WINAPI IDirectMusicMotifTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj)
38 {
39         ICOM_THIS(IDirectMusicMotifTrack,iface);
40
41         if (IsEqualIID (riid, &IID_IUnknown) || 
42             IsEqualIID (riid, &IID_IDirectMusicTrack) ||
43             IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
44                 IDirectMusicMotifTrack_AddRef(iface);
45                 *ppobj = This;
46                 return S_OK;
47         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
48                 IDirectMusicMotifTrackStream_AddRef ((LPPERSISTSTREAM)This->pStream);
49                 *ppobj = This->pStream;
50                 return S_OK;
51         }
52
53         WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
54         return E_NOINTERFACE;
55 }
56
57 ULONG WINAPI IDirectMusicMotifTrack_AddRef (LPDIRECTMUSICTRACK8 iface)
58 {
59         ICOM_THIS(IDirectMusicMotifTrack,iface);
60         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
61         return ++(This->ref);
62 }
63
64 ULONG WINAPI IDirectMusicMotifTrack_Release (LPDIRECTMUSICTRACK8 iface)
65 {
66         ICOM_THIS(IDirectMusicMotifTrack,iface);
67         ULONG ref = --This->ref;
68         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
69         if (ref == 0) {
70                 HeapFree(GetProcessHeap(), 0, This);
71         }
72         return ref;
73 }
74
75 /* IDirectMusicMotifTrack IDirectMusicTrack part: */
76 HRESULT WINAPI IDirectMusicMotifTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
77 {
78         ICOM_THIS(IDirectMusicMotifTrack,iface);
79
80         FIXME("(%p, %p): stub\n", This, pSegment);
81
82         return S_OK;
83 }
84
85 HRESULT WINAPI IDirectMusicMotifTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
86 {
87         ICOM_THIS(IDirectMusicMotifTrack,iface);
88
89         FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
90
91         return S_OK;
92 }
93
94 HRESULT WINAPI IDirectMusicMotifTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
95 {
96         ICOM_THIS(IDirectMusicMotifTrack,iface);
97
98         FIXME("(%p, %p): stub\n", This, pStateData);
99
100         return S_OK;
101 }
102
103 HRESULT WINAPI IDirectMusicMotifTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
104 {
105         ICOM_THIS(IDirectMusicMotifTrack,iface);
106
107         FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
108
109         return S_OK;
110 }
111
112 HRESULT WINAPI IDirectMusicMotifTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam)
113 {
114         ICOM_THIS(IDirectMusicMotifTrack,iface);
115
116         FIXME("(%p, %s, %ld, %p, %p): stub\n", This, debugstr_guid(rguidType), mtTime, pmtNext, pParam);
117
118         return S_OK;
119 }
120
121 HRESULT WINAPI IDirectMusicMotifTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam)
122 {
123         ICOM_THIS(IDirectMusicMotifTrack,iface);
124
125         FIXME("(%p, %s, %ld, %p): stub\n", This, debugstr_guid(rguidType), mtTime, pParam);
126
127         return S_OK;
128 }
129
130 HRESULT WINAPI IDirectMusicMotifTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType)
131 {
132         ICOM_THIS(IDirectMusicMotifTrack,iface);
133
134         TRACE("(%p, %s): ", This, debugstr_guid(rguidType));
135         if (IsEqualGUID (rguidType, &GUID_DisableTimeSig)
136                 || IsEqualGUID (rguidType, &GUID_EnableTimeSig)
137                 || IsEqualGUID (rguidType, &GUID_SeedVariations)
138                 || IsEqualGUID (rguidType, &GUID_Valid_Start_Time)) {
139                 TRACE("param supported\n");
140                 return S_OK;
141                 }
142
143         TRACE("param unsupported\n");
144         return DMUS_E_TYPE_UNSUPPORTED;
145 }
146
147 HRESULT WINAPI IDirectMusicMotifTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType)
148 {
149         ICOM_THIS(IDirectMusicMotifTrack,iface);
150
151         FIXME("(%p, %s): stub\n", This, debugstr_guid(rguidNotificationType));
152
153         return S_OK;
154 }
155
156 HRESULT WINAPI IDirectMusicMotifTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType)
157 {
158         ICOM_THIS(IDirectMusicMotifTrack,iface);
159
160         FIXME("(%p, %s): stub\n", This, debugstr_guid(rguidNotificationType));
161
162         return S_OK;
163 }
164
165 HRESULT WINAPI IDirectMusicMotifTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack)
166 {
167         ICOM_THIS(IDirectMusicMotifTrack,iface);
168
169         FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
170
171         return S_OK;
172 }
173
174 /* IDirectMusicMotifTrack IDirectMusicTrack8 part: */
175 HRESULT WINAPI IDirectMusicMotifTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
176 {
177         ICOM_THIS(IDirectMusicMotifTrack,iface);
178
179         FIXME("(%p, %p, %lli, %lli, %lli, %ld, %p, %p, %ld): stub\n", This, pStateData, rtStart, rtEnd, rtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
180
181         return S_OK;
182 }
183
184 HRESULT WINAPI IDirectMusicMotifTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags)
185 {
186         ICOM_THIS(IDirectMusicMotifTrack,iface);
187
188         FIXME("(%p, %s, %lli, %p, %p, %p, %ld): stub\n", This, debugstr_guid(rguidType), rtTime, prtNext, pParam, pStateData, dwFlags);
189
190         return S_OK;
191 }
192
193 HRESULT WINAPI IDirectMusicMotifTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags)
194 {
195         ICOM_THIS(IDirectMusicMotifTrack,iface);
196
197         FIXME("(%p, %s, %lli, %p, %p, %ld): stub\n", This, debugstr_guid(rguidType), rtTime, pParam, pStateData, dwFlags);
198
199         return S_OK;
200 }
201
202 HRESULT WINAPI IDirectMusicMotifTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack)
203 {
204         ICOM_THIS(IDirectMusicMotifTrack,iface);
205
206         FIXME("(%p, %p, %ld, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
207
208         return S_OK;
209 }
210
211 HRESULT WINAPI IDirectMusicMotifTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack)
212 {
213         ICOM_THIS(IDirectMusicMotifTrack,iface);
214
215         FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
216
217         return S_OK;
218 }
219
220 ICOM_VTABLE(IDirectMusicTrack8) DirectMusicMotifTrack_Vtbl =
221 {
222     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
223         IDirectMusicMotifTrack_QueryInterface,
224         IDirectMusicMotifTrack_AddRef,
225         IDirectMusicMotifTrack_Release,
226         IDirectMusicMotifTrack_Init,
227         IDirectMusicMotifTrack_InitPlay,
228         IDirectMusicMotifTrack_EndPlay,
229         IDirectMusicMotifTrack_Play,
230         IDirectMusicMotifTrack_GetParam,
231         IDirectMusicMotifTrack_SetParam,
232         IDirectMusicMotifTrack_IsParamSupported,
233         IDirectMusicMotifTrack_AddNotificationType,
234         IDirectMusicMotifTrack_RemoveNotificationType,
235         IDirectMusicMotifTrack_Clone,
236         IDirectMusicMotifTrack_PlayEx,
237         IDirectMusicMotifTrack_GetParamEx,
238         IDirectMusicMotifTrack_SetParamEx,
239         IDirectMusicMotifTrack_Compose,
240         IDirectMusicMotifTrack_Join
241 };
242
243 /* for ClassFactory */
244 HRESULT WINAPI DMUSIC_CreateDirectMusicMotifTrack (LPCGUID lpcGUID, LPDIRECTMUSICTRACK8 *ppTrack, LPUNKNOWN pUnkOuter)
245 {
246         IDirectMusicMotifTrack* track;
247         
248         if (IsEqualIID (lpcGUID, &IID_IDirectMusicTrack)
249                 || IsEqualIID (lpcGUID, &IID_IDirectMusicTrack8)) {
250                 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicMotifTrack));
251                 if (NULL == track) {
252                         *ppTrack = (LPDIRECTMUSICTRACK8) NULL;
253                         return E_OUTOFMEMORY;
254                 }
255                 track->lpVtbl = &DirectMusicMotifTrack_Vtbl;
256                 track->ref = 1;
257                 track->pStream = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicMotifTrackStream));
258                 track->pStream->lpVtbl = &DirectMusicMotifTrackStream_Vtbl;
259                 track->pStream->ref = 1;        
260                 track->pStream->pParentTrack = track;
261                 *ppTrack = (LPDIRECTMUSICTRACK8) track;
262                 return S_OK;
263         }
264         
265         WARN("No interface found\n");
266         return E_NOINTERFACE;
267 }
268
269
270 /*****************************************************************************
271  * IDirectMusicMotifTrackStream implementation
272  */
273 /* IDirectMusicMotifTrackStream IUnknown part follow: */
274 HRESULT WINAPI IDirectMusicMotifTrackStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj)
275 {
276         ICOM_THIS(IDirectMusicMotifTrackStream,iface);
277
278         if (IsEqualIID (riid, &IID_IUnknown)
279                 || IsEqualIID (riid, &IID_IPersistStream)) {
280                 IDirectMusicMotifTrackStream_AddRef(iface);
281                 *ppobj = This;
282                 return S_OK;
283         }
284
285         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
286         return E_NOINTERFACE;
287 }
288
289 ULONG WINAPI IDirectMusicMotifTrackStream_AddRef (LPPERSISTSTREAM iface)
290 {
291         ICOM_THIS(IDirectMusicMotifTrackStream,iface);
292         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
293         return ++(This->ref);
294 }
295
296 ULONG WINAPI IDirectMusicMotifTrackStream_Release (LPPERSISTSTREAM iface)
297 {
298         ICOM_THIS(IDirectMusicMotifTrackStream,iface);
299         ULONG ref = --This->ref;
300         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
301         if (ref == 0) {
302                 HeapFree(GetProcessHeap(), 0, This);
303         }
304         return ref;
305 }
306
307 /* IDirectMusicMotifTrackStream IPersist part: */
308 HRESULT WINAPI IDirectMusicMotifTrackStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID)
309 {
310         return E_NOTIMPL;
311 }
312
313 /* IDirectMusicMotifTrackStream IPersistStream part: */
314 HRESULT WINAPI IDirectMusicMotifTrackStream_IsDirty (LPPERSISTSTREAM iface)
315 {
316         return E_NOTIMPL;
317 }
318
319 HRESULT WINAPI IDirectMusicMotifTrackStream_Load (LPPERSISTSTREAM iface, IStream* pStm)
320 {
321         FIXME(": Loading not implemented yet\n");
322         return S_OK;
323 }
324
325 HRESULT WINAPI IDirectMusicMotifTrackStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty)
326 {
327         return E_NOTIMPL;
328 }
329
330 HRESULT WINAPI IDirectMusicMotifTrackStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize)
331 {
332         return E_NOTIMPL;
333 }
334
335 ICOM_VTABLE(IPersistStream) DirectMusicMotifTrackStream_Vtbl =
336 {
337     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
338         IDirectMusicMotifTrackStream_QueryInterface,
339         IDirectMusicMotifTrackStream_AddRef,
340         IDirectMusicMotifTrackStream_Release,
341         IDirectMusicMotifTrackStream_GetClassID,
342         IDirectMusicMotifTrackStream_IsDirty,
343         IDirectMusicMotifTrackStream_Load,
344         IDirectMusicMotifTrackStream_Save,
345         IDirectMusicMotifTrackStream_GetSizeMax
346 };