Consolidate secondary buffer list processing and locking.
[wine] / dlls / dmusic / port.c
1 /* IDirectMusicPort Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (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
13  * GNU Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "dmusic_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
23
24 /* IDirectMusicPortImpl IUnknown part: */
25 HRESULT WINAPI IDirectMusicPortImpl_QueryInterface (LPDIRECTMUSICPORT iface, REFIID riid, LPVOID *ppobj) {
26         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
27         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
28
29         if (IsEqualIID (riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirectMusicPort)) {
30                 IDirectMusicPortImpl_AddRef(iface);
31                 *ppobj = This;
32                 return S_OK;
33         }
34         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
35         return E_NOINTERFACE;
36 }
37
38 ULONG WINAPI IDirectMusicPortImpl_AddRef (LPDIRECTMUSICPORT iface) {
39         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
40         TRACE("(%p): AddRef from %ld\n", This, This->ref);
41         return ++(This->ref);
42 }
43
44 ULONG WINAPI IDirectMusicPortImpl_Release (LPDIRECTMUSICPORT iface) {
45         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
46         ULONG ref = --This->ref;
47         TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
48         if (ref == 0) {
49                 HeapFree(GetProcessHeap(), 0, This);
50         }
51         return ref;
52 }
53
54 /* IDirectMusicPortImpl IDirectMusicPort part: */
55 HRESULT WINAPI IDirectMusicPortImpl_PlayBuffer (LPDIRECTMUSICPORT iface, LPDIRECTMUSICBUFFER pBuffer) {
56         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
57         FIXME("(%p, %p): stub\n", This, pBuffer);
58         return S_OK;
59 }
60
61 HRESULT WINAPI IDirectMusicPortImpl_SetReadNotificationHandle (LPDIRECTMUSICPORT iface, HANDLE hEvent) {
62         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
63         FIXME("(%p, %p): stub\n", This, hEvent);
64         return S_OK;
65 }
66
67 HRESULT WINAPI IDirectMusicPortImpl_Read (LPDIRECTMUSICPORT iface, LPDIRECTMUSICBUFFER pBuffer) {
68         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
69         FIXME("(%p, %p): stub\n", This, pBuffer);
70         return S_OK;
71 }
72
73 HRESULT WINAPI IDirectMusicPortImpl_DownloadInstrument (LPDIRECTMUSICPORT iface, IDirectMusicInstrument* pInstrument, IDirectMusicDownloadedInstrument** ppDownloadedInstrument, DMUS_NOTERANGE* pNoteRanges, DWORD dwNumNoteRanges) {
74         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
75         FIXME("(%p, %p, %p, %p, %ld): stub\n", This, pInstrument, ppDownloadedInstrument, pNoteRanges, dwNumNoteRanges);
76         return S_OK;
77 }
78
79 HRESULT WINAPI IDirectMusicPortImpl_UnloadInstrument (LPDIRECTMUSICPORT iface, IDirectMusicDownloadedInstrument *pDownloadedInstrument) {
80         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
81         FIXME("(%p, %p): stub\n", This, pDownloadedInstrument);
82         return S_OK;
83 }
84
85 HRESULT WINAPI IDirectMusicPortImpl_GetLatencyClock (LPDIRECTMUSICPORT iface, IReferenceClock** ppClock) {
86         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
87         TRACE("(%p, %p)\n", This, ppClock);
88         *ppClock = This->pLatencyClock;
89         IReferenceClock_AddRef (*ppClock);
90         return S_OK;
91 }
92
93 HRESULT WINAPI IDirectMusicPortImpl_GetRunningStats (LPDIRECTMUSICPORT iface, LPDMUS_SYNTHSTATS pStats) {
94         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
95         FIXME("(%p, %p): stub\n", This, pStats);
96         return S_OK;
97 }
98
99 HRESULT WINAPI IDirectMusicPortImpl_Compact (LPDIRECTMUSICPORT iface) {
100         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
101         FIXME("(%p): stub\n", This);
102         return S_OK;
103 }
104
105 HRESULT WINAPI IDirectMusicPortImpl_GetCaps (LPDIRECTMUSICPORT iface, LPDMUS_PORTCAPS pPortCaps) {
106         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
107         TRACE("(%p, %p)\n", This, pPortCaps);
108         pPortCaps = This->pCaps;        
109         return S_OK;
110 }
111
112 HRESULT WINAPI IDirectMusicPortImpl_DeviceIoControl (LPDIRECTMUSICPORT iface, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) {
113         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
114         FIXME("(%p, %ld, %p, %ld, %p, %ld, %p, %p): stub\n", This, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
115         return S_OK;
116 }
117
118 HRESULT WINAPI IDirectMusicPortImpl_SetNumChannelGroups (LPDIRECTMUSICPORT iface, DWORD dwChannelGroups) {
119         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
120         FIXME("(%p, %ld): semi-stub\n", This, dwChannelGroups);
121         This->nrofgroups = dwChannelGroups;
122         return S_OK;
123 }
124
125 HRESULT WINAPI IDirectMusicPortImpl_GetNumChannelGroups (LPDIRECTMUSICPORT iface, LPDWORD pdwChannelGroups) {
126         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
127         TRACE("(%p, %p)\n", This, pdwChannelGroups);
128         *pdwChannelGroups = This->nrofgroups;
129         return S_OK;
130 }
131
132 HRESULT WINAPI IDirectMusicPortImpl_Activate (LPDIRECTMUSICPORT iface, BOOL fActive) {
133         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
134         TRACE("(%p, %d)\n", This, fActive);
135         This->fActive = fActive;
136         return S_OK;
137 }
138
139 HRESULT WINAPI IDirectMusicPortImpl_SetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority) {
140         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
141         FIXME("(%p, %ld, %ld, %ld): semi-stub\n", This, dwChannelGroup, dwChannel, dwPriority);
142         if (dwChannel > 16) {
143                 WARN("isn't there supposed to be 16 channels (no. %ld requested)?! (faking as it is ok)\n", dwChannel);
144                 /*return E_INVALIDARG;*/
145         }       
146         return S_OK;
147 }
148
149 HRESULT WINAPI IDirectMusicPortImpl_GetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority) {
150         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
151         TRACE("(%p, %ld, %ld, %p)\n", This, dwChannelGroup, dwChannel, pdwPriority);
152         *pdwPriority = This->group[dwChannelGroup-1].channel[dwChannel].priority;
153         return S_OK;
154 }
155
156 HRESULT WINAPI IDirectMusicPortImpl_SetDirectSound (LPDIRECTMUSICPORT iface, LPDIRECTSOUND pDirectSound, LPDIRECTSOUNDBUFFER pDirectSoundBuffer) {
157         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
158         FIXME("(%p, %p, %p): stub\n", This, pDirectSound, pDirectSoundBuffer);
159         return S_OK;
160 }
161
162 HRESULT WINAPI IDirectMusicPortImpl_GetFormat (LPDIRECTMUSICPORT iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSize, LPDWORD pdwBufferSize) {
163         IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
164         FIXME("(%p, %p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSize, pdwBufferSize);
165         return S_OK;
166 }
167
168 IDirectMusicPortVtbl DirectMusicPort_Vtbl = {
169         IDirectMusicPortImpl_QueryInterface,
170         IDirectMusicPortImpl_AddRef,
171         IDirectMusicPortImpl_Release,
172         IDirectMusicPortImpl_PlayBuffer,
173         IDirectMusicPortImpl_SetReadNotificationHandle,
174         IDirectMusicPortImpl_Read,
175         IDirectMusicPortImpl_DownloadInstrument,
176         IDirectMusicPortImpl_UnloadInstrument,
177         IDirectMusicPortImpl_GetLatencyClock,
178         IDirectMusicPortImpl_GetRunningStats,
179         IDirectMusicPortImpl_Compact,
180         IDirectMusicPortImpl_GetCaps,
181         IDirectMusicPortImpl_DeviceIoControl,
182         IDirectMusicPortImpl_SetNumChannelGroups,
183         IDirectMusicPortImpl_GetNumChannelGroups,
184         IDirectMusicPortImpl_Activate,
185         IDirectMusicPortImpl_SetChannelPriority,
186         IDirectMusicPortImpl_GetChannelPriority,
187         IDirectMusicPortImpl_SetDirectSound,
188         IDirectMusicPortImpl_GetFormat
189 };