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.c
Go to the documentation of this file.
00001 /* IDirectMusic8 Implementation
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 #include "dmusic_private.h"
00020 
00021 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
00022 
00023 /* IDirectMusic8Impl IUnknown part: */
00024 static HRESULT WINAPI IDirectMusic8Impl_QueryInterface (LPDIRECTMUSIC8 iface, REFIID riid, LPVOID *ppobj) {
00025     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00026     TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
00027 
00028     if (IsEqualIID (riid, &IID_IUnknown) || 
00029         IsEqualIID (riid, &IID_IDirectMusic) ||
00030         IsEqualIID (riid, &IID_IDirectMusic2) ||
00031         IsEqualIID (riid, &IID_IDirectMusic8)) {
00032         IUnknown_AddRef(iface);
00033         *ppobj = This;
00034         return S_OK;
00035     }
00036 
00037     WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
00038     return E_NOINTERFACE;
00039 }
00040 
00041 static ULONG WINAPI IDirectMusic8Impl_AddRef (LPDIRECTMUSIC8 iface) {
00042     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00043     ULONG refCount = InterlockedIncrement(&This->ref);
00044 
00045     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
00046 
00047     DMUSIC_LockModule();
00048 
00049     return refCount;
00050 }
00051 
00052 static ULONG WINAPI IDirectMusic8Impl_Release (LPDIRECTMUSIC8 iface) {
00053     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00054     ULONG refCount = InterlockedDecrement(&This->ref);
00055 
00056     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
00057 
00058     if (!refCount) {
00059         HeapFree(GetProcessHeap(), 0, This);
00060     }
00061 
00062     DMUSIC_UnlockModule();
00063     
00064     return refCount;
00065 }
00066 
00067 /* IDirectMusic8Impl IDirectMusic part: */
00068 static HRESULT WINAPI IDirectMusic8Impl_EnumPort(LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_PORTCAPS pPortCaps) {
00069     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00070     TRACE("(%p, %d, %p)\n", This, dwIndex, pPortCaps);
00071     if (NULL == pPortCaps) { return E_POINTER; }
00072     /* i guess the first port shown is always software synthesizer */
00073     if (dwIndex == 0) 
00074     {
00075         IDirectMusicSynth8* synth;
00076         TRACE("enumerating 'Microsoft Software Synthesizer' port\n");
00077         CoCreateInstance (&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
00078         IDirectMusicSynth8_GetPortCaps (synth, pPortCaps);
00079         IDirectMusicSynth8_Release (synth);
00080         return S_OK;
00081     }
00082 
00083 /* it seems that the rest of devices are obtained thru dmusic32.EnumLegacyDevices...*sigh*...which is undocumented*/
00084 #if 0
00085     int numMIDI = midiOutGetNumDevs();
00086     int numWAVE = waveOutGetNumDevs();
00087     int i;
00088     /* then return digital sound ports */
00089     for (i = 1; i <= numWAVE; i++)
00090     {
00091         TRACE("enumerating 'digital sound' ports\n");   
00092         if (i == dwIndex)
00093         {
00094             DirectSoundEnumerateA(register_waveport, pPortCaps);
00095             return S_OK;    
00096         }
00097     }
00098     /* finally, list all *real* MIDI ports*/
00099     for (i = numWAVE + 1; i <= numWAVE + numMIDI; i++) 
00100     {
00101         TRACE("enumerating 'real MIDI' ports\n");       
00102         if (i == dwIndex)
00103             FIXME("Found MIDI port, but *real* MIDI ports not supported yet\n");
00104     }
00105 #endif  
00106     return S_FALSE;
00107 }
00108 
00109 static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer (LPDIRECTMUSIC8 iface, LPDMUS_BUFFERDESC pBufferDesc, LPDIRECTMUSICBUFFER** ppBuffer, LPUNKNOWN pUnkOuter) {
00110     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00111 
00112     TRACE("(%p, %p, %p, %p)\n", This, pBufferDesc, ppBuffer, pUnkOuter);
00113 
00114     if (pUnkOuter)
00115         return CLASS_E_NOAGGREGATION;
00116 
00117     if (!pBufferDesc || !ppBuffer)
00118         return E_POINTER;
00119 
00120     return DMUSIC_CreateDirectMusicBufferImpl(&IID_IDirectMusicBuffer, (LPVOID)ppBuffer, NULL);
00121 }
00122 
00123 static HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter) {
00124     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00125     int i/*, j*/;
00126     DMUS_PORTCAPS PortCaps;
00127     IDirectMusicPort* pNewPort = NULL;
00128     HRESULT hr = E_FAIL;
00129 
00130     TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter); 
00131     ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS));
00132     PortCaps.dwSize = sizeof(DMUS_PORTCAPS);
00133 
00134     for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) {              
00135         if (IsEqualCLSID (rclsidPort, &PortCaps.guidPort)) {
00136             hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps);
00137             if (FAILED(hr)) {
00138                           *ppPort = NULL;
00139               return hr;
00140             }
00141             This->nrofports++;
00142             if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
00143             else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports);          
00144             This->ppPorts[This->nrofports - 1] = pNewPort;
00145             *ppPort = pNewPort;
00146             return S_OK;            
00147         }
00148     }
00149     /* FIXME: place correct error here */
00150     return E_NOINTERFACE;
00151 }
00152 
00153 static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock (LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_CLOCKINFO lpClockInfo) {
00154     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00155     FIXME("(%p, %d, %p): stub\n", This, dwIndex, lpClockInfo);
00156     return S_FALSE;
00157 }
00158 
00159 static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock (LPDIRECTMUSIC8 iface, LPGUID pguidClock, IReferenceClock** ppReferenceClock) {
00160     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00161 
00162     TRACE("(%p, %p, %p)\n", This, pguidClock, ppReferenceClock);
00163     if (pguidClock)
00164         *pguidClock = This->pMasterClock->pClockInfo.guidClock;
00165     if(ppReferenceClock)
00166         *ppReferenceClock = (IReferenceClock *)This->pMasterClock;
00167 
00168     return S_OK;
00169 }
00170 
00171 static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock (LPDIRECTMUSIC8 iface, REFGUID rguidClock) {
00172     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00173     FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidClock));
00174     return S_OK;
00175 }
00176 
00177 static HRESULT WINAPI IDirectMusic8Impl_Activate (LPDIRECTMUSIC8 iface, BOOL fEnable) {
00178     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00179     int i;
00180     
00181     FIXME("(%p, %d): stub\n", This, fEnable);
00182     for (i = 0; i < This->nrofports; i++) {
00183             IDirectMusicPortImpl_Activate(This->ppPorts[i], fEnable);
00184     }
00185     
00186     return S_OK;
00187 }
00188 
00189 static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort (LPDIRECTMUSIC8 iface, LPGUID pguidPort) {
00190     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00191     HKEY hkGUID;
00192     DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
00193     char returnBuffer[51];
00194     GUID defaultPortGUID;
00195     WCHAR buff[51];
00196 
00197     TRACE("(%p, %p)\n", This, pguidPort);
00198     if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) || 
00199         (RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
00200     {
00201         WARN(": registry entry missing\n" );
00202         *pguidPort = CLSID_DirectMusicSynth;
00203         return S_OK;
00204     }
00205     /* FIXME: Check return types to ensure we're interpreting data right */
00206     MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff) / sizeof(WCHAR));
00207     CLSIDFromString(buff, &defaultPortGUID);
00208     *pguidPort = defaultPortGUID;
00209     
00210     return S_OK;
00211 }
00212 
00213 static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound (LPDIRECTMUSIC8 iface, LPDIRECTSOUND pDirectSound, HWND hWnd) {
00214     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00215     FIXME("(%p, %p, %p): stub\n", This, pDirectSound, hWnd);
00216     return S_OK;
00217 }
00218 
00219 static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock (LPDIRECTMUSIC8 iface, IReferenceClock* pClock) {
00220     IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
00221     FIXME("(%p, %p): stub\n", This, pClock);
00222     return S_OK;
00223 }
00224 
00225 static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
00226     IDirectMusic8Impl_QueryInterface,
00227     IDirectMusic8Impl_AddRef,
00228     IDirectMusic8Impl_Release,
00229     IDirectMusic8Impl_EnumPort,
00230     IDirectMusic8Impl_CreateMusicBuffer,
00231     IDirectMusic8Impl_CreatePort,
00232     IDirectMusic8Impl_EnumMasterClock,
00233     IDirectMusic8Impl_GetMasterClock,
00234     IDirectMusic8Impl_SetMasterClock,
00235     IDirectMusic8Impl_Activate,
00236     IDirectMusic8Impl_GetDefaultPort,
00237     IDirectMusic8Impl_SetDirectSound,
00238     IDirectMusic8Impl_SetExternalMasterClock
00239 };
00240 
00241 /* for ClassFactory */
00242 HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
00243     IDirectMusic8Impl *dmusic;
00244 
00245     TRACE("(%p,%p,%p)\n",lpcGUID, ppobj, pUnkOuter);
00246 
00247     dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
00248     if (NULL == dmusic) {
00249         *ppobj = NULL;
00250         return E_OUTOFMEMORY;
00251     }
00252     dmusic->lpVtbl = &DirectMusic8_Vtbl;
00253     dmusic->ref = 0; /* will be inited with QueryInterface */
00254     dmusic->pMasterClock = NULL;
00255     dmusic->ppPorts = NULL;
00256     dmusic->nrofports = 0;
00257     DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&dmusic->pMasterClock, NULL);
00258     
00259     return IDirectMusic8Impl_QueryInterface ((LPDIRECTMUSIC8)dmusic, lpcGUID, ppobj);
00260 }

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.