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