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