ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dmusic_main.c
Go to the documentation of this file.
00001 /* DirectMusic Main
00002  *
00003  * Copyright (C) 2003-2004 Rok Mandeljc
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #include "config.h"
00021 #include "wine/port.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include "dmusic_private.h"
00026 
00027 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
00028 
00029 LONG DMUSIC_refCount = 0;
00030 
00031 typedef struct {
00032     const IClassFactoryVtbl *lpVtbl;
00033 } IClassFactoryImpl;
00034 
00035 /******************************************************************
00036  *      DirectMusic ClassFactory
00037  */
00038 static HRESULT WINAPI DirectMusicCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
00039     FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
00040 
00041     if (ppobj == NULL) return E_POINTER;
00042     
00043     return E_NOINTERFACE;
00044 }
00045 
00046 static ULONG WINAPI DirectMusicCF_AddRef(LPCLASSFACTORY iface) {
00047     DMUSIC_LockModule();
00048 
00049     return 2; /* non-heap based object */
00050 }
00051 
00052 static ULONG WINAPI DirectMusicCF_Release(LPCLASSFACTORY iface) {
00053     DMUSIC_UnlockModule();
00054 
00055     return 1; /* non-heap based object */
00056 }
00057 
00058 static HRESULT WINAPI DirectMusicCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
00059     TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
00060     return DMUSIC_CreateDirectMusicImpl (riid, ppobj, pOuter);
00061 }
00062 
00063 static HRESULT WINAPI DirectMusicCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
00064     TRACE("(%d)\n", dolock);
00065 
00066     if (dolock)
00067         DMUSIC_LockModule();
00068     else
00069         DMUSIC_UnlockModule();
00070     
00071     return S_OK;
00072 }
00073 
00074 static const IClassFactoryVtbl DirectMusicCF_Vtbl = {
00075     DirectMusicCF_QueryInterface,
00076     DirectMusicCF_AddRef,
00077     DirectMusicCF_Release,
00078     DirectMusicCF_CreateInstance,
00079     DirectMusicCF_LockServer
00080 };
00081 
00082 static IClassFactoryImpl DirectMusic_CF = {&DirectMusicCF_Vtbl};
00083 
00084 /******************************************************************
00085  *      DirectMusicCollection ClassFactory
00086  */
00087 static HRESULT WINAPI CollectionCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
00088     FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
00089 
00090     if (ppobj == NULL) return E_POINTER;
00091     
00092     return E_NOINTERFACE;
00093 }
00094 
00095 static ULONG WINAPI CollectionCF_AddRef(LPCLASSFACTORY iface) {
00096     DMUSIC_LockModule();
00097 
00098     return 2; /* non-heap based object */
00099 }
00100 
00101 static ULONG WINAPI CollectionCF_Release(LPCLASSFACTORY iface) {
00102     DMUSIC_UnlockModule();
00103 
00104     return 1; /* non-heap based object */
00105 }
00106 
00107 static HRESULT WINAPI CollectionCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
00108     TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
00109     return DMUSIC_CreateDirectMusicCollectionImpl (riid, ppobj, pOuter);
00110 }
00111 
00112 static HRESULT WINAPI CollectionCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
00113     TRACE("(%d)\n", dolock);
00114 
00115     if (dolock)
00116         DMUSIC_LockModule();
00117     else
00118         DMUSIC_UnlockModule();
00119     
00120     return S_OK;
00121 }
00122 
00123 static const IClassFactoryVtbl CollectionCF_Vtbl = {
00124     CollectionCF_QueryInterface,
00125     CollectionCF_AddRef,
00126     CollectionCF_Release,
00127     CollectionCF_CreateInstance,
00128     CollectionCF_LockServer
00129 };
00130 
00131 static IClassFactoryImpl Collection_CF = {&CollectionCF_Vtbl};
00132 
00133 /******************************************************************
00134  *      DllMain
00135  *
00136  *
00137  */
00138 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
00139     if (fdwReason == DLL_PROCESS_ATTACH) {
00140             DisableThreadLibraryCalls(hinstDLL);
00141         /* FIXME: Initialisation */
00142     } else if (fdwReason == DLL_PROCESS_DETACH) {
00143         /* FIXME: Cleanup */
00144     }
00145 
00146     return TRUE;
00147 }
00148 
00149 
00150 /******************************************************************
00151  *      DllCanUnloadNow (DMUSIC.@)
00152  *
00153  *
00154  */
00155 HRESULT WINAPI DllCanUnloadNow(void)
00156 {
00157     return DMUSIC_refCount != 0 ? S_FALSE : S_OK;
00158 }
00159 
00160 
00161 /******************************************************************
00162  *      DllGetClassObject (DMUSIC.@)
00163  *
00164  *
00165  */
00166 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
00167 {
00168     TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
00169     if (IsEqualCLSID (rclsid, &CLSID_DirectMusic) && IsEqualIID (riid, &IID_IClassFactory)) {
00170         *ppv = &DirectMusic_CF;
00171         IClassFactory_AddRef((IClassFactory*)*ppv);
00172         return S_OK;
00173     } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCollection) && IsEqualIID (riid, &IID_IClassFactory)) {
00174         *ppv = &Collection_CF;
00175         IClassFactory_AddRef((IClassFactory*)*ppv);
00176         return S_OK;
00177     }
00178     
00179     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
00180     return CLASS_E_CLASSNOTAVAILABLE;
00181 }
00182 
00183 
00184 /******************************************************************
00185  *      Helper functions
00186  *
00187  *
00188  */
00189 /* dwPatch from MIDILOCALE */
00190 DWORD MIDILOCALE2Patch (LPMIDILOCALE pLocale) {
00191     DWORD dwPatch = 0;
00192     if (!pLocale) return 0;
00193     dwPatch |= (pLocale->ulBank & F_INSTRUMENT_DRUMS); /* set drum bit */
00194     dwPatch |= ((pLocale->ulBank & 0x00007F7F) << 8); /* set MIDI bank location */
00195     dwPatch |= (pLocale->ulInstrument & 0x0000007F); /* set PC value */
00196     return dwPatch; 
00197 }
00198 
00199 /* MIDILOCALE from dwPatch */
00200 void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) {
00201     memset (pLocale, 0, sizeof(MIDILOCALE));
00202     
00203     pLocale->ulInstrument = (dwPatch & 0x7F); /* get PC value */
00204     pLocale->ulBank = ((dwPatch & 0x007F7F00) >> 8); /* get MIDI bank location */
00205     pLocale->ulBank |= (dwPatch & F_INSTRUMENT_DRUMS); /* get drum bit */
00206 }
00207 
00208 /* check whether the given DWORD is even (return 0) or odd (return 1) */
00209 int even_or_odd (DWORD number) {
00210     return (number & 0x1); /* basically, check if bit 0 is set ;) */
00211 }
00212 
00213 /* FOURCC to string conversion for debug messages */
00214 const char *debugstr_fourcc (DWORD fourcc) {
00215     if (!fourcc) return "'null'";
00216     return wine_dbg_sprintf ("\'%c%c%c%c\'",
00217         (char)(fourcc), (char)(fourcc >> 8),
00218         (char)(fourcc >> 16), (char)(fourcc >> 24));
00219 }
00220 
00221 /* DMUS_VERSION struct to string conversion for debug messages */
00222 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
00223     if (!version) return "'null'";
00224     return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
00225         (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF), 
00226         (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
00227 }
00228 
00229 /* returns name of given GUID */
00230 const char *debugstr_dmguid (const GUID *id) {
00231     static const guid_info guids[] = {
00232         /* CLSIDs */
00233         GE(CLSID_AudioVBScript),
00234         GE(CLSID_DirectMusic),
00235         GE(CLSID_DirectMusicAudioPath),
00236         GE(CLSID_DirectMusicAudioPathConfig),
00237         GE(CLSID_DirectMusicAuditionTrack),
00238         GE(CLSID_DirectMusicBand),
00239         GE(CLSID_DirectMusicBandTrack),
00240         GE(CLSID_DirectMusicChordMapTrack),
00241         GE(CLSID_DirectMusicChordMap),
00242         GE(CLSID_DirectMusicChordTrack),
00243         GE(CLSID_DirectMusicCollection),
00244         GE(CLSID_DirectMusicCommandTrack),
00245         GE(CLSID_DirectMusicComposer),
00246         GE(CLSID_DirectMusicContainer),
00247         GE(CLSID_DirectMusicGraph),
00248         GE(CLSID_DirectMusicLoader),
00249         GE(CLSID_DirectMusicLyricsTrack),
00250         GE(CLSID_DirectMusicMarkerTrack),
00251         GE(CLSID_DirectMusicMelodyFormulationTrack),
00252         GE(CLSID_DirectMusicMotifTrack),
00253         GE(CLSID_DirectMusicMuteTrack),
00254         GE(CLSID_DirectMusicParamControlTrack),
00255         GE(CLSID_DirectMusicPatternTrack),
00256         GE(CLSID_DirectMusicPerformance),
00257         GE(CLSID_DirectMusicScript),
00258         GE(CLSID_DirectMusicScriptAutoImpSegment),
00259         GE(CLSID_DirectMusicScriptAutoImpPerformance),
00260         GE(CLSID_DirectMusicScriptAutoImpSegmentState),
00261         GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
00262         GE(CLSID_DirectMusicScriptAutoImpAudioPath),
00263         GE(CLSID_DirectMusicScriptAutoImpSong),
00264         GE(CLSID_DirectMusicScriptSourceCodeLoader),
00265         GE(CLSID_DirectMusicScriptTrack),
00266         GE(CLSID_DirectMusicSection),
00267         GE(CLSID_DirectMusicSegment),
00268         GE(CLSID_DirectMusicSegmentState),
00269         GE(CLSID_DirectMusicSegmentTriggerTrack),
00270         GE(CLSID_DirectMusicSegTriggerTrack),
00271         GE(CLSID_DirectMusicSeqTrack),
00272         GE(CLSID_DirectMusicSignPostTrack),
00273         GE(CLSID_DirectMusicSong),
00274         GE(CLSID_DirectMusicStyle),
00275         GE(CLSID_DirectMusicStyleTrack),
00276         GE(CLSID_DirectMusicSynth),
00277         GE(CLSID_DirectMusicSynthSink),
00278         GE(CLSID_DirectMusicSysExTrack),
00279         GE(CLSID_DirectMusicTemplate),
00280         GE(CLSID_DirectMusicTempoTrack),
00281         GE(CLSID_DirectMusicTimeSigTrack),
00282         GE(CLSID_DirectMusicWaveTrack),
00283         GE(CLSID_DirectSoundWave),
00284         /* IIDs */
00285         GE(IID_IDirectMusic),
00286         GE(IID_IDirectMusic2),
00287         GE(IID_IDirectMusic8),
00288         GE(IID_IDirectMusicAudioPath),
00289         GE(IID_IDirectMusicBand),
00290         GE(IID_IDirectMusicBuffer),
00291         GE(IID_IDirectMusicChordMap),
00292         GE(IID_IDirectMusicCollection),
00293         GE(IID_IDirectMusicComposer),
00294         GE(IID_IDirectMusicContainer),
00295         GE(IID_IDirectMusicDownload),
00296         GE(IID_IDirectMusicDownloadedInstrument),
00297         GE(IID_IDirectMusicGetLoader),
00298         GE(IID_IDirectMusicGraph),
00299         GE(IID_IDirectMusicInstrument),
00300         GE(IID_IDirectMusicLoader),
00301         GE(IID_IDirectMusicLoader8),
00302         GE(IID_IDirectMusicObject),
00303         GE(IID_IDirectMusicPatternTrack),
00304         GE(IID_IDirectMusicPerformance),
00305         GE(IID_IDirectMusicPerformance2),
00306         GE(IID_IDirectMusicPerformance8),
00307         GE(IID_IDirectMusicPort),
00308         GE(IID_IDirectMusicPortDownload),
00309         GE(IID_IDirectMusicScript),
00310         GE(IID_IDirectMusicSegment),
00311         GE(IID_IDirectMusicSegment2),
00312         GE(IID_IDirectMusicSegment8),
00313         GE(IID_IDirectMusicSegmentState),
00314         GE(IID_IDirectMusicSegmentState8),
00315         GE(IID_IDirectMusicStyle),
00316         GE(IID_IDirectMusicStyle8),
00317         GE(IID_IDirectMusicSynth),
00318         GE(IID_IDirectMusicSynth8),
00319         GE(IID_IDirectMusicSynthSink),
00320         GE(IID_IDirectMusicThru),
00321         GE(IID_IDirectMusicTool),
00322         GE(IID_IDirectMusicTool8),
00323         GE(IID_IDirectMusicTrack),
00324         GE(IID_IDirectMusicTrack8),
00325         GE(IID_IUnknown),
00326         GE(IID_IPersistStream),
00327         GE(IID_IStream),
00328         GE(IID_IClassFactory),
00329         /* GUIDs */
00330         GE(GUID_DirectMusicAllTypes),
00331         GE(GUID_NOTIFICATION_CHORD),
00332         GE(GUID_NOTIFICATION_COMMAND),
00333         GE(GUID_NOTIFICATION_MEASUREANDBEAT),
00334         GE(GUID_NOTIFICATION_PERFORMANCE),
00335         GE(GUID_NOTIFICATION_RECOMPOSE),
00336         GE(GUID_NOTIFICATION_SEGMENT),
00337         GE(GUID_BandParam),
00338         GE(GUID_ChordParam),
00339         GE(GUID_CommandParam),
00340         GE(GUID_CommandParam2),
00341         GE(GUID_CommandParamNext),
00342         GE(GUID_IDirectMusicBand),
00343         GE(GUID_IDirectMusicChordMap),
00344         GE(GUID_IDirectMusicStyle),
00345         GE(GUID_MuteParam),
00346         GE(GUID_Play_Marker),
00347         GE(GUID_RhythmParam),
00348         GE(GUID_TempoParam),
00349         GE(GUID_TimeSignature),
00350         GE(GUID_Valid_Start_Time),
00351         GE(GUID_Clear_All_Bands),
00352         GE(GUID_ConnectToDLSCollection),
00353         GE(GUID_Disable_Auto_Download),
00354         GE(GUID_DisableTempo),
00355         GE(GUID_DisableTimeSig),
00356         GE(GUID_Download),
00357         GE(GUID_DownloadToAudioPath),
00358         GE(GUID_Enable_Auto_Download),
00359         GE(GUID_EnableTempo),
00360         GE(GUID_EnableTimeSig),
00361         GE(GUID_IgnoreBankSelectForGM),
00362         GE(GUID_SeedVariations),
00363         GE(GUID_StandardMIDIFile),
00364         GE(GUID_Unload),
00365         GE(GUID_UnloadFromAudioPath),
00366         GE(GUID_Variations),
00367         GE(GUID_PerfMasterTempo),
00368         GE(GUID_PerfMasterVolume),
00369         GE(GUID_PerfMasterGrooveLevel),
00370         GE(GUID_PerfAutoDownload),
00371         GE(GUID_DefaultGMCollection),
00372         GE(GUID_Synth_Default),
00373         GE(GUID_Buffer_Reverb),
00374         GE(GUID_Buffer_EnvReverb),
00375         GE(GUID_Buffer_Stereo),
00376         GE(GUID_Buffer_3D_Dry),
00377         GE(GUID_Buffer_Mono),
00378         GE(GUID_DMUS_PROP_GM_Hardware),
00379         GE(GUID_DMUS_PROP_GS_Capable),
00380         GE(GUID_DMUS_PROP_GS_Hardware),
00381         GE(GUID_DMUS_PROP_DLS1),
00382         GE(GUID_DMUS_PROP_DLS2),
00383         GE(GUID_DMUS_PROP_Effects),
00384         GE(GUID_DMUS_PROP_INSTRUMENT2),
00385         GE(GUID_DMUS_PROP_LegacyCaps),
00386         GE(GUID_DMUS_PROP_MemorySize),
00387         GE(GUID_DMUS_PROP_SampleMemorySize),
00388         GE(GUID_DMUS_PROP_SamplePlaybackRate),
00389         GE(GUID_DMUS_PROP_SetSynthSink),
00390         GE(GUID_DMUS_PROP_SinkUsesDSound),
00391         GE(GUID_DMUS_PROP_SynthSink_DSOUND),
00392         GE(GUID_DMUS_PROP_SynthSink_WAVE),
00393         GE(GUID_DMUS_PROP_Volume),
00394         GE(GUID_DMUS_PROP_WavesReverb),
00395         GE(GUID_DMUS_PROP_WriteLatency),
00396         GE(GUID_DMUS_PROP_WritePeriod),
00397         GE(GUID_DMUS_PROP_XG_Capable),
00398         GE(GUID_DMUS_PROP_XG_Hardware)
00399     };
00400 
00401     unsigned int i;
00402 
00403         if (!id) return "(null)";
00404 
00405     for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
00406         if (IsEqualGUID(id, guids[i].guid))
00407             return guids[i].name;
00408     }
00409     /* if we didn't find it, act like standard debugstr_guid */ 
00410     return debugstr_guid(id);
00411 }   
00412 
00413 /* generic flag-dumping function */
00414 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
00415     char buffer[128] = "", *ptr = &buffer[0];
00416     unsigned int i;
00417     int size = sizeof(buffer);
00418     
00419     for (i=0; i < num_names; i++)
00420     {
00421         if ((flags & names[i].val) ||   /* standard flag*/
00422             ((!flags) && (!names[i].val))) { /* zero value only */
00423                 int cnt = snprintf(ptr, size, "%s ", names[i].name);
00424                 if (cnt < 0 || cnt >= size) break;
00425                 size -= cnt;
00426                 ptr += cnt;
00427         }
00428     }
00429     
00430     return wine_dbg_sprintf("%s", buffer);
00431 }
00432 
00433 /* dump DMUS_OBJ flags */
00434 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
00435     static const flag_info flags[] = {
00436         FE(DMUS_OBJ_OBJECT),
00437         FE(DMUS_OBJ_CLASS),
00438         FE(DMUS_OBJ_NAME),
00439         FE(DMUS_OBJ_CATEGORY),
00440         FE(DMUS_OBJ_FILENAME),
00441         FE(DMUS_OBJ_FULLPATH),
00442         FE(DMUS_OBJ_URL),
00443         FE(DMUS_OBJ_VERSION),
00444         FE(DMUS_OBJ_DATE),
00445         FE(DMUS_OBJ_LOADED),
00446         FE(DMUS_OBJ_MEMORY),
00447         FE(DMUS_OBJ_STREAM)
00448     };
00449     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
00450 }
00451 
00452 /* dump whole DMUS_OBJECTDESC struct */
00453 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
00454     if (pDesc) {
00455         char buffer[1024] = "", *ptr = &buffer[0];
00456         
00457         ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
00458         ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
00459         ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
00460         if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
00461         if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
00462         if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
00463         if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
00464         if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
00465         if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
00466         if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
00467         if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n  - pbMemData = %p\n",
00468                                                              wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
00469         if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
00470 
00471         return wine_dbg_sprintf("%s", buffer);
00472     } else {
00473         return wine_dbg_sprintf("(NULL)");
00474     }
00475 }

Generated on Sat May 26 2012 04:20:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.