mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-01-19 16:00:51 +00:00
make dsound driver using the desktop window handle (#269)
* Dsound driver is now making use of an already existing window handle: the desktop window * Removing of fluid_dll.c because it has becoming useless * avoid a potential deadlock when calling functions within DllMain()
This commit is contained in:
parent
2aa612b764
commit
be6e1ab88a
3 changed files with 4 additions and 157 deletions
|
@ -76,7 +76,7 @@ if ( PORTAUDIO_SUPPORT )
|
||||||
endif ( PORTAUDIO_SUPPORT )
|
endif ( PORTAUDIO_SUPPORT )
|
||||||
|
|
||||||
if ( WINDOWS_SUPPORT )
|
if ( WINDOWS_SUPPORT )
|
||||||
set ( fluid_windows_SOURCES fluid_dll.c drivers/fluid_dsound.c drivers/fluid_winmidi.c )
|
set ( fluid_windows_SOURCES drivers/fluid_dsound.c drivers/fluid_winmidi.c )
|
||||||
endif ( WINDOWS_SUPPORT )
|
endif ( WINDOWS_SUPPORT )
|
||||||
|
|
||||||
if ( OSS_SUPPORT )
|
if ( OSS_SUPPORT )
|
||||||
|
|
|
@ -35,12 +35,8 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth);
|
||||||
void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* data);
|
void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* data);
|
||||||
DWORD WINAPI fluid_dsound_audio_run(LPVOID lpParameter);
|
DWORD WINAPI fluid_dsound_audio_run(LPVOID lpParameter);
|
||||||
|
|
||||||
HWND fluid_win32_get_window(void);
|
|
||||||
char* fluid_win32_error(HRESULT hr);
|
char* fluid_win32_error(HRESULT hr);
|
||||||
|
|
||||||
|
|
||||||
#define FLUID_HINSTANCE ((HINSTANCE)fluid_get_hinstance())
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
fluid_audio_driver_t driver;
|
fluid_audio_driver_t driver;
|
||||||
LPDIRECTSOUND direct_sound;
|
LPDIRECTSOUND direct_sound;
|
||||||
|
@ -110,20 +106,6 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
|
||||||
int periods, period_size;
|
int periods, period_size;
|
||||||
fluid_dsound_devsel_t devsel;
|
fluid_dsound_devsel_t devsel;
|
||||||
|
|
||||||
/* check if the globals are initialized */
|
|
||||||
if (FLUID_HINSTANCE == NULL) {
|
|
||||||
FLUID_LOG(FLUID_ERR, "FluidSynth hinstance not set, which is needed for DirectSound");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (fluid_wnd == NULL) {
|
|
||||||
if (fluid_win32_create_window() != 0) {
|
|
||||||
FLUID_LOG(FLUID_ERR, "Couldn't create window needed for DirectSound");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/* create and clear the driver data */
|
/* create and clear the driver data */
|
||||||
dev = FLUID_NEW(fluid_dsound_audio_driver_t);
|
dev = FLUID_NEW(fluid_dsound_audio_driver_t);
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
|
@ -131,7 +113,6 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
FLUID_MEMSET(dev, 0, sizeof(fluid_dsound_audio_driver_t));
|
FLUID_MEMSET(dev, 0, sizeof(fluid_dsound_audio_driver_t));
|
||||||
|
|
||||||
dev->synth = synth;
|
dev->synth = synth;
|
||||||
dev->cont = 1;
|
dev->cont = 1;
|
||||||
|
|
||||||
|
@ -183,7 +164,7 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
|
||||||
goto error_recovery;
|
goto error_recovery;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = IDirectSound_SetCooperativeLevel(dev->direct_sound, fluid_win32_get_window(), DSSCL_PRIORITY);
|
hr = IDirectSound_SetCooperativeLevel(dev->direct_sound, GetDesktopWindow(), DSSCL_PRIORITY);
|
||||||
if (hr != DS_OK) {
|
if (hr != DS_OK) {
|
||||||
FLUID_LOG(FLUID_ERR, "Failed to set the cooperative level");
|
FLUID_LOG(FLUID_ERR, "Failed to set the cooperative level");
|
||||||
goto error_recovery;
|
goto error_recovery;
|
||||||
|
@ -301,7 +282,6 @@ void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d)
|
||||||
if (dev->direct_sound != NULL) {
|
if (dev->direct_sound != NULL) {
|
||||||
IDirectSound_Release(dev->direct_sound);
|
IDirectSound_Release(dev->direct_sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUID_FREE(dev);
|
FLUID_FREE(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
133
src/fluid_dll.c
133
src/fluid_dll.c
|
@ -1,133 +0,0 @@
|
||||||
/* FluidSynth - A Software Synthesizer
|
|
||||||
*
|
|
||||||
* Copyright (C) 2003 Peter Hanappe and others.
|
|
||||||
*
|
|
||||||
* This library 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.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free
|
|
||||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include "fluidsynth_priv.h"
|
|
||||||
#include "fluid_sys.h"
|
|
||||||
|
|
||||||
static HINSTANCE fluid_hinstance = NULL;
|
|
||||||
static HWND fluid_wnd = NULL;
|
|
||||||
static int fluid_refCount = 0;
|
|
||||||
|
|
||||||
int fluid_win32_create_window(void);
|
|
||||||
void fluid_win32_destroy_window(void);
|
|
||||||
HWND fluid_win32_get_window(void);
|
|
||||||
|
|
||||||
#ifndef FLUIDSYNTH_NOT_A_DLL
|
|
||||||
BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
|
||||||
{
|
|
||||||
FLUID_LOG(FLUID_DBG, "DllMain");
|
|
||||||
switch (ul_reason_for_call) {
|
|
||||||
case DLL_PROCESS_ATTACH:
|
|
||||||
fluid_refCount++;
|
|
||||||
if (1 == fluid_refCount) {
|
|
||||||
fluid_set_hinstance((void*) hModule);
|
|
||||||
fluid_win32_create_window();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DLL_PROCESS_DETACH:
|
|
||||||
fluid_refCount--;
|
|
||||||
if (fluid_refCount == 0) {
|
|
||||||
fluid_win32_destroy_window();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the handle to the instance of the application on the Windows platform.
|
|
||||||
* @param Application instance pointer
|
|
||||||
*
|
|
||||||
* The handle is needed to open DirectSound.
|
|
||||||
*/
|
|
||||||
void fluid_set_hinstance(void* hinstance)
|
|
||||||
{
|
|
||||||
if (fluid_hinstance == NULL) {
|
|
||||||
fluid_hinstance = (HINSTANCE) hinstance;
|
|
||||||
FLUID_LOG(FLUID_DBG, "DLL instance = %d", (int) fluid_hinstance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the handle to the instance of the application on the Windows platform.
|
|
||||||
* @return Application instance pointer or NULL if not set
|
|
||||||
*/
|
|
||||||
void* fluid_get_hinstance(void)
|
|
||||||
{
|
|
||||||
return (void*) fluid_hinstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
static long FAR PASCAL fluid_win32_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
switch (message) {
|
|
||||||
case WM_CREATE:
|
|
||||||
break;
|
|
||||||
case WM_DESTROY:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return(0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
int fluid_win32_create_window(void)
|
|
||||||
{
|
|
||||||
WNDCLASS myClass;
|
|
||||||
myClass.hCursor = LoadCursor( NULL, IDC_ARROW );
|
|
||||||
myClass.hIcon = NULL;
|
|
||||||
myClass.lpszMenuName = (LPSTR) NULL;
|
|
||||||
myClass.lpszClassName = (LPSTR) "FluidSynth";
|
|
||||||
myClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
|
|
||||||
myClass.hInstance = fluid_hinstance;
|
|
||||||
myClass.style = CS_GLOBALCLASS;
|
|
||||||
myClass.lpfnWndProc = fluid_win32_wndproc;
|
|
||||||
myClass.cbClsExtra = 0;
|
|
||||||
myClass.cbWndExtra = 0;
|
|
||||||
if (!RegisterClass(&myClass)) {
|
|
||||||
return -100;
|
|
||||||
}
|
|
||||||
fluid_wnd = CreateWindow((LPSTR) "FluidSynth", (LPSTR) "FluidSynth", WS_OVERLAPPEDWINDOW,
|
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL,
|
|
||||||
fluid_hinstance, (LPSTR) NULL);
|
|
||||||
if (fluid_wnd == NULL) {
|
|
||||||
FLUID_LOG(FLUID_ERR, "Can't create window");
|
|
||||||
return -101;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fluid_win32_destroy_window(void)
|
|
||||||
{
|
|
||||||
HWND hwnd = fluid_win32_get_window();
|
|
||||||
if (hwnd) {
|
|
||||||
DestroyWindow(hwnd);
|
|
||||||
fluid_wnd = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND fluid_win32_get_window(void)
|
|
||||||
{
|
|
||||||
return fluid_wnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // #ifdef WIN32
|
|
Loading…
Reference in a new issue