efb70c6e4e8ceba58fcf68f2733c16895f97d2a9
[reactos.git] / reactos / dll / directx / wine / dmusic / dmusic_private.h
1 /*
2 * DirectMusic Private Include
3 *
4 * Copyright (C) 2003-2004 Rok Mandeljc
5 * Copyright (C) 2012 Christian Costa
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #ifndef __WINE_DMUSIC_PRIVATE_H
23 #define __WINE_DMUSIC_PRIVATE_H
24
25 //#include <stdarg.h>
26
27 #define COBJMACROS
28 #define WIN32_NO_STATUS
29 #define _INC_WINDOWS
30 #define COM_NO_WINDOWS_H
31
32 //#include "windef.h"
33 //#include "winbase.h"
34 //#include "winnt.h"
35 //#include "wingdi.h"
36 //#include "winuser.h"
37
38 #include <wine/debug.h>
39 #include <wine/list.h>
40 #include <wine/unicode.h>
41 #include <winreg.h>
42 #include <objbase.h>
43
44 #include <dmusici.h>
45 #include <dmusicf.h>
46 #include <dmusics.h>
47
48 /*****************************************************************************
49 * Interfaces
50 */
51 typedef struct IDirectMusic8Impl IDirectMusic8Impl;
52 typedef struct IDirectMusicBufferImpl IDirectMusicBufferImpl;
53 typedef struct IDirectMusicDownloadedInstrumentImpl IDirectMusicDownloadedInstrumentImpl;
54 typedef struct IDirectMusicDownloadImpl IDirectMusicDownloadImpl;
55 typedef struct IReferenceClockImpl IReferenceClockImpl;
56
57 typedef struct IDirectMusicCollectionImpl IDirectMusicCollectionImpl;
58 typedef struct IDirectMusicInstrumentImpl IDirectMusicInstrumentImpl;
59
60 typedef struct SynthPortImpl SynthPortImpl;
61
62 /*****************************************************************************
63 * Some stuff to make my life easier :=)
64 */
65
66 /* some sort of aux. midi channel: big fake at the moment; accepts only priority
67 changes... more coming soon */
68 typedef struct DMUSIC_PRIVATE_MCHANNEL_ {
69 DWORD priority;
70 } DMUSIC_PRIVATE_MCHANNEL, *LPDMUSIC_PRIVATE_MCHANNEL;
71
72 /* some sort of aux. channel group: collection of 16 midi channels */
73 typedef struct DMUSIC_PRIVATE_CHANNEL_GROUP_ {
74 DMUSIC_PRIVATE_MCHANNEL channel[16]; /* 16 channels in a group */
75 } DMUSIC_PRIVATE_CHANNEL_GROUP, *LPDMUSIC_PRIVATE_CHANNEL_GROUP;
76
77 typedef struct port_info {
78 DMUS_PORTCAPS caps;
79 HRESULT (*create)(LPCGUID guid, LPVOID *object, LPUNKNOWN unkouter, LPDMUS_PORTPARAMS port_params, LPDMUS_PORTCAPS port_caps, DWORD device);
80 ULONG device;
81 } port_info;
82
83 typedef struct instrument_region {
84 RGNHEADER header;
85 WAVELINK wave_link;
86 WSMPL wave_sample;
87 WLOOP wave_loop;
88 BOOL loop_present;
89 } instrument_region;
90
91 typedef struct instrument_articulation {
92 CONNECTIONLIST connections_list;
93 CONNECTION *connections;
94 } instrument_articulation;
95
96 /*****************************************************************************
97 * ClassFactory
98 */
99
100 /* CLSID */
101 extern HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
102 extern HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl(LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
103
104 /* Internal */
105 extern HRESULT DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface) DECLSPEC_HIDDEN;
106 extern HRESULT DMUSIC_CreateDirectMusicDownloadImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
107 extern HRESULT DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
108 extern HRESULT DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
109
110 /*****************************************************************************
111 * IDirectMusic8Impl implementation structure
112 */
113 struct IDirectMusic8Impl {
114 /* IUnknown fields */
115 IDirectMusic8 IDirectMusic8_iface;
116 LONG ref;
117
118 /* IDirectMusicImpl fields */
119 IReferenceClockImpl* pMasterClock;
120 IDirectMusicPort** ppPorts;
121 int nrofports;
122 port_info* system_ports;
123 int nb_system_ports;
124 };
125
126 /*****************************************************************************
127 * IDirectMusicBufferImpl implementation structure
128 */
129 struct IDirectMusicBufferImpl {
130 /* IUnknown fields */
131 IDirectMusicBuffer IDirectMusicBuffer_iface;
132 LONG ref;
133
134 /* IDirectMusicBufferImpl fields */
135 GUID format;
136 DWORD size;
137 LPBYTE data;
138 DWORD write_pos;
139 REFERENCE_TIME start_time;
140 };
141
142 /*****************************************************************************
143 * IDirectMusicDownloadedInstrumentImpl implementation structure
144 */
145 struct IDirectMusicDownloadedInstrumentImpl {
146 /* IUnknown fields */
147 IDirectMusicDownloadedInstrument IDirectMusicDownloadedInstrument_iface;
148 LONG ref;
149
150 /* IDirectMusicDownloadedInstrumentImpl fields */
151 BOOL downloaded;
152 void *data;
153 };
154
155 /*****************************************************************************
156 * IDirectMusicDownloadImpl implementation structure
157 */
158 struct IDirectMusicDownloadImpl {
159 /* IUnknown fields */
160 IDirectMusicDownload IDirectMusicDownload_iface;
161 LONG ref;
162
163 /* IDirectMusicDownloadImpl fields */
164 };
165
166 /*****************************************************************************
167 * SynthPortImpl implementation structure
168 */
169 struct SynthPortImpl {
170 /* IUnknown fields */
171 IDirectMusicPort IDirectMusicPort_iface;
172 IDirectMusicPortDownload IDirectMusicPortDownload_iface;
173 IDirectMusicThru IDirectMusicThru_iface;
174 LONG ref;
175
176 /* IDirectMusicPort fields */
177 IDirectSound* pDirectSound;
178 IReferenceClock* pLatencyClock;
179 IDirectMusicSynth* synth;
180 IDirectMusicSynthSink* synth_sink;
181 BOOL fActive;
182 DMUS_PORTCAPS caps;
183 DMUS_PORTPARAMS params;
184 int nrofgroups;
185 DMUSIC_PRIVATE_CHANNEL_GROUP group[1];
186 };
187
188 /** Internal factory */
189 extern HRESULT DMUSIC_CreateSynthPortImpl(LPCGUID guid, LPVOID *object, LPUNKNOWN unkouter, LPDMUS_PORTPARAMS port_params, LPDMUS_PORTCAPS port_caps, DWORD device) DECLSPEC_HIDDEN;
190 extern HRESULT DMUSIC_CreateMidiOutPortImpl(LPCGUID guid, LPVOID *object, LPUNKNOWN unkouter, LPDMUS_PORTPARAMS port_params, LPDMUS_PORTCAPS port_caps, DWORD device) DECLSPEC_HIDDEN;
191 extern HRESULT DMUSIC_CreateMidiInPortImpl(LPCGUID guid, LPVOID *object, LPUNKNOWN unkouter, LPDMUS_PORTPARAMS port_params, LPDMUS_PORTCAPS port_caps, DWORD device) DECLSPEC_HIDDEN;
192
193 /*****************************************************************************
194 * IReferenceClockImpl implementation structure
195 */
196 struct IReferenceClockImpl {
197 /* IUnknown fields */
198 IReferenceClock IReferenceClock_iface;
199 LONG ref;
200
201 /* IReferenceClockImpl fields */
202 REFERENCE_TIME rtTime;
203 DMUS_CLOCKINFO pClockInfo;
204 };
205
206 typedef struct _DMUS_PRIVATE_INSTRUMENT_ENTRY {
207 struct list entry; /* for listing elements */
208 IDirectMusicInstrument* pInstrument;
209 } DMUS_PRIVATE_INSTRUMENTENTRY, *LPDMUS_PRIVATE_INSTRUMENTENTRY;
210
211 typedef struct _DMUS_PRIVATE_POOLCUE {
212 struct list entry; /* for listing elements */
213 } DMUS_PRIVATE_POOLCUE, *LPDMUS_PRIVATE_POOLCUE;
214
215 /*****************************************************************************
216 * IDirectMusicCollectionImpl implementation structure
217 */
218 struct IDirectMusicCollectionImpl {
219 /* IUnknown fields */
220 IDirectMusicCollection IDirectMusicCollection_iface;
221 IDirectMusicObject IDirectMusicObject_iface;
222 IPersistStream IPersistStream_iface;
223 LONG ref;
224
225 /* IDirectMusicCollectionImpl fields */
226 IStream *pStm; /* stream from which we load collection and later instruments */
227 LARGE_INTEGER liCollectionPosition; /* offset in a stream where collection was loaded from */
228 LARGE_INTEGER liWavePoolTablePosition; /* offset in a stream where wave pool table can be found */
229 LPDMUS_OBJECTDESC pDesc;
230 CHAR* szCopyright; /* FIXME: should probably placed somewhere else */
231 LPDLSHEADER pHeader;
232 /* pool table */
233 LPPOOLTABLE pPoolTable;
234 LPPOOLCUE pPoolCues;
235 /* instruments */
236 struct list Instruments;
237 };
238
239 /*****************************************************************************
240 * IDirectMusicInstrumentImpl implementation structure
241 */
242 struct IDirectMusicInstrumentImpl {
243 /* IUnknown fields */
244 IDirectMusicInstrument IDirectMusicInstrument_iface;
245 LONG ref;
246
247 /* IDirectMusicInstrumentImpl fields */
248 LARGE_INTEGER liInstrumentPosition; /* offset in a stream where instrument chunk can be found */
249 ULONG length; /* Length of the instrument in the stream */
250 GUID id;
251 INSTHEADER header;
252 WCHAR wszName[DMUS_MAX_NAME];
253 /* instrument data */
254 BOOL loaded;
255 instrument_region *regions;
256 ULONG nb_articulations;
257 instrument_articulation *articulations;
258 };
259
260 static inline IDirectMusicInstrumentImpl *impl_from_IDirectMusicInstrument(IDirectMusicInstrument *iface)
261 {
262 return CONTAINING_RECORD(iface, IDirectMusicInstrumentImpl, IDirectMusicInstrument_iface);
263 }
264
265 /* custom :) */
266 extern HRESULT IDirectMusicInstrumentImpl_CustomLoad(IDirectMusicInstrument *iface, IStream *stream) DECLSPEC_HIDDEN;
267
268 /**********************************************************************
269 * Dll lifetime tracking declaration for dmusic.dll
270 */
271 extern LONG DMUSIC_refCount DECLSPEC_HIDDEN;
272 static inline void DMUSIC_LockModule(void) { InterlockedIncrement( &DMUSIC_refCount ); }
273 static inline void DMUSIC_UnlockModule(void) { InterlockedDecrement( &DMUSIC_refCount ); }
274
275
276 /*****************************************************************************
277 * Misc.
278 */
279 /* my custom ICOM stuff */
280 #define ICOM_NAME_MULTI(impl,field,iface,name) impl* const name=(impl*)((char*)(iface) - offsetof(impl,field))
281 #define ICOM_THIS_MULTI(impl,field,iface) ICOM_NAME_MULTI(impl,field,iface,This)
282
283 /* for simpler reading */
284 typedef struct _DMUS_PRIVATE_CHUNK {
285 FOURCC fccID; /* FOURCC ID of the chunk */
286 DWORD dwSize; /* size of the chunk */
287 } DMUS_PRIVATE_CHUNK, *LPDMUS_PRIVATE_CHUNK;
288
289 /* used for generic dumping (copied from ddraw) */
290 typedef struct {
291 DWORD val;
292 const char* name;
293 } flag_info;
294
295 typedef struct {
296 const GUID *guid;
297 const char* name;
298 } guid_info;
299
300 /* used for initialising structs (primarily for DMUS_OBJECTDESC) */
301 #define DM_STRUCT_INIT(x) \
302 do { \
303 memset((x), 0, sizeof(*(x))); \
304 (x)->dwSize = sizeof(*x); \
305 } while (0)
306
307 #define FE(x) { x, #x }
308 #define GE(x) { &x, #x }
309
310 /* dwPatch from MIDILOCALE */
311 extern DWORD MIDILOCALE2Patch (const MIDILOCALE *pLocale) DECLSPEC_HIDDEN;
312 /* MIDILOCALE from dwPatch */
313 extern void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) DECLSPEC_HIDDEN;
314
315 /* check whether the given DWORD is even (return 0) or odd (return 1) */
316 extern int even_or_odd (DWORD number) DECLSPEC_HIDDEN;
317 /* FOURCC to string conversion for debug messages */
318 extern const char *debugstr_fourcc (DWORD fourcc) DECLSPEC_HIDDEN;
319 /* returns name of given GUID */
320 extern const char *debugstr_dmguid (const GUID *id) DECLSPEC_HIDDEN;
321 /* Dump whole DMUS_OBJECTDESC struct */
322 extern void dump_DMUS_OBJECTDESC(LPDMUS_OBJECTDESC desc) DECLSPEC_HIDDEN;
323 /* Dump whole DMUS_PORTPARAMS struct */
324 extern void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params) DECLSPEC_HIDDEN;
325
326 #endif /* __WINE_DMUSIC_PRIVATE_H */