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