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