Fix implementation of IDirectMusic8Impl_CreatePort.
[wine] / dlls / dmusic / dmusic_private.h
1 /* DirectMusic Private Include
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 #ifndef __WINE_DMUSIC_PRIVATE_H
21 #define __WINE_DMUSIC_PRIVATE_H
22
23 #include <stdarg.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32
33 #include "wine/debug.h"
34 #include "wine/list.h"
35 #include "wine/unicode.h"
36 #include "winreg.h"
37 #include "objbase.h"
38
39 #include "dmusici.h"
40 #include "dmusicf.h"
41 #include "dmusics.h"
42
43 /*****************************************************************************
44  * Interfaces
45  */
46 typedef struct IDirectMusic8Impl IDirectMusic8Impl;
47 typedef struct IDirectMusicBufferImpl IDirectMusicBufferImpl;
48 typedef struct IDirectMusicDownloadedInstrumentImpl IDirectMusicDownloadedInstrumentImpl;
49 typedef struct IDirectMusicDownloadImpl IDirectMusicDownloadImpl;
50 typedef struct IDirectMusicPortDownloadImpl IDirectMusicPortDownloadImpl;
51 typedef struct IDirectMusicPortImpl IDirectMusicPortImpl;
52 typedef struct IDirectMusicThruImpl IDirectMusicThruImpl;
53 typedef struct IReferenceClockImpl IReferenceClockImpl;
54
55 typedef struct IDirectMusicCollectionImpl IDirectMusicCollectionImpl;
56 typedef struct IDirectMusicInstrumentImpl IDirectMusicInstrumentImpl;
57
58         
59 /*****************************************************************************
60  * Predeclare the interface implementation structures
61  */
62 extern const IDirectMusicPortVtbl DirectMusicPort_Vtbl;
63
64 /*****************************************************************************
65  * Some stuff to make my life easier :=)
66  */
67  
68 /* some sort of aux. midi channel: big fake at the moment; accepts only priority
69    changes... more coming soon */
70 typedef struct DMUSIC_PRIVATE_MCHANNEL_ {
71         DWORD priority;
72 } DMUSIC_PRIVATE_MCHANNEL, *LPDMUSIC_PRIVATE_MCHANNEL;
73
74 /* some sort of aux. channel group: collection of 16 midi channels */
75 typedef struct DMUSIC_PRIVATE_CHANNEL_GROUP_ {
76         DMUSIC_PRIVATE_MCHANNEL channel[16]; /* 16 channels in a group */
77 } DMUSIC_PRIVATE_CHANNEL_GROUP, *LPDMUSIC_PRIVATE_CHANNEL_GROUP;
78
79
80 /*****************************************************************************
81  * ClassFactory
82  */
83 extern HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
84 extern HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
85 extern HRESULT WINAPI DMUSIC_CreateDirectMusicDownloadedInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
86 extern HRESULT WINAPI DMUSIC_CreateDirectMusicDownloadImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
87 extern HRESULT WINAPI DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
88
89 extern HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
90 extern HRESULT WINAPI DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter);
91
92 /*****************************************************************************
93  * IDirectMusic8Impl implementation structure
94  */
95 struct IDirectMusic8Impl {
96   /* IUnknown fields */
97   const IDirectMusic8Vtbl *lpVtbl;
98   LONG           ref;
99
100   /* IDirectMusicImpl fields */
101   IReferenceClockImpl* pMasterClock;
102   IDirectMusicPort** ppPorts;
103   int nrofports;
104 };
105
106 /* IUnknown: */
107 extern ULONG WINAPI   IDirectMusic8Impl_AddRef (LPDIRECTMUSIC8 iface);
108
109 /*****************************************************************************
110  * IDirectMusicBufferImpl implementation structure
111  */
112 struct IDirectMusicBufferImpl {
113   /* IUnknown fields */
114   const IDirectMusicBufferVtbl *lpVtbl;
115   LONG           ref;
116
117   /* IDirectMusicBufferImpl fields */
118 };
119
120 /* IUnknown: */
121 extern ULONG WINAPI   IDirectMusicBufferImpl_AddRef (LPDIRECTMUSICBUFFER iface);
122
123 /*****************************************************************************
124  * IDirectMusicDownloadedInstrumentImpl implementation structure
125  */
126 struct IDirectMusicDownloadedInstrumentImpl {
127   /* IUnknown fields */
128   const IDirectMusicDownloadedInstrumentVtbl *lpVtbl;
129   LONG           ref;
130
131   /* IDirectMusicDownloadedInstrumentImpl fields */
132 };
133
134 /* IUnknown: */
135 extern ULONG WINAPI   IDirectMusicDownloadedInstrumentImpl_AddRef (LPDIRECTMUSICDOWNLOADEDINSTRUMENT iface);
136 /* IDirectMusicDownloadedInstrumentImpl: */
137 /* none yet */
138
139 /*****************************************************************************
140  * IDirectMusicDownloadImpl implementation structure
141  */
142 struct IDirectMusicDownloadImpl {
143   /* IUnknown fields */
144   const IDirectMusicDownloadVtbl *lpVtbl;
145   LONG           ref;
146
147   /* IDirectMusicDownloadImpl fields */
148 };
149
150 /* IUnknown: */
151 extern ULONG WINAPI   IDirectMusicDownloadImpl_AddRef (LPDIRECTMUSICDOWNLOAD iface);
152
153 /*****************************************************************************
154  * IDirectMusicPortDownloadImpl implementation structure
155  */
156 struct IDirectMusicPortDownloadImpl {
157   /* IUnknown fields */
158   const IDirectMusicPortDownloadVtbl *lpVtbl;
159   LONG           ref;
160
161   /* IDirectMusicPortDownloadImpl fields */
162 };
163
164 /* IUnknown: */
165 extern ULONG WINAPI   IDirectMusicPortDownloadImpl_AddRef (LPDIRECTMUSICPORTDOWNLOAD iface);
166
167 /*****************************************************************************
168  * IDirectMusicPortImpl implementation structure
169  */
170 struct IDirectMusicPortImpl {
171   /* IUnknown fields */
172   const IDirectMusicPortVtbl *lpVtbl;
173   LONG           ref;
174
175   /* IDirectMusicPortImpl fields */
176   IDirectSound* pDirectSound;
177   IReferenceClock* pLatencyClock;
178   BOOL fActive;
179   DMUS_PORTCAPS caps;
180   DMUS_PORTPARAMS params;
181   int nrofgroups;
182   DMUSIC_PRIVATE_CHANNEL_GROUP group[1];
183 };
184
185 /* IUnknown: */
186 extern ULONG WINAPI   IDirectMusicPortImpl_AddRef (LPDIRECTMUSICPORT iface);
187 extern HRESULT WINAPI IDirectMusicPortImpl_Activate (LPDIRECTMUSICPORT iface, BOOL fActive);
188
189 /** Internal factory */
190 extern HRESULT WINAPI DMUSIC_CreateDirectMusicPortImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter, LPDMUS_PORTPARAMS pPortParams, LPDMUS_PORTCAPS pPortCaps);
191
192 /*****************************************************************************
193  * IDirectMusicThruImpl implementation structure
194  */
195 struct IDirectMusicThruImpl {
196   /* IUnknown fields */
197   const IDirectMusicThruVtbl *lpVtbl;
198   LONG           ref;
199
200   /* IDirectMusicThruImpl fields */
201 };
202
203 /* IUnknown: */
204 extern ULONG WINAPI   IDirectMusicThruImpl_AddRef (LPDIRECTMUSICTHRU iface);
205
206 /*****************************************************************************
207  * IReferenceClockImpl implementation structure
208  */
209 struct IReferenceClockImpl {
210   /* IUnknown fields */
211   const IReferenceClockVtbl *lpVtbl;
212   LONG           ref;
213
214   /* IReferenceClockImpl fields */
215   REFERENCE_TIME rtTime;
216   DMUS_CLOCKINFO pClockInfo;
217 };
218
219 /* IUnknown: */
220 extern ULONG WINAPI   IReferenceClockImpl_AddRef (IReferenceClock *iface);
221
222 typedef struct _DMUS_PRIVATE_INSTRUMENT_ENTRY {
223         struct list entry; /* for listing elements */
224         IDirectMusicInstrument* pInstrument;
225 } DMUS_PRIVATE_INSTRUMENTENTRY, *LPDMUS_PRIVATE_INSTRUMENTENTRY;
226
227 typedef struct _DMUS_PRIVATE_POOLCUE {
228         struct list entry; /* for listing elements */
229 } DMUS_PRIVATE_POOLCUE, *LPDMUS_PRIVATE_POOLCUE;
230
231 /*****************************************************************************
232  * IDirectMusicCollectionImpl implementation structure
233  */
234 struct IDirectMusicCollectionImpl {
235   /* IUnknown fields */
236   const IUnknownVtbl *UnknownVtbl;
237   const IDirectMusicCollectionVtbl *CollectionVtbl;
238   const IDirectMusicObjectVtbl *ObjectVtbl;
239   const IPersistStreamVtbl *PersistStreamVtbl;
240   LONG           ref;
241
242   /* IDirectMusicCollectionImpl fields */
243   IStream *pStm; /* stream from which we load collection and later instruments */
244   LARGE_INTEGER liCollectionPosition; /* offset in a stream where collection was loaded from */
245   LARGE_INTEGER liWavePoolTablePosition; /* offset in a stream where wave pool table can be found */
246   LPDMUS_OBJECTDESC pDesc;
247   CHAR* szCopyright; /* FIXME: should probably placed somewhere else */
248   LPDLSHEADER pHeader;
249   /* pool table */
250   LPPOOLTABLE pPoolTable;
251   LPPOOLCUE pPoolCues;
252   /* instruments */
253   struct list Instruments;
254 };
255
256 /* IUnknown: */
257 extern ULONG WINAPI   IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface);
258 /* IDirectMusicCollection: */
259 extern ULONG WINAPI   IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface);
260 /* IDirectMusicObject: */
261 extern ULONG WINAPI   IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface);
262 /* IPersistStream: */
263 extern ULONG WINAPI   IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface);
264
265 /*****************************************************************************
266  * IDirectMusicInstrumentImpl implementation structure
267  */
268 struct IDirectMusicInstrumentImpl {
269   /* IUnknown fields */
270   const IUnknownVtbl *UnknownVtbl;
271   const IDirectMusicInstrumentVtbl *InstrumentVtbl;
272   LONG           ref;
273
274   /* IDirectMusicInstrumentImpl fields */
275   LARGE_INTEGER liInstrumentPosition; /* offset in a stream where instrument chunk can be found */
276   LPGUID pInstrumentID;
277   LPINSTHEADER pHeader;
278   WCHAR wszName[DMUS_MAX_NAME];
279   /* instrument data */
280 };
281
282 /* IUnknown: */
283 extern ULONG WINAPI   IDirectMusicInstrumentImpl_IUnknown_AddRef (LPUNKNOWN iface);
284 /* IDirectMusicInstrumentImpl: */
285 extern ULONG WINAPI   IDirectMusicInstrumentImpl_IDirectMusicInstrument_AddRef (LPDIRECTMUSICINSTRUMENT iface);
286 /* custom :) */
287 extern HRESULT WINAPI IDirectMusicInstrumentImpl_Custom_Load (LPDIRECTMUSICINSTRUMENT iface, LPSTREAM pStm);
288
289 /**********************************************************************
290  * Dll lifetime tracking declaration for dmusic.dll
291  */
292 extern LONG DMUSIC_refCount;
293 static inline void DMUSIC_LockModule(void) { InterlockedIncrement( &DMUSIC_refCount ); }
294 static inline void DMUSIC_UnlockModule(void) { InterlockedDecrement( &DMUSIC_refCount ); }
295
296 /*****************************************************************************
297  * Helper Functions
298  */
299 void register_waveport (LPGUID lpGUID, LPCSTR lpszDesc, LPCSTR lpszDrvName, LPVOID lpContext);
300
301
302 /*****************************************************************************
303  * Misc.
304  */
305 /* my custom ICOM stuff */
306 #define ICOM_NAME_MULTI(impl,field,iface,name)  impl* const name=(impl*)((char*)(iface) - offsetof(impl,field))
307 #define ICOM_THIS_MULTI(impl,field,iface) ICOM_NAME_MULTI(impl,field,iface,This)
308  
309 /* for simpler reading */
310 typedef struct _DMUS_PRIVATE_CHUNK {
311         FOURCC fccID; /* FOURCC ID of the chunk */
312         DWORD dwSize; /* size of the chunk */
313 } DMUS_PRIVATE_CHUNK, *LPDMUS_PRIVATE_CHUNK;
314
315 /* used for generic dumping (copied from ddraw) */
316 typedef struct {
317     DWORD val;
318     const char* name;
319 } flag_info;
320
321 typedef struct {
322     const GUID *guid;
323     const char* name;
324 } guid_info;
325
326 /* used for initialising structs (primarily for DMUS_OBJECTDESC) */
327 #define DM_STRUCT_INIT(x)                               \
328         do {                                                            \
329                 memset((x), 0, sizeof(*(x)));   \
330                 (x)->dwSize = sizeof(*x);               \
331         } while (0)
332
333 #define FE(x) { x, #x } 
334 #define GE(x) { &x, #x }
335
336 /* dwPatch from MIDILOCALE */
337 extern DWORD MIDILOCALE2Patch (LPMIDILOCALE pLocale);
338 /* MIDILOCALE from dwPatch */
339 extern void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale);
340
341 /* check whether the given DWORD is even (return 0) or odd (return 1) */
342 extern int even_or_odd (DWORD number);
343 /* FOURCC to string conversion for debug messages */
344 extern const char *debugstr_fourcc (DWORD fourcc);
345 /* DMUS_VERSION struct to string conversion for debug messages */
346 extern const char *debugstr_dmversion (LPDMUS_VERSION version);
347 /* returns name of given GUID */
348 extern const char *debugstr_dmguid (const GUID *id);
349 /* returns name of given error code */
350 extern const char *debugstr_dmreturn (DWORD code);
351 /* generic flags-dumping function */
352 extern const char *debugstr_flags (DWORD flags, const flag_info* names, size_t num_names);
353 extern const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask);
354 /* dump whole DMUS_OBJECTDESC struct */
355 extern const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc);
356
357 #endif  /* __WINE_DMUSIC_PRIVATE_H */