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