ole32/tests: Relax the reference counting tests a bit. We only care whether reference...
[wine/hramrach.git] / dlls / dswave / dswave_main.c
blobb907e9e599b8f6cafedbe6bc559b3be93a68d12f
1 /* DirectMusic Wave Main
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 "config.h"
21 #include "wine/port.h"
23 #include <stdio.h>
25 #include "dswave_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(dswave);
29 LONG DSWAVE_refCount = 0;
31 typedef struct {
32 const IClassFactoryVtbl *lpVtbl;
33 } IClassFactoryImpl;
35 /******************************************************************
36 * DirectMusicWave ClassFactory
38 static HRESULT WINAPI WaveCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
39 FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
41 if (ppobj == NULL) return E_POINTER;
43 return E_NOINTERFACE;
46 static ULONG WINAPI WaveCF_AddRef(LPCLASSFACTORY iface) {
47 DSWAVE_LockModule();
49 return 2; /* non-heap based object */
52 static ULONG WINAPI WaveCF_Release(LPCLASSFACTORY iface) {
53 DSWAVE_UnlockModule();
55 return 1; /* non-heap based object */
58 static HRESULT WINAPI WaveCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
59 TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
61 return DMUSIC_CreateDirectMusicWaveImpl (riid, ppobj, pOuter);
64 static HRESULT WINAPI WaveCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
65 TRACE("(%d)\n", dolock);
67 if (dolock)
68 DSWAVE_LockModule();
69 else
70 DSWAVE_UnlockModule();
72 return S_OK;
75 static const IClassFactoryVtbl WaveCF_Vtbl = {
76 WaveCF_QueryInterface,
77 WaveCF_AddRef,
78 WaveCF_Release,
79 WaveCF_CreateInstance,
80 WaveCF_LockServer
83 static IClassFactoryImpl Wave_CF = {&WaveCF_Vtbl};
85 /******************************************************************
86 * DllMain
90 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
91 if (fdwReason == DLL_PROCESS_ATTACH) {
92 DisableThreadLibraryCalls(hinstDLL);
93 /* FIXME: Initialisation */
94 } else if (fdwReason == DLL_PROCESS_DETACH) {
95 /* FIXME: Cleanup */
98 return TRUE;
102 /******************************************************************
103 * DllCanUnloadNow (DSWAVE.@)
107 HRESULT WINAPI DllCanUnloadNow(void)
109 return DSWAVE_refCount != 0 ? S_FALSE : S_OK;
113 /******************************************************************
114 * DllGetClassObject (DSWAVE.@)
118 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
120 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
121 if (IsEqualCLSID (rclsid, &CLSID_DirectSoundWave) && IsEqualIID (riid, &IID_IClassFactory)) {
122 *ppv = &Wave_CF;
123 IClassFactory_AddRef((IClassFactory*)*ppv);
124 return S_OK;
127 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
128 return CLASS_E_CLASSNOTAVAILABLE;
131 /******************************************************************
132 * Helper functions
136 /* FOURCC to string conversion for debug messages */
137 const char *debugstr_fourcc (DWORD fourcc) {
138 if (!fourcc) return "'null'";
139 return wine_dbg_sprintf ("\'%c%c%c%c\'",
140 (char)(fourcc), (char)(fourcc >> 8),
141 (char)(fourcc >> 16), (char)(fourcc >> 24));
144 /* DMUS_VERSION struct to string conversion for debug messages */
145 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
146 if (!version) return "'null'";
147 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
148 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
149 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
152 /* returns name of given GUID */
153 const char *debugstr_dmguid (const GUID *id) {
154 static const guid_info guids[] = {
155 /* CLSIDs */
156 GE(CLSID_AudioVBScript),
157 GE(CLSID_DirectMusic),
158 GE(CLSID_DirectMusicAudioPath),
159 GE(CLSID_DirectMusicAudioPathConfig),
160 GE(CLSID_DirectMusicAuditionTrack),
161 GE(CLSID_DirectMusicBand),
162 GE(CLSID_DirectMusicBandTrack),
163 GE(CLSID_DirectMusicChordMapTrack),
164 GE(CLSID_DirectMusicChordMap),
165 GE(CLSID_DirectMusicChordTrack),
166 GE(CLSID_DirectMusicCollection),
167 GE(CLSID_DirectMusicCommandTrack),
168 GE(CLSID_DirectMusicComposer),
169 GE(CLSID_DirectMusicContainer),
170 GE(CLSID_DirectMusicGraph),
171 GE(CLSID_DirectMusicLoader),
172 GE(CLSID_DirectMusicLyricsTrack),
173 GE(CLSID_DirectMusicMarkerTrack),
174 GE(CLSID_DirectMusicMelodyFormulationTrack),
175 GE(CLSID_DirectMusicMotifTrack),
176 GE(CLSID_DirectMusicMuteTrack),
177 GE(CLSID_DirectMusicParamControlTrack),
178 GE(CLSID_DirectMusicPatternTrack),
179 GE(CLSID_DirectMusicPerformance),
180 GE(CLSID_DirectMusicScript),
181 GE(CLSID_DirectMusicScriptAutoImpSegment),
182 GE(CLSID_DirectMusicScriptAutoImpPerformance),
183 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
184 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
185 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
186 GE(CLSID_DirectMusicScriptAutoImpSong),
187 GE(CLSID_DirectMusicScriptSourceCodeLoader),
188 GE(CLSID_DirectMusicScriptTrack),
189 GE(CLSID_DirectMusicSection),
190 GE(CLSID_DirectMusicSegment),
191 GE(CLSID_DirectMusicSegmentState),
192 GE(CLSID_DirectMusicSegmentTriggerTrack),
193 GE(CLSID_DirectMusicSegTriggerTrack),
194 GE(CLSID_DirectMusicSeqTrack),
195 GE(CLSID_DirectMusicSignPostTrack),
196 GE(CLSID_DirectMusicSong),
197 GE(CLSID_DirectMusicStyle),
198 GE(CLSID_DirectMusicStyleTrack),
199 GE(CLSID_DirectMusicSynth),
200 GE(CLSID_DirectMusicSynthSink),
201 GE(CLSID_DirectMusicSysExTrack),
202 GE(CLSID_DirectMusicTemplate),
203 GE(CLSID_DirectMusicTempoTrack),
204 GE(CLSID_DirectMusicTimeSigTrack),
205 GE(CLSID_DirectMusicWaveTrack),
206 GE(CLSID_DirectSoundWave),
207 /* IIDs */
208 GE(IID_IDirectMusic),
209 GE(IID_IDirectMusic2),
210 GE(IID_IDirectMusic8),
211 GE(IID_IDirectMusicAudioPath),
212 GE(IID_IDirectMusicBand),
213 GE(IID_IDirectMusicBuffer),
214 GE(IID_IDirectMusicChordMap),
215 GE(IID_IDirectMusicCollection),
216 GE(IID_IDirectMusicComposer),
217 GE(IID_IDirectMusicContainer),
218 GE(IID_IDirectMusicDownload),
219 GE(IID_IDirectMusicDownloadedInstrument),
220 GE(IID_IDirectMusicGetLoader),
221 GE(IID_IDirectMusicGraph),
222 GE(IID_IDirectMusicInstrument),
223 GE(IID_IDirectMusicLoader),
224 GE(IID_IDirectMusicLoader8),
225 GE(IID_IDirectMusicObject),
226 GE(IID_IDirectMusicPatternTrack),
227 GE(IID_IDirectMusicPerformance),
228 GE(IID_IDirectMusicPerformance2),
229 GE(IID_IDirectMusicPerformance8),
230 GE(IID_IDirectMusicPort),
231 GE(IID_IDirectMusicPortDownload),
232 GE(IID_IDirectMusicScript),
233 GE(IID_IDirectMusicSegment),
234 GE(IID_IDirectMusicSegment2),
235 GE(IID_IDirectMusicSegment8),
236 GE(IID_IDirectMusicSegmentState),
237 GE(IID_IDirectMusicSegmentState8),
238 GE(IID_IDirectMusicStyle),
239 GE(IID_IDirectMusicStyle8),
240 GE(IID_IDirectMusicSynth),
241 GE(IID_IDirectMusicSynth8),
242 GE(IID_IDirectMusicSynthSink),
243 GE(IID_IDirectMusicThru),
244 GE(IID_IDirectMusicTool),
245 GE(IID_IDirectMusicTool8),
246 GE(IID_IDirectMusicTrack),
247 GE(IID_IDirectMusicTrack8),
248 GE(IID_IUnknown),
249 GE(IID_IPersistStream),
250 GE(IID_IStream),
251 GE(IID_IClassFactory),
252 /* GUIDs */
253 GE(GUID_DirectMusicAllTypes),
254 GE(GUID_NOTIFICATION_CHORD),
255 GE(GUID_NOTIFICATION_COMMAND),
256 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
257 GE(GUID_NOTIFICATION_PERFORMANCE),
258 GE(GUID_NOTIFICATION_RECOMPOSE),
259 GE(GUID_NOTIFICATION_SEGMENT),
260 GE(GUID_BandParam),
261 GE(GUID_ChordParam),
262 GE(GUID_CommandParam),
263 GE(GUID_CommandParam2),
264 GE(GUID_CommandParamNext),
265 GE(GUID_IDirectMusicBand),
266 GE(GUID_IDirectMusicChordMap),
267 GE(GUID_IDirectMusicStyle),
268 GE(GUID_MuteParam),
269 GE(GUID_Play_Marker),
270 GE(GUID_RhythmParam),
271 GE(GUID_TempoParam),
272 GE(GUID_TimeSignature),
273 GE(GUID_Valid_Start_Time),
274 GE(GUID_Clear_All_Bands),
275 GE(GUID_ConnectToDLSCollection),
276 GE(GUID_Disable_Auto_Download),
277 GE(GUID_DisableTempo),
278 GE(GUID_DisableTimeSig),
279 GE(GUID_Download),
280 GE(GUID_DownloadToAudioPath),
281 GE(GUID_Enable_Auto_Download),
282 GE(GUID_EnableTempo),
283 GE(GUID_EnableTimeSig),
284 GE(GUID_IgnoreBankSelectForGM),
285 GE(GUID_SeedVariations),
286 GE(GUID_StandardMIDIFile),
287 GE(GUID_Unload),
288 GE(GUID_UnloadFromAudioPath),
289 GE(GUID_Variations),
290 GE(GUID_PerfMasterTempo),
291 GE(GUID_PerfMasterVolume),
292 GE(GUID_PerfMasterGrooveLevel),
293 GE(GUID_PerfAutoDownload),
294 GE(GUID_DefaultGMCollection),
295 GE(GUID_Synth_Default),
296 GE(GUID_Buffer_Reverb),
297 GE(GUID_Buffer_EnvReverb),
298 GE(GUID_Buffer_Stereo),
299 GE(GUID_Buffer_3D_Dry),
300 GE(GUID_Buffer_Mono),
301 GE(GUID_DMUS_PROP_GM_Hardware),
302 GE(GUID_DMUS_PROP_GS_Capable),
303 GE(GUID_DMUS_PROP_GS_Hardware),
304 GE(GUID_DMUS_PROP_DLS1),
305 GE(GUID_DMUS_PROP_DLS2),
306 GE(GUID_DMUS_PROP_Effects),
307 GE(GUID_DMUS_PROP_INSTRUMENT2),
308 GE(GUID_DMUS_PROP_LegacyCaps),
309 GE(GUID_DMUS_PROP_MemorySize),
310 GE(GUID_DMUS_PROP_SampleMemorySize),
311 GE(GUID_DMUS_PROP_SamplePlaybackRate),
312 GE(GUID_DMUS_PROP_SetSynthSink),
313 GE(GUID_DMUS_PROP_SinkUsesDSound),
314 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
315 GE(GUID_DMUS_PROP_SynthSink_WAVE),
316 GE(GUID_DMUS_PROP_Volume),
317 GE(GUID_DMUS_PROP_WavesReverb),
318 GE(GUID_DMUS_PROP_WriteLatency),
319 GE(GUID_DMUS_PROP_WritePeriod),
320 GE(GUID_DMUS_PROP_XG_Capable),
321 GE(GUID_DMUS_PROP_XG_Hardware)
324 unsigned int i;
326 if (!id) return "(null)";
328 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
329 if (IsEqualGUID(id, guids[i].guid))
330 return guids[i].name;
332 /* if we didn't find it, act like standard debugstr_guid */
333 return debugstr_guid(id);
336 /* generic flag-dumping function */
337 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
338 char buffer[128] = "", *ptr = &buffer[0];
339 unsigned int i;
340 int size = sizeof(buffer);
342 for (i=0; i < num_names; i++)
344 if ((flags & names[i].val) || /* standard flag*/
345 ((!flags) && (!names[i].val))) { /* zero value only */
346 int cnt = snprintf(ptr, size, "%s ", names[i].name);
347 if (cnt < 0 || cnt >= size) break;
348 size -= cnt;
349 ptr += cnt;
353 return wine_dbg_sprintf("%s", buffer);
356 /* dump DMUS_OBJ flags */
357 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
358 static const flag_info flags[] = {
359 FE(DMUS_OBJ_OBJECT),
360 FE(DMUS_OBJ_CLASS),
361 FE(DMUS_OBJ_NAME),
362 FE(DMUS_OBJ_CATEGORY),
363 FE(DMUS_OBJ_FILENAME),
364 FE(DMUS_OBJ_FULLPATH),
365 FE(DMUS_OBJ_URL),
366 FE(DMUS_OBJ_VERSION),
367 FE(DMUS_OBJ_DATE),
368 FE(DMUS_OBJ_LOADED),
369 FE(DMUS_OBJ_MEMORY),
370 FE(DMUS_OBJ_STREAM)
372 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
375 /* dump whole DMUS_OBJECTDESC struct */
376 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
377 if (pDesc) {
378 char buffer[1024] = "", *ptr = &buffer[0];
380 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
381 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
382 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
383 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
384 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
385 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
386 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
387 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
388 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
389 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
390 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
391 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
392 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
394 return wine_dbg_sprintf("%s", buffer);
395 } else {
396 return wine_dbg_sprintf("(NULL)");