3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include "dmusic_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
42 IClassFactory IClassFactory_iface
;
43 HRESULT (*create_instance
)(IUnknown
**ret_iface
);
46 /******************************************************************
47 * IClassFactory implementation
49 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
51 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
54 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
59 if (IsEqualGUID(&IID_IUnknown
, riid
))
60 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
61 else if (IsEqualGUID(&IID_IClassFactory
, riid
))
62 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
64 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
70 IUnknown_AddRef((IUnknown
*)*ppv
);
74 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
76 return 2; /* non-heap based object */
79 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
81 return 1; /* non-heap based object */
84 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*unk_outer
, REFIID riid
, void **ret_iface
)
86 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
90 TRACE("(%p, %s, %p)\n", unk_outer
, debugstr_dmguid(riid
), ret_iface
);
93 if (unk_outer
) return CLASS_E_NOAGGREGATION
;
94 if (SUCCEEDED(hr
= This
->create_instance(&object
)))
96 hr
= IUnknown_QueryInterface(object
, riid
, ret_iface
);
97 IUnknown_Release(object
);
103 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
105 TRACE("(%d)\n", dolock
);
109 static const IClassFactoryVtbl classfactory_vtbl
= {
110 ClassFactory_QueryInterface
,
112 ClassFactory_Release
,
113 ClassFactory_CreateInstance
,
114 ClassFactory_LockServer
117 static IClassFactoryImpl DirectMusic_CF
= {{&classfactory_vtbl
}, music_create
};
118 static IClassFactoryImpl Collection_CF
= {{&classfactory_vtbl
}, collection_create
};
122 /******************************************************************
123 * DllGetClassObject (DMUSIC.@)
127 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
129 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
130 if (IsEqualCLSID (rclsid
, &CLSID_DirectMusic
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
131 *ppv
= &DirectMusic_CF
;
132 IClassFactory_AddRef((IClassFactory
*)*ppv
);
134 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicCollection
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
135 *ppv
= &Collection_CF
;
136 IClassFactory_AddRef((IClassFactory
*)*ppv
);
140 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
141 return CLASS_E_CLASSNOTAVAILABLE
;
144 /******************************************************************
149 /* dwPatch from MIDILOCALE */
150 DWORD
MIDILOCALE2Patch (const MIDILOCALE
*pLocale
) {
152 if (!pLocale
) return 0;
153 dwPatch
|= (pLocale
->ulBank
& F_INSTRUMENT_DRUMS
); /* set drum bit */
154 dwPatch
|= ((pLocale
->ulBank
& 0x00007F7F) << 8); /* set MIDI bank location */
155 dwPatch
|= (pLocale
->ulInstrument
& 0x0000007F); /* set PC value */
159 /* MIDILOCALE from dwPatch */
160 void Patch2MIDILOCALE (DWORD dwPatch
, LPMIDILOCALE pLocale
) {
161 memset (pLocale
, 0, sizeof(MIDILOCALE
));
163 pLocale
->ulInstrument
= (dwPatch
& 0x7F); /* get PC value */
164 pLocale
->ulBank
= ((dwPatch
& 0x007F7F00) >> 8); /* get MIDI bank location */
165 pLocale
->ulBank
|= (dwPatch
& F_INSTRUMENT_DRUMS
); /* get drum bit */
168 /* generic flag-dumping function */
169 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
170 char buffer
[128] = "", *ptr
= &buffer
[0];
172 int size
= sizeof(buffer
);
174 for (i
=0; i
< num_names
; i
++)
176 if ((flags
& names
[i
].val
) || /* standard flag*/
177 ((!flags
) && (!names
[i
].val
))) { /* zero value only */
178 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
179 if (cnt
< 0 || cnt
>= size
) break;
185 return wine_dbg_sprintf("%s", buffer
);
188 /* Dump DMUS_PORTPARAMS flags */
189 static const char* debugstr_DMUS_PORTPARAMS_FLAGS(DWORD flagmask
)
191 static const flag_info flags
[] = {
192 FE(DMUS_PORTPARAMS_VOICES
),
193 FE(DMUS_PORTPARAMS_CHANNELGROUPS
),
194 FE(DMUS_PORTPARAMS_AUDIOCHANNELS
),
195 FE(DMUS_PORTPARAMS_SAMPLERATE
),
196 FE(DMUS_PORTPARAMS_EFFECTS
),
197 FE(DMUS_PORTPARAMS_SHARE
)
199 return debugstr_flags(flagmask
, flags
, ARRAY_SIZE(flags
));
202 /* Dump whole DMUS_PORTPARAMS struct */
203 void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params
)
205 TRACE("DMUS_PORTPARAMS (%p):\n", params
);
206 TRACE(" - dwSize = %ld\n", params
->dwSize
);
207 TRACE(" - dwValidParams = %s\n", debugstr_DMUS_PORTPARAMS_FLAGS(params
->dwValidParams
));
208 if (params
->dwValidParams
& DMUS_PORTPARAMS_VOICES
) TRACE(" - dwVoices = %lu\n", params
->dwVoices
);
209 if (params
->dwValidParams
& DMUS_PORTPARAMS_CHANNELGROUPS
) TRACE(" - dwChannelGroup = %lu\n", params
->dwChannelGroups
);
210 if (params
->dwValidParams
& DMUS_PORTPARAMS_AUDIOCHANNELS
) TRACE(" - dwAudioChannels = %lu\n", params
->dwAudioChannels
);
211 if (params
->dwValidParams
& DMUS_PORTPARAMS_SAMPLERATE
) TRACE(" - dwSampleRate = %lu\n", params
->dwSampleRate
);
212 if (params
->dwValidParams
& DMUS_PORTPARAMS_EFFECTS
) TRACE(" - dwEffectFlags = %lx\n", params
->dwEffectFlags
);
213 if (params
->dwValidParams
& DMUS_PORTPARAMS_SHARE
) TRACE(" - fShare = %u\n", params
->fShare
);