2012-05-24 08:50:24 +02:00
|
|
|
/*
|
|
|
|
* IDirectMusic8 Implementation
|
2003-03-21 01:42:38 +01:00
|
|
|
*
|
2004-01-20 01:21:40 +01:00
|
|
|
* Copyright (C) 2003-2004 Rok Mandeljc
|
2012-05-24 08:50:24 +02:00
|
|
|
* Copyright (C) 2012 Christian Costa
|
2003-03-21 01:42:38 +01:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-03-21 01:42:38 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-05-30 12:54:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-03-21 01:42:38 +01:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-03-21 01:42:38 +01:00
|
|
|
*/
|
2012-03-29 08:52:45 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-03-21 01:42:38 +01:00
|
|
|
#include "dmusic_private.h"
|
2019-12-13 00:29:06 +01:00
|
|
|
#include "dmobject.h"
|
2019-06-14 18:42:45 +02:00
|
|
|
#include "wine/heap.h"
|
2003-03-21 01:42:38 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
|
|
|
|
|
2019-06-14 18:42:45 +02:00
|
|
|
struct master_clock {
|
|
|
|
IReferenceClock IReferenceClock_iface;
|
|
|
|
LONG ref;
|
|
|
|
double freq;
|
|
|
|
REFERENCE_TIME last_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct master_clock *impl_from_IReferenceClock(IReferenceClock *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct master_clock, IReferenceClock_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI master_IReferenceClock_QueryInterface(IReferenceClock *iface, REFIID riid,
|
|
|
|
void **ret_iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IReferenceClock))
|
|
|
|
*ret_iface = iface;
|
|
|
|
else {
|
|
|
|
WARN("no interface for %s\n", debugstr_dmguid(riid));
|
|
|
|
*ret_iface = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IReferenceClock_AddRef(iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI master_IReferenceClock_AddRef(IReferenceClock *iface)
|
|
|
|
{
|
|
|
|
struct master_clock *This = impl_from_IReferenceClock(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p) ref = %lu\n", iface, ref);
|
2019-06-14 18:42:45 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI master_IReferenceClock_Release(IReferenceClock *iface)
|
|
|
|
{
|
|
|
|
struct master_clock *This = impl_from_IReferenceClock(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p) ref = %lu\n", iface, ref);
|
2019-06-14 18:42:45 +02:00
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
heap_free(This);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI master_IReferenceClock_GetTime(IReferenceClock *iface,
|
|
|
|
REFERENCE_TIME *time)
|
|
|
|
{
|
|
|
|
struct master_clock *This = impl_from_IReferenceClock(iface);
|
|
|
|
LARGE_INTEGER counter;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, time);
|
|
|
|
|
|
|
|
QueryPerformanceCounter(&counter);
|
|
|
|
*time = counter.QuadPart * This->freq;
|
|
|
|
hr = (*time == This->last_time) ? S_FALSE : S_OK;
|
|
|
|
This->last_time = *time;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI master_IReferenceClock_AdviseTime(IReferenceClock *iface,
|
|
|
|
REFERENCE_TIME base, REFERENCE_TIME offset, HANDLE event, DWORD *cookie)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %s, %s, %p, %p): method not implemented\n", iface, wine_dbgstr_longlong(base),
|
|
|
|
wine_dbgstr_longlong(offset), event, cookie);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI master_IReferenceClock_AdvisePeriodic(IReferenceClock *iface,
|
|
|
|
REFERENCE_TIME start, REFERENCE_TIME period, HANDLE semaphore, DWORD *cookie)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %s, %s, %p, %p): method not implemented\n", iface, wine_dbgstr_longlong(start),
|
|
|
|
wine_dbgstr_longlong(period), semaphore, cookie);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI master_IReferenceClock_Unadvise(IReferenceClock *iface, DWORD cookie)
|
|
|
|
{
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p, %#lx): method not implemented\n", iface, cookie);
|
2019-06-14 18:42:45 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IReferenceClockVtbl master_clock_vtbl = {
|
|
|
|
master_IReferenceClock_QueryInterface,
|
|
|
|
master_IReferenceClock_AddRef,
|
|
|
|
master_IReferenceClock_Release,
|
|
|
|
master_IReferenceClock_GetTime,
|
|
|
|
master_IReferenceClock_AdviseTime,
|
|
|
|
master_IReferenceClock_AdvisePeriodic,
|
|
|
|
master_IReferenceClock_Unadvise,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT master_clock_create(IReferenceClock **clock)
|
|
|
|
{
|
|
|
|
struct master_clock *obj;
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", clock);
|
|
|
|
|
|
|
|
if (!(obj = heap_alloc_zero(sizeof(*obj))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
obj->IReferenceClock_iface.lpVtbl = &master_clock_vtbl;
|
|
|
|
obj->ref = 1;
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
obj->freq = 10000000.0 / freq.QuadPart;
|
|
|
|
|
|
|
|
*clock = &obj->IReferenceClock_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static inline IDirectMusic8Impl *impl_from_IDirectMusic8(IDirectMusic8 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusic8Impl, IDirectMusic8_iface);
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusic8Impl IUnknown part: */
|
2012-05-24 08:50:32 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_QueryInterface(LPDIRECTMUSIC8 iface, REFIID riid, LPVOID *ret_iface)
|
2012-05-01 10:06:58 +02:00
|
|
|
{
|
2012-05-24 08:50:32 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualIID (riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID (riid, &IID_IDirectMusic) ||
|
|
|
|
IsEqualIID (riid, &IID_IDirectMusic2) ||
|
|
|
|
IsEqualIID (riid, &IID_IDirectMusic8))
|
|
|
|
{
|
|
|
|
IDirectMusic8_AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_iface = NULL;
|
|
|
|
|
|
|
|
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static ULONG WINAPI IDirectMusic8Impl_AddRef(LPDIRECTMUSIC8 iface)
|
|
|
|
{
|
2012-05-24 08:50:24 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p): new ref = %lu\n", This, ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-05-24 08:50:24 +02:00
|
|
|
return ref;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static ULONG WINAPI IDirectMusic8Impl_Release(LPDIRECTMUSIC8 iface)
|
|
|
|
{
|
2012-05-24 08:50:24 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p): new ref = %lu\n", This, ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-05-24 08:50:24 +02:00
|
|
|
if (!ref) {
|
2019-06-14 18:42:44 +02:00
|
|
|
IReferenceClock_Release(This->master_clock);
|
2017-05-10 15:13:19 +02:00
|
|
|
if (This->dsound)
|
|
|
|
IDirectSound_Release(This->dsound);
|
2012-09-16 20:24:10 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->system_ports);
|
2017-05-10 14:43:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->ports);
|
2012-05-24 08:50:24 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2014-05-31 19:21:33 +02:00
|
|
|
DMUSIC_UnlockModule();
|
2012-05-24 08:50:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusic8Impl IDirectMusic part: */
|
2012-03-29 08:52:45 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_EnumPort(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_PORTCAPS port_caps)
|
|
|
|
{
|
2012-05-01 10:06:58 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
2012-03-29 08:52:45 +02:00
|
|
|
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p, %ld, %p)\n", This, index, port_caps);
|
2012-03-29 08:52:45 +02:00
|
|
|
|
|
|
|
if (!port_caps)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2017-05-10 14:43:59 +02:00
|
|
|
if (index >= This->num_system_ports)
|
2012-09-16 20:24:10 +02:00
|
|
|
return S_FALSE;
|
2012-03-29 08:52:45 +02:00
|
|
|
|
2012-09-16 20:24:10 +02:00
|
|
|
*port_caps = This->system_ports[index].caps;
|
2012-03-29 08:52:45 +02:00
|
|
|
|
2012-09-16 20:24:10 +02:00
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-16 20:23:54 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer(LPDIRECTMUSIC8 iface, LPDMUS_BUFFERDESC buffer_desc, LPDIRECTMUSICBUFFER* buffer, LPUNKNOWN unkouter)
|
2012-04-21 14:19:35 +02:00
|
|
|
{
|
2012-09-16 20:23:54 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
2008-12-22 14:19:30 +01:00
|
|
|
|
2012-09-16 20:23:54 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p)\n", This, buffer_desc, buffer, unkouter);
|
2008-12-22 14:19:30 +01:00
|
|
|
|
2012-09-16 20:23:54 +02:00
|
|
|
if (unkouter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2008-12-22 14:19:30 +01:00
|
|
|
|
2012-09-16 20:23:54 +02:00
|
|
|
if (!buffer_desc || !buffer)
|
|
|
|
return E_POINTER;
|
2008-12-22 14:19:30 +01:00
|
|
|
|
2012-09-16 20:23:54 +02:00
|
|
|
return DMUSIC_CreateDirectMusicBufferImpl(buffer_desc, (LPVOID)buffer);
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 22:31:58 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSID rclsid_port, LPDMUS_PORTPARAMS port_params, LPDIRECTMUSICPORT* port, LPUNKNOWN unkouter)
|
2012-04-10 22:30:38 +02:00
|
|
|
{
|
2012-09-17 22:31:58 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
int i;
|
|
|
|
DMUS_PORTCAPS port_caps;
|
|
|
|
IDirectMusicPort* new_port = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
GUID default_port;
|
|
|
|
const GUID *request_port = rclsid_port;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p, %p, %p)\n", This, debugstr_dmguid(rclsid_port), port_params, port, unkouter);
|
|
|
|
|
2017-05-12 16:11:25 +02:00
|
|
|
if (!rclsid_port || !port)
|
2012-09-17 22:31:58 +02:00
|
|
|
return E_POINTER;
|
|
|
|
if (!port_params)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (unkouter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2017-05-12 16:11:25 +02:00
|
|
|
if (!This->dsound)
|
|
|
|
return DMUS_E_DSOUND_NOT_SET;
|
2012-09-17 22:31:58 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(dmusic))
|
|
|
|
dump_DMUS_PORTPARAMS(port_params);
|
|
|
|
|
|
|
|
ZeroMemory(&port_caps, sizeof(DMUS_PORTCAPS));
|
|
|
|
port_caps.dwSize = sizeof(DMUS_PORTCAPS);
|
|
|
|
|
|
|
|
if (IsEqualGUID(request_port, &GUID_NULL)) {
|
|
|
|
hr = IDirectMusic8_GetDefaultPort(iface, &default_port);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
request_port = &default_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &port_caps); i++) {
|
|
|
|
if (IsEqualCLSID(request_port, &port_caps.guidPort)) {
|
2017-05-10 14:44:01 +02:00
|
|
|
hr = This->system_ports[i].create(This, port_params, &port_caps, &new_port);
|
2012-09-17 22:31:58 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
*port = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2017-05-10 14:43:59 +02:00
|
|
|
This->num_ports++;
|
|
|
|
if (!This->ports)
|
2017-05-12 16:11:22 +02:00
|
|
|
This->ports = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(*This->ports) * This->num_ports);
|
2012-09-17 22:31:58 +02:00
|
|
|
else
|
2017-05-12 16:11:22 +02:00
|
|
|
This->ports = HeapReAlloc(GetProcessHeap(), 0, This->ports,
|
|
|
|
sizeof(*This->ports) * This->num_ports);
|
2017-05-10 14:43:59 +02:00
|
|
|
This->ports[This->num_ports - 1] = new_port;
|
2012-09-17 22:31:58 +02:00
|
|
|
*port = new_port;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:11:22 +02:00
|
|
|
void dmusic_remove_port(IDirectMusic8Impl *dmusic, IDirectMusicPort *port)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("Removing port %p.\n", port);
|
|
|
|
|
|
|
|
for (i = 0; i < dmusic->num_ports; i++)
|
|
|
|
{
|
|
|
|
if (dmusic->ports[i] == port) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
ERR("Port %p not found in ports array.\n", port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!--dmusic->num_ports) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmusic->ports);
|
|
|
|
dmusic->ports = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove(&dmusic->ports[i], &dmusic->ports[i + 1],
|
|
|
|
(dmusic->num_ports - i) * sizeof(*dmusic->ports));
|
|
|
|
dmusic->ports = HeapReAlloc(GetProcessHeap(), 0, dmusic->ports,
|
|
|
|
sizeof(*dmusic->ports) * dmusic->num_ports);
|
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_CLOCKINFO clock_info)
|
|
|
|
{
|
2022-02-04 22:35:57 +01:00
|
|
|
TRACE("(%p, %ld, %p)\n", iface, index, clock_info);
|
2012-05-01 10:06:58 +02:00
|
|
|
|
2012-05-01 10:07:09 +02:00
|
|
|
if (!clock_info)
|
|
|
|
return E_POINTER;
|
2012-05-01 10:06:58 +02:00
|
|
|
|
2012-05-01 10:07:09 +02:00
|
|
|
if (index > 1)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if (!index)
|
|
|
|
{
|
|
|
|
static const GUID guid_system_clock = { 0x58d58419, 0x71b4, 0x11d1, { 0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12 } };
|
|
|
|
|
|
|
|
clock_info->ctType = 0;
|
|
|
|
clock_info->guidClock = guid_system_clock;
|
2020-01-21 22:24:44 +01:00
|
|
|
lstrcpyW(clock_info->wszDescription, L"System Clock");
|
2012-05-01 10:07:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const GUID guid_dsound_clock = { 0x58d58420, 0x71b4, 0x11d1, { 0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12 } };
|
|
|
|
|
|
|
|
clock_info->ctType = 0;
|
|
|
|
clock_info->guidClock = guid_dsound_clock;
|
2020-01-21 22:24:44 +01:00
|
|
|
lstrcpyW(clock_info->wszDescription, L"DirectSound Clock");
|
2012-05-01 10:07:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-16 20:24:02 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock(LPDIRECTMUSIC8 iface, LPGUID guid_clock, IReferenceClock** reference_clock)
|
2012-05-01 10:06:58 +02:00
|
|
|
{
|
2012-09-16 20:24:02 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
2003-06-07 02:39:18 +02:00
|
|
|
|
2012-09-16 20:24:02 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, guid_clock, reference_clock);
|
2003-06-07 02:39:18 +02:00
|
|
|
|
2012-09-16 20:24:02 +02:00
|
|
|
if (guid_clock)
|
2019-06-14 18:42:44 +02:00
|
|
|
*guid_clock = GUID_NULL;
|
2014-06-16 23:22:54 +02:00
|
|
|
if (reference_clock) {
|
2019-06-14 18:42:44 +02:00
|
|
|
*reference_clock = This->master_clock;
|
2014-06-16 23:22:54 +02:00
|
|
|
IReferenceClock_AddRef(*reference_clock);
|
|
|
|
}
|
2012-09-16 20:24:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock(LPDIRECTMUSIC8 iface, REFGUID rguidClock)
|
|
|
|
{
|
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s): stub\n", This, debugstr_dmguid(rguidClock));
|
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:07:23 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_Activate(LPDIRECTMUSIC8 iface, BOOL enable)
|
2012-05-01 10:06:58 +02:00
|
|
|
{
|
2012-05-01 10:07:23 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u)\n", This, enable);
|
|
|
|
|
2017-05-10 14:43:59 +02:00
|
|
|
for (i = 0; i < This->num_ports; i++)
|
2012-05-01 10:07:23 +02:00
|
|
|
{
|
2017-05-10 14:43:59 +02:00
|
|
|
hr = IDirectMusicPort_Activate(This->ports[i], enable);
|
2012-05-01 10:07:23 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-21 11:46:57 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort(LPDIRECTMUSIC8 iface, LPGUID guid_port)
|
2012-05-01 10:06:58 +02:00
|
|
|
{
|
2012-09-21 11:46:57 +02:00
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
HKEY hkGUID;
|
|
|
|
DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
|
|
|
|
char returnBuffer[51];
|
|
|
|
GUID defaultPortGUID;
|
|
|
|
WCHAR buff[51];
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, guid_port);
|
|
|
|
|
|
|
|
if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) ||
|
|
|
|
(RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
|
|
|
|
{
|
|
|
|
WARN(": registry entry missing\n" );
|
|
|
|
*guid_port = CLSID_DirectMusicSynth;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
/* FIXME: Check return types to ensure we're interpreting data right */
|
2018-10-23 19:42:34 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, ARRAY_SIZE(buff));
|
2012-09-21 11:46:57 +02:00
|
|
|
CLSIDFromString(buff, &defaultPortGUID);
|
|
|
|
*guid_port = defaultPortGUID;
|
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 15:13:19 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(IDirectMusic8 *iface, IDirectSound *dsound,
|
|
|
|
HWND hwnd)
|
2012-05-01 10:06:58 +02:00
|
|
|
{
|
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
2017-05-10 15:13:19 +02:00
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, dsound, hwnd);
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_ports; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectMusicPort_SetDirectSound(This->ports[i], NULL, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->dsound)
|
|
|
|
IDirectSound_Release(This->dsound);
|
|
|
|
|
|
|
|
if (!dsound) {
|
|
|
|
hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&This->dsound, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
hr = IDirectSound_SetCooperativeLevel(This->dsound, hwnd ? hwnd : GetForegroundWindow(),
|
|
|
|
DSSCL_PRIORITY);
|
2017-05-11 11:05:51 +02:00
|
|
|
if (FAILED(hr)) {
|
2017-05-10 15:13:19 +02:00
|
|
|
IDirectSound_Release(This->dsound);
|
2017-05-11 11:05:51 +02:00
|
|
|
This->dsound = NULL;
|
|
|
|
}
|
2017-05-10 15:13:19 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2012-05-01 10:06:58 +02:00
|
|
|
|
2017-05-10 15:13:19 +02:00
|
|
|
IDirectSound_AddRef(dsound);
|
|
|
|
This->dsound = dsound;
|
2012-05-01 10:06:58 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:06:58 +02:00
|
|
|
static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock(LPDIRECTMUSIC8 iface, IReferenceClock* clock)
|
|
|
|
{
|
|
|
|
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, clock);
|
|
|
|
|
|
|
|
return S_OK;
|
2003-04-08 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
|
2012-09-16 20:24:02 +02:00
|
|
|
IDirectMusic8Impl_QueryInterface,
|
|
|
|
IDirectMusic8Impl_AddRef,
|
|
|
|
IDirectMusic8Impl_Release,
|
|
|
|
IDirectMusic8Impl_EnumPort,
|
|
|
|
IDirectMusic8Impl_CreateMusicBuffer,
|
|
|
|
IDirectMusic8Impl_CreatePort,
|
|
|
|
IDirectMusic8Impl_EnumMasterClock,
|
|
|
|
IDirectMusic8Impl_GetMasterClock,
|
|
|
|
IDirectMusic8Impl_SetMasterClock,
|
|
|
|
IDirectMusic8Impl_Activate,
|
|
|
|
IDirectMusic8Impl_GetDefaultPort,
|
|
|
|
IDirectMusic8Impl_SetDirectSound,
|
|
|
|
IDirectMusic8Impl_SetExternalMasterClock
|
2003-04-08 23:42:00 +02:00
|
|
|
};
|
|
|
|
|
2012-09-16 20:24:10 +02:00
|
|
|
static void create_system_ports_list(IDirectMusic8Impl* object)
|
|
|
|
{
|
2020-01-21 22:24:44 +01:00
|
|
|
static const WCHAR emulated[] = L" [Emulated]";
|
2012-09-16 20:24:10 +02:00
|
|
|
port_info * port;
|
|
|
|
ULONG nb_ports;
|
|
|
|
ULONG nb_midi_out;
|
|
|
|
ULONG nb_midi_in;
|
|
|
|
MIDIOUTCAPSW caps_out;
|
|
|
|
MIDIINCAPSW caps_in;
|
|
|
|
IDirectMusicSynth8* synth;
|
|
|
|
HRESULT hr;
|
2013-01-15 23:26:59 +01:00
|
|
|
ULONG i;
|
2012-09-16 20:24:10 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", object);
|
|
|
|
|
|
|
|
/* NOTE:
|
|
|
|
- it seems some native versions get the rest of devices through dmusic32.EnumLegacyDevices...*sigh*...which is undocumented
|
|
|
|
- should we enum wave devices ? Native does not seem to
|
|
|
|
*/
|
|
|
|
|
|
|
|
nb_midi_out = midiOutGetNumDevs();
|
|
|
|
nb_midi_in = midiInGetNumDevs();
|
|
|
|
nb_ports = 1 /* midi mapper */ + nb_midi_out + nb_midi_in + 1 /* synth port */;
|
|
|
|
|
|
|
|
port = object->system_ports = HeapAlloc(GetProcessHeap(), 0, nb_ports * sizeof(port_info));
|
|
|
|
if (!object->system_ports)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fill common port caps for all winmm ports */
|
|
|
|
for (i = 0; i < (nb_ports - 1 /* synth port*/); i++)
|
|
|
|
{
|
|
|
|
object->system_ports[i].caps.dwSize = sizeof(DMUS_PORTCAPS);
|
|
|
|
object->system_ports[i].caps.dwType = DMUS_PORT_WINMM_DRIVER;
|
|
|
|
object->system_ports[i].caps.dwMemorySize = 0;
|
|
|
|
object->system_ports[i].caps.dwMaxChannelGroups = 1;
|
|
|
|
object->system_ports[i].caps.dwMaxVoices = 0;
|
|
|
|
object->system_ports[i].caps.dwMaxAudioChannels = 0;
|
|
|
|
object->system_ports[i].caps.dwEffectFlags = DMUS_EFFECT_NONE;
|
|
|
|
/* Fake port GUID */
|
|
|
|
object->system_ports[i].caps.guidPort = IID_IUnknown;
|
|
|
|
object->system_ports[i].caps.guidPort.Data1 = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill midi mapper port info */
|
|
|
|
port->device = MIDI_MAPPER;
|
2017-05-10 14:44:01 +02:00
|
|
|
port->create = midi_out_port_create;
|
2012-09-16 20:24:10 +02:00
|
|
|
midiOutGetDevCapsW(MIDI_MAPPER, &caps_out, sizeof(caps_out));
|
2019-06-03 10:31:02 +02:00
|
|
|
lstrcpyW(port->caps.wszDescription, caps_out.szPname);
|
|
|
|
lstrcatW(port->caps.wszDescription, emulated);
|
2012-09-16 20:24:10 +02:00
|
|
|
port->caps.dwFlags = DMUS_PC_SHAREABLE;
|
|
|
|
port->caps.dwClass = DMUS_PC_OUTPUTCLASS;
|
|
|
|
port++;
|
|
|
|
|
|
|
|
/* Fill midi out port info */
|
|
|
|
for (i = 0; i < nb_midi_out; i++)
|
|
|
|
{
|
|
|
|
port->device = i;
|
2017-05-10 14:44:01 +02:00
|
|
|
port->create = midi_out_port_create;
|
2012-09-16 20:24:10 +02:00
|
|
|
midiOutGetDevCapsW(i, &caps_out, sizeof(caps_out));
|
2019-06-03 10:31:02 +02:00
|
|
|
lstrcpyW(port->caps.wszDescription, caps_out.szPname);
|
|
|
|
lstrcatW(port->caps.wszDescription, emulated);
|
2012-09-16 20:24:10 +02:00
|
|
|
port->caps.dwFlags = DMUS_PC_SHAREABLE | DMUS_PC_EXTERNAL;
|
|
|
|
port->caps.dwClass = DMUS_PC_OUTPUTCLASS;
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill midi in port info */
|
|
|
|
for (i = 0; i < nb_midi_in; i++)
|
|
|
|
{
|
|
|
|
port->device = i;
|
2017-05-10 14:44:01 +02:00
|
|
|
port->create = midi_in_port_create;
|
2012-09-16 20:24:10 +02:00
|
|
|
midiInGetDevCapsW(i, &caps_in, sizeof(caps_in));
|
2019-06-03 10:31:02 +02:00
|
|
|
lstrcpyW(port->caps.wszDescription, caps_in.szPname);
|
|
|
|
lstrcatW(port->caps.wszDescription, emulated);
|
2012-09-16 20:24:10 +02:00
|
|
|
port->caps.dwFlags = DMUS_PC_EXTERNAL;
|
|
|
|
port->caps.dwClass = DMUS_PC_INPUTCLASS;
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill synth port info */
|
2017-05-10 14:44:01 +02:00
|
|
|
port->create = synth_port_create;
|
2012-09-16 20:24:10 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2012-11-05 09:46:13 +01:00
|
|
|
port->caps.dwSize = sizeof(port->caps);
|
2012-09-16 20:24:10 +02:00
|
|
|
hr = IDirectMusicSynth8_GetPortCaps(synth, &port->caps);
|
|
|
|
IDirectMusicSynth8_Release(synth);
|
|
|
|
}
|
2012-09-28 08:59:36 +02:00
|
|
|
if (FAILED(hr))
|
2012-09-16 20:24:10 +02:00
|
|
|
nb_ports--;
|
|
|
|
|
2017-05-10 14:43:59 +02:00
|
|
|
object->num_system_ports = nb_ports;
|
2012-09-16 20:24:10 +02:00
|
|
|
}
|
|
|
|
|
2012-05-25 08:04:31 +02:00
|
|
|
/* For ClassFactory */
|
|
|
|
HRESULT WINAPI DMUSIC_CreateDirectMusicImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
|
|
|
|
{
|
|
|
|
IDirectMusic8Impl *dmusic;
|
|
|
|
HRESULT ret;
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2016-07-26 10:42:02 +02:00
|
|
|
TRACE("(%s, %p, %p)\n", debugstr_guid(riid), ret_iface, unkouter);
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2012-05-25 08:04:31 +02:00
|
|
|
*ret_iface = NULL;
|
2013-12-28 23:34:11 +01:00
|
|
|
if (unkouter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2012-05-25 08:04:31 +02:00
|
|
|
|
|
|
|
dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
|
|
|
|
if (!dmusic)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
dmusic->IDirectMusic8_iface.lpVtbl = &DirectMusic8_Vtbl;
|
2014-05-31 19:21:33 +02:00
|
|
|
dmusic->ref = 1;
|
2019-06-14 18:42:45 +02:00
|
|
|
ret = master_clock_create(&dmusic->master_clock);
|
2012-05-25 08:04:31 +02:00
|
|
|
if (FAILED(ret)) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmusic);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-16 20:24:10 +02:00
|
|
|
create_system_ports_list(dmusic);
|
|
|
|
|
2014-05-31 19:21:33 +02:00
|
|
|
DMUSIC_LockModule();
|
|
|
|
ret = IDirectMusic8Impl_QueryInterface(&dmusic->IDirectMusic8_iface, riid, ret_iface);
|
2016-08-31 22:52:01 +02:00
|
|
|
IDirectMusic8_Release(&dmusic->IDirectMusic8_iface);
|
2014-05-31 19:21:33 +02:00
|
|
|
|
|
|
|
return ret;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|