propsys/tests: Added PropVariantToGUID tests.
[wine] / dlls / dmsynth / dmsynth_main.c
1 /* DirectMusicSynthesizer Main
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
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.
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 GNU
13  * Lesser General Public License for more details.
14  *
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
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include <stdio.h>
24
25 #include "dmsynth_private.h"
26 #include "rpcproxy.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
29
30 static HINSTANCE instance;
31 LONG DMSYNTH_refCount = 0;
32
33 typedef struct {
34         IClassFactory IClassFactory_iface;
35         HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
36 } IClassFactoryImpl;
37
38 /******************************************************************
39  *      IClassFactory implementation
40  */
41 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
42 {
43         return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
44 }
45
46 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
47 {
48         if (ppv == NULL)
49                 return E_POINTER;
50
51         if (IsEqualGUID(&IID_IUnknown, riid))
52                 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
53         else if (IsEqualGUID(&IID_IClassFactory, riid))
54                 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
55         else {
56                 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
57                 *ppv = NULL;
58                 return E_NOINTERFACE;
59         }
60
61         *ppv = iface;
62         IUnknown_AddRef((IUnknown*)*ppv);
63         return S_OK;
64 }
65
66 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
67 {
68         DMSYNTH_LockModule();
69
70         return 2; /* non-heap based object */
71 }
72
73 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
74 {
75         DMSYNTH_UnlockModule();
76
77         return 1; /* non-heap based object */
78 }
79
80 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
81         REFIID riid, void **ppv)
82 {
83         IClassFactoryImpl *This = impl_from_IClassFactory(iface);
84
85         TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
86
87         return This->fnCreateInstance(riid, ppv, pUnkOuter);
88 }
89
90 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
91 {
92         TRACE("(%d)\n", dolock);
93
94         if (dolock)
95                 DMSYNTH_LockModule();
96         else
97                 DMSYNTH_UnlockModule();
98
99         return S_OK;
100 }
101
102 static const IClassFactoryVtbl classfactory_vtbl = {
103         ClassFactory_QueryInterface,
104         ClassFactory_AddRef,
105         ClassFactory_Release,
106         ClassFactory_CreateInstance,
107         ClassFactory_LockServer
108 };
109
110 static IClassFactoryImpl Synth_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSynthImpl};
111 static IClassFactoryImpl SynthSink_CF = {{&classfactory_vtbl},
112                                          DMUSIC_CreateDirectMusicSynthSinkImpl};
113
114 /******************************************************************
115  *              DllMain
116  *
117  *
118  */
119 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
120         if (fdwReason == DLL_PROCESS_ATTACH) {
121                 instance = hinstDLL;
122                 DisableThreadLibraryCalls(hinstDLL);
123                 /* FIXME: Initialisation */
124         } else if (fdwReason == DLL_PROCESS_DETACH) {
125                 /* FIXME: Cleanup */
126         }
127
128         return TRUE;
129 }
130
131
132 /******************************************************************
133  *              DllCanUnloadNow (DMSYNTH.@)
134  *
135  *
136  */
137 HRESULT WINAPI DllCanUnloadNow(void)
138 {
139         return DMSYNTH_refCount != 0 ? S_FALSE : S_OK;
140 }
141
142
143 /******************************************************************
144  *              DllGetClassObject (DMSYNTH.@)
145  *
146  *
147  */
148 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
149 {
150     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
151     if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSynth) && IsEqualIID (riid, &IID_IClassFactory)) {
152                 *ppv = &Synth_CF;
153                 IClassFactory_AddRef((IClassFactory*)*ppv);
154                 return S_OK;            
155         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSynth) && IsEqualIID (riid, &IID_IClassFactory)) {
156                 *ppv = &SynthSink_CF;
157                 IClassFactory_AddRef((IClassFactory*)*ppv);
158                 return S_OK;            
159         } 
160
161     WARN("(%s,%s,%p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
162     return CLASS_E_CLASSNOTAVAILABLE;
163 }
164
165 /***********************************************************************
166  *              DllRegisterServer (DMSYNTH.@)
167  */
168 HRESULT WINAPI DllRegisterServer(void)
169 {
170     return __wine_register_resources( instance );
171 }
172
173 /***********************************************************************
174  *              DllUnregisterServer (DMSYNTH.@)
175  */
176 HRESULT WINAPI DllUnregisterServer(void)
177 {
178     return __wine_unregister_resources( instance );
179 }
180
181 /******************************************************************
182  *              Helper functions
183  *
184  *
185  */
186
187 /* returns name of given GUID */
188 const char *debugstr_dmguid (const GUID *id) {
189         static const guid_info guids[] = {
190                 /* CLSIDs */
191                 GE(CLSID_AudioVBScript),
192                 GE(CLSID_DirectMusic),
193                 GE(CLSID_DirectMusicAudioPath),
194                 GE(CLSID_DirectMusicAudioPathConfig),
195                 GE(CLSID_DirectMusicAuditionTrack),
196                 GE(CLSID_DirectMusicBand),
197                 GE(CLSID_DirectMusicBandTrack),
198                 GE(CLSID_DirectMusicChordMapTrack),
199                 GE(CLSID_DirectMusicChordMap),
200                 GE(CLSID_DirectMusicChordTrack),
201                 GE(CLSID_DirectMusicCollection),
202                 GE(CLSID_DirectMusicCommandTrack),
203                 GE(CLSID_DirectMusicComposer),
204                 GE(CLSID_DirectMusicContainer),
205                 GE(CLSID_DirectMusicGraph),
206                 GE(CLSID_DirectMusicLoader),
207                 GE(CLSID_DirectMusicLyricsTrack),
208                 GE(CLSID_DirectMusicMarkerTrack),
209                 GE(CLSID_DirectMusicMelodyFormulationTrack),
210                 GE(CLSID_DirectMusicMotifTrack),
211                 GE(CLSID_DirectMusicMuteTrack),
212                 GE(CLSID_DirectMusicParamControlTrack),
213                 GE(CLSID_DirectMusicPatternTrack),
214                 GE(CLSID_DirectMusicPerformance),
215                 GE(CLSID_DirectMusicScript),
216                 GE(CLSID_DirectMusicScriptAutoImpSegment),
217                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
218                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
219                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
220                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
221                 GE(CLSID_DirectMusicScriptAutoImpSong),
222                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
223                 GE(CLSID_DirectMusicScriptTrack),
224                 GE(CLSID_DirectMusicSection),
225                 GE(CLSID_DirectMusicSegment),
226                 GE(CLSID_DirectMusicSegmentState),
227                 GE(CLSID_DirectMusicSegmentTriggerTrack),
228                 GE(CLSID_DirectMusicSegTriggerTrack),
229                 GE(CLSID_DirectMusicSeqTrack),
230                 GE(CLSID_DirectMusicSignPostTrack),
231                 GE(CLSID_DirectMusicSong),
232                 GE(CLSID_DirectMusicStyle),
233                 GE(CLSID_DirectMusicStyleTrack),
234                 GE(CLSID_DirectMusicSynth),
235                 GE(CLSID_DirectMusicSynthSink),
236                 GE(CLSID_DirectMusicSysExTrack),
237                 GE(CLSID_DirectMusicTemplate),
238                 GE(CLSID_DirectMusicTempoTrack),
239                 GE(CLSID_DirectMusicTimeSigTrack),
240                 GE(CLSID_DirectMusicWaveTrack),
241                 GE(CLSID_DirectSoundWave),
242                 /* IIDs */
243                 GE(IID_IDirectMusic),
244                 GE(IID_IDirectMusic2),
245                 GE(IID_IDirectMusic8),
246                 GE(IID_IDirectMusicAudioPath),
247                 GE(IID_IDirectMusicBand),
248                 GE(IID_IDirectMusicBuffer),
249                 GE(IID_IDirectMusicChordMap),
250                 GE(IID_IDirectMusicCollection),
251                 GE(IID_IDirectMusicComposer),
252                 GE(IID_IDirectMusicContainer),
253                 GE(IID_IDirectMusicDownload),
254                 GE(IID_IDirectMusicDownloadedInstrument),
255                 GE(IID_IDirectMusicGetLoader),
256                 GE(IID_IDirectMusicGraph),
257                 GE(IID_IDirectMusicInstrument),
258                 GE(IID_IDirectMusicLoader),
259                 GE(IID_IDirectMusicLoader8),
260                 GE(IID_IDirectMusicObject),
261                 GE(IID_IDirectMusicPatternTrack),
262                 GE(IID_IDirectMusicPerformance),
263                 GE(IID_IDirectMusicPerformance2),
264                 GE(IID_IDirectMusicPerformance8),
265                 GE(IID_IDirectMusicPort),
266                 GE(IID_IDirectMusicPortDownload),
267                 GE(IID_IDirectMusicScript),
268                 GE(IID_IDirectMusicSegment),
269                 GE(IID_IDirectMusicSegment2),
270                 GE(IID_IDirectMusicSegment8),
271                 GE(IID_IDirectMusicSegmentState),
272                 GE(IID_IDirectMusicSegmentState8),
273                 GE(IID_IDirectMusicStyle),
274                 GE(IID_IDirectMusicStyle8),
275                 GE(IID_IDirectMusicSynth),
276                 GE(IID_IDirectMusicSynth8),
277                 GE(IID_IDirectMusicSynthSink),
278                 GE(IID_IDirectMusicThru),
279                 GE(IID_IDirectMusicTool),
280                 GE(IID_IDirectMusicTool8),
281                 GE(IID_IDirectMusicTrack),
282                 GE(IID_IDirectMusicTrack8),
283                 GE(IID_IUnknown),
284                 GE(IID_IPersistStream),
285                 GE(IID_IStream),
286                 GE(IID_IClassFactory),
287                 /* GUIDs */
288                 GE(GUID_DirectMusicAllTypes),
289                 GE(GUID_NOTIFICATION_CHORD),
290                 GE(GUID_NOTIFICATION_COMMAND),
291                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
292                 GE(GUID_NOTIFICATION_PERFORMANCE),
293                 GE(GUID_NOTIFICATION_RECOMPOSE),
294                 GE(GUID_NOTIFICATION_SEGMENT),
295                 GE(GUID_BandParam),
296                 GE(GUID_ChordParam),
297                 GE(GUID_CommandParam),
298                 GE(GUID_CommandParam2),
299                 GE(GUID_CommandParamNext),
300                 GE(GUID_IDirectMusicBand),
301                 GE(GUID_IDirectMusicChordMap),
302                 GE(GUID_IDirectMusicStyle),
303                 GE(GUID_MuteParam),
304                 GE(GUID_Play_Marker),
305                 GE(GUID_RhythmParam),
306                 GE(GUID_TempoParam),
307                 GE(GUID_TimeSignature),
308                 GE(GUID_Valid_Start_Time),
309                 GE(GUID_Clear_All_Bands),
310                 GE(GUID_ConnectToDLSCollection),
311                 GE(GUID_Disable_Auto_Download),
312                 GE(GUID_DisableTempo),
313                 GE(GUID_DisableTimeSig),
314                 GE(GUID_Download),
315                 GE(GUID_DownloadToAudioPath),
316                 GE(GUID_Enable_Auto_Download),
317                 GE(GUID_EnableTempo),
318                 GE(GUID_EnableTimeSig),
319                 GE(GUID_IgnoreBankSelectForGM),
320                 GE(GUID_SeedVariations),
321                 GE(GUID_StandardMIDIFile),
322                 GE(GUID_Unload),
323                 GE(GUID_UnloadFromAudioPath),
324                 GE(GUID_Variations),
325                 GE(GUID_PerfMasterTempo),
326                 GE(GUID_PerfMasterVolume),
327                 GE(GUID_PerfMasterGrooveLevel),
328                 GE(GUID_PerfAutoDownload),
329                 GE(GUID_DefaultGMCollection),
330                 GE(GUID_Synth_Default),
331                 GE(GUID_Buffer_Reverb),
332                 GE(GUID_Buffer_EnvReverb),
333                 GE(GUID_Buffer_Stereo),
334                 GE(GUID_Buffer_3D_Dry),
335                 GE(GUID_Buffer_Mono),
336                 GE(GUID_DMUS_PROP_GM_Hardware),
337                 GE(GUID_DMUS_PROP_GS_Capable),
338                 GE(GUID_DMUS_PROP_GS_Hardware),
339                 GE(GUID_DMUS_PROP_DLS1),
340                 GE(GUID_DMUS_PROP_DLS2),
341                 GE(GUID_DMUS_PROP_Effects),
342                 GE(GUID_DMUS_PROP_INSTRUMENT2),
343                 GE(GUID_DMUS_PROP_LegacyCaps),
344                 GE(GUID_DMUS_PROP_MemorySize),
345                 GE(GUID_DMUS_PROP_SampleMemorySize),
346                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
347                 GE(GUID_DMUS_PROP_SetSynthSink),
348                 GE(GUID_DMUS_PROP_SinkUsesDSound),
349                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
350                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
351                 GE(GUID_DMUS_PROP_Volume),
352                 GE(GUID_DMUS_PROP_WavesReverb),
353                 GE(GUID_DMUS_PROP_WriteLatency),
354                 GE(GUID_DMUS_PROP_WritePeriod),
355                 GE(GUID_DMUS_PROP_XG_Capable),
356                 GE(GUID_DMUS_PROP_XG_Hardware)
357         };
358
359         unsigned int i;
360
361         if (!id) return "(null)";
362
363         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
364                 if (IsEqualGUID(id, guids[i].guid))
365                         return guids[i].name;
366         }
367         /* if we didn't find it, act like standard debugstr_guid */     
368         return debugstr_guid(id);
369 }