Skip to content

Commit

Permalink
drivers: winmidi,waveout and dsound using utf8 options
Browse files Browse the repository at this point in the history
Unicode support enabled in CMake script and CLI utility
  • Loading branch information
pedrolcl committed May 1, 2024
1 parent 46c7659 commit e3534c8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ if ( WIN32 OR CYGWIN )
endif()
endif ()
message ( STATUS "Targeting Windows Version ${windows-version}" )
add_definitions ( -D _UNICODE -D UNICODE )
add_definitions ( -D _WIN32_WINNT=${windows-version} )
add_definitions ( -D WINVER=${windows-version} )
list ( APPEND CMAKE_REQUIRED_DEFINITIONS "-DWINVER=${windows-version}" )
Expand Down
31 changes: 25 additions & 6 deletions src/drivers/fluid_dsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,18 @@ typedef struct
BOOL CALLBACK
fluid_dsound_enum_callback(LPGUID guid, LPCTSTR description, LPCTSTR module, LPVOID context)
{
fluid_settings_t *settings = (fluid_settings_t *) context;
fluid_settings_add_option(settings, "audio.dsound.device", (const char *)description);
fluid_settings_t *settings = (fluid_settings_t *)context;
char *name;
#if _UNICODE
int nsz = WideCharToMultiByte(CP_UTF8, 0, description, -1, 0, 0, 0, 0);
name = FLUID_ARRAY(char, nsz + 1);
WideCharToMultiByte(CP_UTF8, 0, description, -1, name, nsz, 0, 0);
#else
name = FLUID_STRDUP(description);
#endif
FLUID_LOG(FLUID_DBG, "adding audio.dsound.device=%s", name);
fluid_settings_add_option(settings, "audio.dsound.device", name);
FLUID_FREE(name);

return TRUE;
}
Expand All @@ -121,10 +131,18 @@ fluid_dsound_enum_callback(LPGUID guid, LPCTSTR description, LPCTSTR module, LPV
BOOL CALLBACK
fluid_dsound_enum_callback2(LPGUID guid, LPCTSTR description, LPCTSTR module, LPVOID context)
{
fluid_dsound_devsel_t *devsel = (fluid_dsound_devsel_t *) context;
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", description);

if(FLUID_STRCASECMP(devsel->devname, description) == 0)
fluid_dsound_devsel_t *devsel = (fluid_dsound_devsel_t *)context;
char *name;
#if _UNICODE
int nsz = WideCharToMultiByte(CP_UTF8, 0, description, -1, 0, 0, 0, 0);
name = FLUID_ARRAY(char, nsz + 1);
WideCharToMultiByte(CP_UTF8, 0, description, -1, name, nsz, 0, 0);
#else
name = FLUID_STRDUP(description);
#endif
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", name);

if (FLUID_STRCASECMP(devsel->devname, name) == 0)
{
/* The device exists, return a copy of its GUID */
devsel->devGUID = FLUID_NEW(GUID);
Expand All @@ -137,6 +155,7 @@ fluid_dsound_enum_callback2(LPGUID guid, LPCTSTR description, LPCTSTR module, LP
return FALSE;
}
}
FLUID_FREE(name);

return TRUE;
}
Expand Down
16 changes: 8 additions & 8 deletions src/drivers/fluid_waveout.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ static DWORD WINAPI fluid_waveout_synth_thread(void *data)
void fluid_waveout_audio_driver_settings(fluid_settings_t *settings)
{
UINT n, nDevs = waveOutGetNumDevs();
#ifdef _UNICODE
char dev_name[MAXPNAMELEN];
#endif
char *dev_name;

fluid_settings_register_str(settings, "audio.waveout.device", "default", 0);
fluid_settings_add_option(settings, "audio.waveout.device", "default");
Expand All @@ -218,13 +216,15 @@ void fluid_waveout_audio_driver_settings(fluid_settings_t *settings)
if(res == MMSYSERR_NOERROR)
{
#ifdef _UNICODE
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, dev_name, MAXPNAMELEN, 0, 0);
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", dev_name);
fluid_settings_add_option(settings, "audio.waveout.device", dev_name);
int nsz = WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, 0, 0, 0, 0);
dev_name = FLUID_ARRAY(char, nsz + 1);
WideCharToMultiByte(CP_UTF8, 0, caps.szPname, -1, dev_name, nsz, 0, 0);
#else
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", caps.szPname);
fluid_settings_add_option(settings, "audio.waveout.device", caps.szPname);
dev_name = FLUID_STRDUP(caps.szPname);
#endif
FLUID_LOG(FLUID_DBG, "Testing audio device: %s", dev_name);
fluid_settings_add_option(settings, "audio.waveout.device", dev_name);
FLUID_FREE(dev_name);
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/drivers/fluid_winmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,24 @@ fluid_winmidi_callback(HMIDIIN hmi, UINT wMsg, DWORD_PTR dwInstance,
* @param dev_name, name of the device.
* @return the new device name (that must be freed when finish with it) or
* NULL if memory allocation error.
* Note: the returned name will be encoded in UTF8 if built with _UNICODE.
*/
static char *fluid_winmidi_get_device_name(int dev_idx, char *dev_name)
static char *fluid_winmidi_get_device_name(int dev_idx, TCHAR *input_dev_name)
{
char *new_dev_name;
char *dev_name;

int i = dev_idx;
size_t size = 0; /* index size */

#if _UNICODE
int nsz = WideCharToMultiByte(CP_UTF8, 0, input_dev_name, -1, 0, 0, 0, 0);
dev_name = FLUID_ARRAY(char, nsz + 1);
WideCharToMultiByte(CP_UTF8, 0, input_dev_name, -1, dev_name, nsz, 0, 0);
#else
dev_name = FLUID_STRDUP(input_dev_name);
#endif

do
{
size++;
Expand All @@ -256,6 +266,7 @@ static char *fluid_winmidi_get_device_name(int dev_idx, char *dev_name)
{
FLUID_LOG(FLUID_ERR, "Out of memory");
}
FLUID_FREE(dev_name);

return new_dev_name;
}
Expand Down Expand Up @@ -429,14 +440,7 @@ fluid_winmidi_parse_device_name(fluid_winmidi_driver_t *dev, char *dev_name)
break;
}

#ifdef _UNICODE
WCHAR wDevName[MAXPNAMELEN];
MultiByteToWideChar(CP_UTF8, 0, dev_name, -1, wDevName, MAXPNAMELEN);

str_cmp_res = wcsicmp(wDevName, new_dev_name);
#else
str_cmp_res = FLUID_STRCASECMP(dev_name, new_dev_name);
#endif

FLUID_LOG(FLUID_DBG, "Testing midi device \"%s\"", new_dev_name);
FLUID_FREE(new_dev_name);
Expand Down
5 changes: 4 additions & 1 deletion src/fluidsynth.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ int main(int argc, char **argv)
static const char optchars[] = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:QqR:r:sT:Vvz:";

#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8);
// console output will be utf-8
SetConsoleOutputCP(CP_UTF8);
// console input, too
SetConsoleCP(CP_UTF8);
#endif

#if SDL2_SUPPORT
Expand Down

0 comments on commit e3534c8

Please sign in to comment.