riched20: Move underline drawing to a common function.
[wine.git] / dlls / dmcompos / dmcompos_main.c
blobe82ca945f5bdacc9b481b7943b3f58ad282c9172
1 /* DirectMusicComposer 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 "dmcompos_private.h"
24 #include "rpcproxy.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmcompos);
28 static HINSTANCE instance;
29 LONG DMCOMPOS_refCount = 0;
31 typedef struct {
32 IClassFactory IClassFactory_iface;
33 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
34 } IClassFactoryImpl;
36 static HRESULT WINAPI create_direct_music_template(REFIID riid, void **ppv, IUnknown *pUnkOuter)
38 FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
40 return E_NOINTERFACE;
43 /******************************************************************
44 * IClassFactory implementation
46 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
48 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
53 if (ppv == NULL)
54 return E_POINTER;
56 if (IsEqualGUID(&IID_IUnknown, riid))
57 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
58 else if (IsEqualGUID(&IID_IClassFactory, riid))
59 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
60 else {
61 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
62 *ppv = NULL;
63 return E_NOINTERFACE;
66 *ppv = iface;
67 IUnknown_AddRef((IUnknown*)*ppv);
68 return S_OK;
71 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
73 DMCOMPOS_LockModule();
75 return 2; /* non-heap based object */
78 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
80 DMCOMPOS_UnlockModule();
82 return 1; /* non-heap based object */
85 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
86 REFIID riid, void **ppv)
88 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
90 TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
92 return This->fnCreateInstance(riid, ppv, pUnkOuter);
95 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
97 TRACE("(%d)\n", dolock);
99 if (dolock)
100 DMCOMPOS_LockModule();
101 else
102 DMCOMPOS_UnlockModule();
104 return S_OK;
107 static const IClassFactoryVtbl classfactory_vtbl = {
108 ClassFactory_QueryInterface,
109 ClassFactory_AddRef,
110 ClassFactory_Release,
111 ClassFactory_CreateInstance,
112 ClassFactory_LockServer
115 static IClassFactoryImpl ChordMap_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicChordMapImpl};
116 static IClassFactoryImpl Composer_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicComposerImpl};
117 static IClassFactoryImpl ChordMapTrack_CF = {{&classfactory_vtbl},
118 DMUSIC_CreateDirectMusicChordMapTrack};
119 static IClassFactoryImpl Template_CF = {{&classfactory_vtbl}, create_direct_music_template};
120 static IClassFactoryImpl SignPostTrack_CF = {{&classfactory_vtbl},
121 DMUSIC_CreateDirectMusicSignPostTrack};
123 /******************************************************************
124 * DllMain
128 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
129 if (fdwReason == DLL_PROCESS_ATTACH) {
130 instance = hinstDLL;
131 DisableThreadLibraryCalls(hinstDLL);
132 /* FIXME: Initialisation */
134 else if (fdwReason == DLL_PROCESS_DETACH) {
135 /* FIXME: Cleanup */
138 return TRUE;
142 /******************************************************************
143 * DllCanUnloadNow (DMCOMPOS.@)
147 HRESULT WINAPI DllCanUnloadNow(void) {
148 return DMCOMPOS_refCount != 0 ? S_FALSE : S_OK;
152 /******************************************************************
153 * DllGetClassObject (DMCOMPOS.@)
157 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
158 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
159 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordMap) && IsEqualIID (riid, &IID_IClassFactory)) {
160 *ppv = &ChordMap_CF;
161 IClassFactory_AddRef((IClassFactory*)*ppv);
162 return S_OK;
163 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicComposer) && IsEqualIID (riid, &IID_IClassFactory)) {
164 *ppv = &Composer_CF;
165 IClassFactory_AddRef((IClassFactory*)*ppv);
166 return S_OK;
167 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordMapTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
168 *ppv = &ChordMapTrack_CF;
169 IClassFactory_AddRef((IClassFactory*)*ppv);
170 return S_OK;
171 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTemplate) && IsEqualIID (riid, &IID_IClassFactory)) {
172 *ppv = &Template_CF;
173 IClassFactory_AddRef((IClassFactory*)*ppv);
174 return S_OK;
175 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSignPostTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
176 *ppv = &SignPostTrack_CF;
177 IClassFactory_AddRef((IClassFactory*)*ppv);
178 return S_OK;
181 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
182 return CLASS_E_CLASSNOTAVAILABLE;
185 /***********************************************************************
186 * DllRegisterServer (DMCOMPOS.@)
188 HRESULT WINAPI DllRegisterServer(void)
190 return __wine_register_resources( instance );
193 /***********************************************************************
194 * DllUnregisterServer (DMCOMPOS.@)
196 HRESULT WINAPI DllUnregisterServer(void)
198 return __wine_unregister_resources( instance );
201 /******************************************************************
202 * Helper functions
206 /* FOURCC to string conversion for debug messages */
207 const char *debugstr_fourcc (DWORD fourcc) {
208 if (!fourcc) return "'null'";
209 return wine_dbg_sprintf ("\'%c%c%c%c\'",
210 (char)(fourcc), (char)(fourcc >> 8),
211 (char)(fourcc >> 16), (char)(fourcc >> 24));
214 /* DMUS_VERSION struct to string conversion for debug messages */
215 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
216 if (!version) return "'null'";
217 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
218 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
219 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
222 /* returns name of given GUID */
223 const char *debugstr_dmguid (const GUID *id) {
224 static const guid_info guids[] = {
225 /* CLSIDs */
226 GE(CLSID_AudioVBScript),
227 GE(CLSID_DirectMusic),
228 GE(CLSID_DirectMusicAudioPath),
229 GE(CLSID_DirectMusicAudioPathConfig),
230 GE(CLSID_DirectMusicAuditionTrack),
231 GE(CLSID_DirectMusicBand),
232 GE(CLSID_DirectMusicBandTrack),
233 GE(CLSID_DirectMusicChordMapTrack),
234 GE(CLSID_DirectMusicChordMap),
235 GE(CLSID_DirectMusicChordTrack),
236 GE(CLSID_DirectMusicCollection),
237 GE(CLSID_DirectMusicCommandTrack),
238 GE(CLSID_DirectMusicComposer),
239 GE(CLSID_DirectMusicContainer),
240 GE(CLSID_DirectMusicGraph),
241 GE(CLSID_DirectMusicLoader),
242 GE(CLSID_DirectMusicLyricsTrack),
243 GE(CLSID_DirectMusicMarkerTrack),
244 GE(CLSID_DirectMusicMelodyFormulationTrack),
245 GE(CLSID_DirectMusicMotifTrack),
246 GE(CLSID_DirectMusicMuteTrack),
247 GE(CLSID_DirectMusicParamControlTrack),
248 GE(CLSID_DirectMusicPatternTrack),
249 GE(CLSID_DirectMusicPerformance),
250 GE(CLSID_DirectMusicScript),
251 GE(CLSID_DirectMusicScriptAutoImpSegment),
252 GE(CLSID_DirectMusicScriptAutoImpPerformance),
253 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
254 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
255 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
256 GE(CLSID_DirectMusicScriptAutoImpSong),
257 GE(CLSID_DirectMusicScriptSourceCodeLoader),
258 GE(CLSID_DirectMusicScriptTrack),
259 GE(CLSID_DirectMusicSection),
260 GE(CLSID_DirectMusicSegment),
261 GE(CLSID_DirectMusicSegmentState),
262 GE(CLSID_DirectMusicSegmentTriggerTrack),
263 GE(CLSID_DirectMusicSegTriggerTrack),
264 GE(CLSID_DirectMusicSeqTrack),
265 GE(CLSID_DirectMusicSignPostTrack),
266 GE(CLSID_DirectMusicSong),
267 GE(CLSID_DirectMusicStyle),
268 GE(CLSID_DirectMusicStyleTrack),
269 GE(CLSID_DirectMusicSynth),
270 GE(CLSID_DirectMusicSynthSink),
271 GE(CLSID_DirectMusicSysExTrack),
272 GE(CLSID_DirectMusicTemplate),
273 GE(CLSID_DirectMusicTempoTrack),
274 GE(CLSID_DirectMusicTimeSigTrack),
275 GE(CLSID_DirectMusicWaveTrack),
276 GE(CLSID_DirectSoundWave),
277 /* IIDs */
278 GE(IID_IDirectMusic),
279 GE(IID_IDirectMusic2),
280 GE(IID_IDirectMusic8),
281 GE(IID_IDirectMusicAudioPath),
282 GE(IID_IDirectMusicBand),
283 GE(IID_IDirectMusicBuffer),
284 GE(IID_IDirectMusicChordMap),
285 GE(IID_IDirectMusicCollection),
286 GE(IID_IDirectMusicComposer),
287 GE(IID_IDirectMusicContainer),
288 GE(IID_IDirectMusicDownload),
289 GE(IID_IDirectMusicDownloadedInstrument),
290 GE(IID_IDirectMusicGetLoader),
291 GE(IID_IDirectMusicGraph),
292 GE(IID_IDirectMusicInstrument),
293 GE(IID_IDirectMusicLoader),
294 GE(IID_IDirectMusicLoader8),
295 GE(IID_IDirectMusicObject),
296 GE(IID_IDirectMusicPatternTrack),
297 GE(IID_IDirectMusicPerformance),
298 GE(IID_IDirectMusicPerformance2),
299 GE(IID_IDirectMusicPerformance8),
300 GE(IID_IDirectMusicPort),
301 GE(IID_IDirectMusicPortDownload),
302 GE(IID_IDirectMusicScript),
303 GE(IID_IDirectMusicSegment),
304 GE(IID_IDirectMusicSegment2),
305 GE(IID_IDirectMusicSegment8),
306 GE(IID_IDirectMusicSegmentState),
307 GE(IID_IDirectMusicSegmentState8),
308 GE(IID_IDirectMusicStyle),
309 GE(IID_IDirectMusicStyle8),
310 GE(IID_IDirectMusicSynth),
311 GE(IID_IDirectMusicSynth8),
312 GE(IID_IDirectMusicSynthSink),
313 GE(IID_IDirectMusicThru),
314 GE(IID_IDirectMusicTool),
315 GE(IID_IDirectMusicTool8),
316 GE(IID_IDirectMusicTrack),
317 GE(IID_IDirectMusicTrack8),
318 GE(IID_IUnknown),
319 GE(IID_IPersistStream),
320 GE(IID_IStream),
321 GE(IID_IClassFactory),
322 /* GUIDs */
323 GE(GUID_DirectMusicAllTypes),
324 GE(GUID_NOTIFICATION_CHORD),
325 GE(GUID_NOTIFICATION_COMMAND),
326 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
327 GE(GUID_NOTIFICATION_PERFORMANCE),
328 GE(GUID_NOTIFICATION_RECOMPOSE),
329 GE(GUID_NOTIFICATION_SEGMENT),
330 GE(GUID_BandParam),
331 GE(GUID_ChordParam),
332 GE(GUID_CommandParam),
333 GE(GUID_CommandParam2),
334 GE(GUID_CommandParamNext),
335 GE(GUID_IDirectMusicBand),
336 GE(GUID_IDirectMusicChordMap),
337 GE(GUID_IDirectMusicStyle),
338 GE(GUID_MuteParam),
339 GE(GUID_Play_Marker),
340 GE(GUID_RhythmParam),
341 GE(GUID_TempoParam),
342 GE(GUID_TimeSignature),
343 GE(GUID_Valid_Start_Time),
344 GE(GUID_Clear_All_Bands),
345 GE(GUID_ConnectToDLSCollection),
346 GE(GUID_Disable_Auto_Download),
347 GE(GUID_DisableTempo),
348 GE(GUID_DisableTimeSig),
349 GE(GUID_Download),
350 GE(GUID_DownloadToAudioPath),
351 GE(GUID_Enable_Auto_Download),
352 GE(GUID_EnableTempo),
353 GE(GUID_EnableTimeSig),
354 GE(GUID_IgnoreBankSelectForGM),
355 GE(GUID_SeedVariations),
356 GE(GUID_StandardMIDIFile),
357 GE(GUID_Unload),
358 GE(GUID_UnloadFromAudioPath),
359 GE(GUID_Variations),
360 GE(GUID_PerfMasterTempo),
361 GE(GUID_PerfMasterVolume),
362 GE(GUID_PerfMasterGrooveLevel),
363 GE(GUID_PerfAutoDownload),
364 GE(GUID_DefaultGMCollection),
365 GE(GUID_Synth_Default),
366 GE(GUID_Buffer_Reverb),
367 GE(GUID_Buffer_EnvReverb),
368 GE(GUID_Buffer_Stereo),
369 GE(GUID_Buffer_3D_Dry),
370 GE(GUID_Buffer_Mono),
371 GE(GUID_DMUS_PROP_GM_Hardware),
372 GE(GUID_DMUS_PROP_GS_Capable),
373 GE(GUID_DMUS_PROP_GS_Hardware),
374 GE(GUID_DMUS_PROP_DLS1),
375 GE(GUID_DMUS_PROP_DLS2),
376 GE(GUID_DMUS_PROP_Effects),
377 GE(GUID_DMUS_PROP_INSTRUMENT2),
378 GE(GUID_DMUS_PROP_LegacyCaps),
379 GE(GUID_DMUS_PROP_MemorySize),
380 GE(GUID_DMUS_PROP_SampleMemorySize),
381 GE(GUID_DMUS_PROP_SamplePlaybackRate),
382 GE(GUID_DMUS_PROP_SetSynthSink),
383 GE(GUID_DMUS_PROP_SinkUsesDSound),
384 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
385 GE(GUID_DMUS_PROP_SynthSink_WAVE),
386 GE(GUID_DMUS_PROP_Volume),
387 GE(GUID_DMUS_PROP_WavesReverb),
388 GE(GUID_DMUS_PROP_WriteLatency),
389 GE(GUID_DMUS_PROP_WritePeriod),
390 GE(GUID_DMUS_PROP_XG_Capable),
391 GE(GUID_DMUS_PROP_XG_Hardware)
394 unsigned int i;
396 if (!id) return "(null)";
398 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
399 if (IsEqualGUID(id, guids[i].guid))
400 return guids[i].name;
402 /* if we didn't find it, act like standard debugstr_guid */
403 return debugstr_guid(id);
406 /* generic flag-dumping function */
407 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
408 char buffer[128] = "", *ptr = &buffer[0];
409 unsigned int i;
410 int size = sizeof(buffer);
412 for (i=0; i < num_names; i++)
414 if ((flags & names[i].val) || /* standard flag*/
415 ((!flags) && (!names[i].val))) { /* zero value only */
416 int cnt = snprintf(ptr, size, "%s ", names[i].name);
417 if (cnt < 0 || cnt >= size) break;
418 size -= cnt;
419 ptr += cnt;
423 return wine_dbg_sprintf("%s", buffer);
426 /* dump DMUS_OBJ flags */
427 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
428 static const flag_info flags[] = {
429 FE(DMUS_OBJ_OBJECT),
430 FE(DMUS_OBJ_CLASS),
431 FE(DMUS_OBJ_NAME),
432 FE(DMUS_OBJ_CATEGORY),
433 FE(DMUS_OBJ_FILENAME),
434 FE(DMUS_OBJ_FULLPATH),
435 FE(DMUS_OBJ_URL),
436 FE(DMUS_OBJ_VERSION),
437 FE(DMUS_OBJ_DATE),
438 FE(DMUS_OBJ_LOADED),
439 FE(DMUS_OBJ_MEMORY),
440 FE(DMUS_OBJ_STREAM)
442 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
445 /* dump whole DMUS_OBJECTDESC struct */
446 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
447 if (pDesc) {
448 char buffer[1024] = "", *ptr = &buffer[0];
450 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
451 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
452 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
453 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
454 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
455 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
456 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
457 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
458 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
459 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
460 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
461 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
462 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
464 return wine_dbg_sprintf("%s", buffer);
465 } else {
466 return wine_dbg_sprintf("(NULL)");