gdiplus: Support GdipSetClipRegion in metafiles.
[wine.git] / dlls / dmstyle / dmutils.c
blobe55141094847b72eb739b6531d4685ce4191e47b
1 /* Debug and Helper Functions
3 * Copyright (C) 2004 Rok Mandeljc
4 * Copyright (C) 2004 Raphael Junqueira
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.
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.
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
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <string.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "wingdi.h"
31 #include "winuser.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35 #include "objbase.h"
37 #include "dmusici.h"
38 #include "dmusicf.h"
39 #include "dmusics.h"
41 #include "dmutils.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dmfile);
45 HRESULT IDirectMusicUtils_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
47 switch (pChunk->fccID) {
48 case DMUS_FOURCC_GUID_CHUNK: {
49 TRACE(": GUID chunk\n");
50 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
51 IStream_Read (pStm, &pDesc->guidObject, pChunk->dwSize, NULL);
52 break;
54 case DMUS_FOURCC_DATE_CHUNK: {
55 TRACE(": file date chunk\n");
56 pDesc->dwValidData |= DMUS_OBJ_DATE;
57 IStream_Read (pStm, &pDesc->ftDate, pChunk->dwSize, NULL);
58 break;
60 case DMUS_FOURCC_NAME_CHUNK: {
61 TRACE(": name chunk\n");
62 pDesc->dwValidData |= DMUS_OBJ_NAME;
63 IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
64 break;
66 case DMUS_FOURCC_FILE_CHUNK: {
67 TRACE(": file name chunk\n");
68 pDesc->dwValidData |= DMUS_OBJ_FILENAME;
69 IStream_Read (pStm, pDesc->wszFileName, pChunk->dwSize, NULL);
70 break;
72 case DMUS_FOURCC_VERSION_CHUNK: {
73 TRACE(": version chunk\n");
74 pDesc->dwValidData |= DMUS_OBJ_VERSION;
75 IStream_Read (pStm, &pDesc->vVersion, pChunk->dwSize, NULL);
76 break;
78 case DMUS_FOURCC_CATEGORY_CHUNK: {
79 TRACE(": category chunk\n");
80 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
81 IStream_Read (pStm, pDesc->wszCategory, pChunk->dwSize, NULL);
82 break;
84 default:
85 /* not handled */
86 return S_FALSE;
89 return S_OK;
92 HRESULT IDirectMusicUtils_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
94 LARGE_INTEGER liMove; /* used when skipping chunks */
96 /**
97 * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
98 * (though strings seem to be valid unicode)
100 switch (pChunk->fccID) {
102 case mmioFOURCC('I','N','A','M'):
103 case DMUS_FOURCC_UNAM_CHUNK: {
104 TRACE(": name chunk\n");
105 pDesc->dwValidData |= DMUS_OBJ_NAME;
106 IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
107 TRACE(" - wszName: %s\n", debugstr_w(pDesc->wszName));
108 break;
111 case mmioFOURCC('I','A','R','T'):
112 case DMUS_FOURCC_UART_CHUNK: {
113 TRACE(": artist chunk (ignored)\n");
114 liMove.QuadPart = pChunk->dwSize;
115 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
116 break;
118 case mmioFOURCC('I','C','O','P'):
119 case DMUS_FOURCC_UCOP_CHUNK: {
120 TRACE(": copyright chunk (ignored)\n");
121 liMove.QuadPart = pChunk->dwSize;
122 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
123 break;
125 case mmioFOURCC('I','S','B','J'):
126 case DMUS_FOURCC_USBJ_CHUNK: {
127 TRACE(": subject chunk (ignored)\n");
128 liMove.QuadPart = pChunk->dwSize;
129 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
130 break;
132 case mmioFOURCC('I','C','M','T'):
133 case DMUS_FOURCC_UCMT_CHUNK: {
134 TRACE(": comment chunk (ignored)\n");
135 liMove.QuadPart = pChunk->dwSize;
136 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
137 break;
139 default:
140 /* not handled */
141 return S_FALSE;
144 return S_OK;
147 HRESULT IDirectMusicUtils_IPersistStream_ParseReference (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicObject** ppObject) {
148 DMUS_PRIVATE_CHUNK Chunk;
149 DWORD ListSize[3], ListCount[3];
150 LARGE_INTEGER liMove; /* used when skipping chunks */
151 HRESULT hr;
153 DMUS_IO_REFERENCE ref;
154 DMUS_OBJECTDESC ref_desc;
156 memset(&ref, 0, sizeof(ref));
157 memset(&ref_desc, 0, sizeof(ref_desc));
159 if (pChunk->fccID != DMUS_FOURCC_REF_LIST) {
160 ERR(": %s chunk should be a REF list\n", debugstr_fourcc (pChunk->fccID));
161 return E_FAIL;
164 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
165 ListCount[0] = 0;
167 do {
168 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
169 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
170 TRACE(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
172 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, &ref_desc);
173 if (FAILED(hr)) return hr;
175 if (hr == S_FALSE) {
176 switch (Chunk.fccID) {
177 case DMUS_FOURCC_REF_CHUNK: {
178 TRACE(": Reference chunk\n");
179 if (Chunk.dwSize != sizeof(DMUS_IO_REFERENCE)) return E_FAIL;
180 IStream_Read (pStm, &ref, sizeof(DMUS_IO_REFERENCE), NULL);
181 TRACE(" - guidClassID: %s\n", debugstr_dmguid(&ref.guidClassID));
182 TRACE(" - dwValidData: %u\n", ref.dwValidData);
183 break;
185 default: {
186 TRACE(": unknown chunk (irrelevant & skipping)\n");
187 liMove.QuadPart = Chunk.dwSize;
188 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
189 break;
193 TRACE(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
194 } while (ListCount[0] < ListSize[0]);
196 ref_desc.dwValidData |= DMUS_OBJ_CLASS;
197 ref_desc.guidClass = ref.guidClassID;
199 TRACE("** DM Reference Begin of Load ***\n");
200 TRACE("With Desc:\n");
201 debugstr_DMUS_OBJECTDESC(&ref_desc);
204 LPDIRECTMUSICGETLOADER pGetLoader = NULL;
205 LPDIRECTMUSICLOADER pLoader = NULL;
207 IStream_QueryInterface (pStm, &IID_IDirectMusicGetLoader, (LPVOID*)&pGetLoader);
208 IDirectMusicGetLoader_GetLoader (pGetLoader, &pLoader);
209 IDirectMusicGetLoader_Release (pGetLoader);
211 hr = IDirectMusicLoader_GetObject (pLoader, &ref_desc, &IID_IDirectMusicObject, (LPVOID*)ppObject);
212 IDirectMusicLoader_Release (pLoader); /* release loader */
214 TRACE("** DM Reference End of Load ***\n");
216 return hr;
219 /* FOURCC to string conversion for debug messages */
220 const char *debugstr_fourcc (DWORD fourcc) {
221 if (!fourcc) return "'null'";
222 return wine_dbg_sprintf ("\'%c%c%c%c\'",
223 (char)(fourcc), (char)(fourcc >> 8),
224 (char)(fourcc >> 16), (char)(fourcc >> 24));
227 /* DMUS_VERSION struct to string conversion for debug messages */
228 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
229 if (!version) return "'null'";
230 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
231 HIWORD(version->dwVersionMS),LOWORD(version->dwVersionMS),
232 HIWORD(version->dwVersionLS), LOWORD(version->dwVersionLS));
235 /* month number into month name (for debugstr_filetime) */
236 static const char *debugstr_month (DWORD dwMonth) {
237 switch (dwMonth) {
238 case 1: return "January";
239 case 2: return "February";
240 case 3: return "March";
241 case 4: return "April";
242 case 5: return "May";
243 case 6: return "June";
244 case 7: return "July";
245 case 8: return "August";
246 case 9: return "September";
247 case 10: return "October";
248 case 11: return "November";
249 case 12: return "December";
250 default: return "Invalid";
254 /* FILETIME struct to string conversion for debug messages */
255 static const char *debugstr_filetime (const FILETIME *time) {
256 SYSTEMTIME sysTime;
258 if (!time) return "'null'";
260 FileTimeToSystemTime (time, &sysTime);
262 return wine_dbg_sprintf ("\'%02i. %s %04i %02i:%02i:%02i\'",
263 sysTime.wDay, debugstr_month(sysTime.wMonth), sysTime.wYear,
264 sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
267 /* returns name of given GUID */
268 const char *debugstr_dmguid (const GUID *id) {
269 static const guid_info guids[] = {
270 /* CLSIDs */
271 GE(CLSID_AudioVBScript),
272 GE(CLSID_DirectMusic),
273 GE(CLSID_DirectMusicAudioPathConfig),
274 GE(CLSID_DirectMusicAuditionTrack),
275 GE(CLSID_DirectMusicBand),
276 GE(CLSID_DirectMusicBandTrack),
277 GE(CLSID_DirectMusicChordMapTrack),
278 GE(CLSID_DirectMusicChordMap),
279 GE(CLSID_DirectMusicChordTrack),
280 GE(CLSID_DirectMusicCollection),
281 GE(CLSID_DirectMusicCommandTrack),
282 GE(CLSID_DirectMusicComposer),
283 GE(CLSID_DirectMusicContainer),
284 GE(CLSID_DirectMusicGraph),
285 GE(CLSID_DirectMusicLoader),
286 GE(CLSID_DirectMusicLyricsTrack),
287 GE(CLSID_DirectMusicMarkerTrack),
288 GE(CLSID_DirectMusicMelodyFormulationTrack),
289 GE(CLSID_DirectMusicMotifTrack),
290 GE(CLSID_DirectMusicMuteTrack),
291 GE(CLSID_DirectMusicParamControlTrack),
292 GE(CLSID_DirectMusicPatternTrack),
293 GE(CLSID_DirectMusicPerformance),
294 GE(CLSID_DirectMusicScript),
295 GE(CLSID_DirectMusicScriptAutoImpSegment),
296 GE(CLSID_DirectMusicScriptAutoImpPerformance),
297 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
298 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
299 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
300 GE(CLSID_DirectMusicScriptAutoImpSong),
301 GE(CLSID_DirectMusicScriptSourceCodeLoader),
302 GE(CLSID_DirectMusicScriptTrack),
303 GE(CLSID_DirectMusicSection),
304 GE(CLSID_DirectMusicSegment),
305 GE(CLSID_DirectMusicSegmentState),
306 GE(CLSID_DirectMusicSegmentTriggerTrack),
307 GE(CLSID_DirectMusicSegTriggerTrack),
308 GE(CLSID_DirectMusicSeqTrack),
309 GE(CLSID_DirectMusicSignPostTrack),
310 GE(CLSID_DirectMusicSong),
311 GE(CLSID_DirectMusicStyle),
312 GE(CLSID_DirectMusicStyleTrack),
313 GE(CLSID_DirectMusicSynth),
314 GE(CLSID_DirectMusicSynthSink),
315 GE(CLSID_DirectMusicSysExTrack),
316 GE(CLSID_DirectMusicTemplate),
317 GE(CLSID_DirectMusicTempoTrack),
318 GE(CLSID_DirectMusicTimeSigTrack),
319 GE(CLSID_DirectMusicWaveTrack),
320 GE(CLSID_DirectSoundWave),
321 /* IIDs */
322 GE(IID_IDirectMusic),
323 GE(IID_IDirectMusic2),
324 GE(IID_IDirectMusic8),
325 GE(IID_IDirectMusicAudioPath),
326 GE(IID_IDirectMusicBand),
327 GE(IID_IDirectMusicBuffer),
328 GE(IID_IDirectMusicChordMap),
329 GE(IID_IDirectMusicCollection),
330 GE(IID_IDirectMusicComposer),
331 GE(IID_IDirectMusicContainer),
332 GE(IID_IDirectMusicDownload),
333 GE(IID_IDirectMusicDownloadedInstrument),
334 GE(IID_IDirectMusicGetLoader),
335 GE(IID_IDirectMusicGraph),
336 GE(IID_IDirectMusicInstrument),
337 GE(IID_IDirectMusicLoader),
338 GE(IID_IDirectMusicLoader8),
339 GE(IID_IDirectMusicObject),
340 GE(IID_IDirectMusicPatternTrack),
341 GE(IID_IDirectMusicPerformance),
342 GE(IID_IDirectMusicPerformance2),
343 GE(IID_IDirectMusicPerformance8),
344 GE(IID_IDirectMusicPort),
345 GE(IID_IDirectMusicPortDownload),
346 GE(IID_IDirectMusicScript),
347 GE(IID_IDirectMusicSegment),
348 GE(IID_IDirectMusicSegment2),
349 GE(IID_IDirectMusicSegment8),
350 GE(IID_IDirectMusicSegmentState),
351 GE(IID_IDirectMusicSegmentState8),
352 GE(IID_IDirectMusicStyle),
353 GE(IID_IDirectMusicStyle8),
354 GE(IID_IDirectMusicSynth),
355 GE(IID_IDirectMusicSynth8),
356 GE(IID_IDirectMusicSynthSink),
357 GE(IID_IDirectMusicThru),
358 GE(IID_IDirectMusicTool),
359 GE(IID_IDirectMusicTool8),
360 GE(IID_IDirectMusicTrack),
361 GE(IID_IDirectMusicTrack8),
362 GE(IID_IUnknown),
363 GE(IID_IPersistStream),
364 GE(IID_IStream),
365 GE(IID_IClassFactory),
366 /* GUIDs */
367 GE(GUID_DirectMusicAllTypes),
368 GE(GUID_NOTIFICATION_CHORD),
369 GE(GUID_NOTIFICATION_COMMAND),
370 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
371 GE(GUID_NOTIFICATION_PERFORMANCE),
372 GE(GUID_NOTIFICATION_RECOMPOSE),
373 GE(GUID_NOTIFICATION_SEGMENT),
374 GE(GUID_BandParam),
375 GE(GUID_ChordParam),
376 GE(GUID_CommandParam),
377 GE(GUID_CommandParam2),
378 GE(GUID_CommandParamNext),
379 GE(GUID_IDirectMusicBand),
380 GE(GUID_IDirectMusicChordMap),
381 GE(GUID_IDirectMusicStyle),
382 GE(GUID_MuteParam),
383 GE(GUID_Play_Marker),
384 GE(GUID_RhythmParam),
385 GE(GUID_TempoParam),
386 GE(GUID_TimeSignature),
387 GE(GUID_Valid_Start_Time),
388 GE(GUID_Clear_All_Bands),
389 GE(GUID_ConnectToDLSCollection),
390 GE(GUID_Disable_Auto_Download),
391 GE(GUID_DisableTempo),
392 GE(GUID_DisableTimeSig),
393 GE(GUID_Download),
394 GE(GUID_DownloadToAudioPath),
395 GE(GUID_Enable_Auto_Download),
396 GE(GUID_EnableTempo),
397 GE(GUID_EnableTimeSig),
398 GE(GUID_IgnoreBankSelectForGM),
399 GE(GUID_SeedVariations),
400 GE(GUID_StandardMIDIFile),
401 GE(GUID_Unload),
402 GE(GUID_UnloadFromAudioPath),
403 GE(GUID_Variations),
404 GE(GUID_PerfMasterTempo),
405 GE(GUID_PerfMasterVolume),
406 GE(GUID_PerfMasterGrooveLevel),
407 GE(GUID_PerfAutoDownload),
408 GE(GUID_DefaultGMCollection),
409 GE(GUID_Synth_Default),
410 GE(GUID_Buffer_Reverb),
411 GE(GUID_Buffer_EnvReverb),
412 GE(GUID_Buffer_Stereo),
413 GE(GUID_Buffer_3D_Dry),
414 GE(GUID_Buffer_Mono),
415 GE(GUID_DMUS_PROP_GM_Hardware),
416 GE(GUID_DMUS_PROP_GS_Capable),
417 GE(GUID_DMUS_PROP_GS_Hardware),
418 GE(GUID_DMUS_PROP_DLS1),
419 GE(GUID_DMUS_PROP_DLS2),
420 GE(GUID_DMUS_PROP_Effects),
421 GE(GUID_DMUS_PROP_INSTRUMENT2),
422 GE(GUID_DMUS_PROP_LegacyCaps),
423 GE(GUID_DMUS_PROP_MemorySize),
424 GE(GUID_DMUS_PROP_SampleMemorySize),
425 GE(GUID_DMUS_PROP_SamplePlaybackRate),
426 GE(GUID_DMUS_PROP_SetSynthSink),
427 GE(GUID_DMUS_PROP_SinkUsesDSound),
428 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
429 GE(GUID_DMUS_PROP_SynthSink_WAVE),
430 GE(GUID_DMUS_PROP_Volume),
431 GE(GUID_DMUS_PROP_WavesReverb),
432 GE(GUID_DMUS_PROP_WriteLatency),
433 GE(GUID_DMUS_PROP_WritePeriod),
434 GE(GUID_DMUS_PROP_XG_Capable),
435 GE(GUID_DMUS_PROP_XG_Hardware)
438 unsigned int i;
440 if (!id) return "(null)";
441 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
442 if (IsEqualGUID(id, guids[i].guid))
443 return guids[i].name;
446 /* if we didn't find it, act like standard debugstr_guid */
447 return debugstr_guid(id);
450 /* generic flag-dumping function */
451 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
452 static char buffer[128] = "", *ptr = &buffer[0];
453 unsigned int i;
454 int size = sizeof(buffer);
456 for (i=0; i < num_names; i++) {
457 if ((flags & names[i].val)) {
458 int cnt = snprintf(ptr, size, "%s ", names[i].name);
459 if (cnt < 0 || cnt >= size) break;
460 size -= cnt;
461 ptr += cnt;
465 ptr = &buffer[0];
466 return ptr;
469 /* dump DMUS_OBJ flags */
470 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
471 static const flag_info flags[] = {
472 FE(DMUS_OBJ_OBJECT),
473 FE(DMUS_OBJ_CLASS),
474 FE(DMUS_OBJ_NAME),
475 FE(DMUS_OBJ_CATEGORY),
476 FE(DMUS_OBJ_FILENAME),
477 FE(DMUS_OBJ_FULLPATH),
478 FE(DMUS_OBJ_URL),
479 FE(DMUS_OBJ_VERSION),
480 FE(DMUS_OBJ_DATE),
481 FE(DMUS_OBJ_LOADED),
482 FE(DMUS_OBJ_MEMORY),
483 FE(DMUS_OBJ_STREAM)
485 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
488 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
489 if (pDesc) {
490 char buffer[1024], *ptr = buffer;
492 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
493 ptr += sprintf(ptr, " - dwSize = 0x%08X\n", pDesc->dwSize);
494 ptr += sprintf(ptr, " - dwValidData = 0x%08X ( %s)\n", pDesc->dwValidData, debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
495 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
496 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
497 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = %s\n", debugstr_filetime (&pDesc->ftDate));
498 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
499 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
500 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
501 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
502 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
503 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
504 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p\n", pDesc->pStream);
506 return wine_dbg_sprintf("%s", buffer);
507 } else {
508 return wine_dbg_sprintf("(NULL)");