winmidi: Sync with Chocolate Doom (#1060)

* Clean up `SendNullRPN()`

* Use GM as default case

* Use explicit casting for `MAKE_EVT` macro

* Limit max channel volume

* Rename `ConvertWideToUtf8()` to `M_ConvertWideToUtf8()`

Maintain consistency with other `M_*` functions.
This commit is contained in:
ceski 2023-05-17 11:18:02 -07:00 committed by GitHub
parent feb602580e
commit fb03087079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 15 deletions

View File

@ -143,7 +143,8 @@ static buffer_t buffer;
#define STREAM_MAX_EVENTS 4
#define MAKE_EVT(a, b, c, d) ((DWORD)((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)))
#define MAKE_EVT(a, b, c, d) \
((DWORD)(a) | ((DWORD)(b) << 8) | ((DWORD)(c) << 16) | ((DWORD)(d) << 24))
#define PADDED_SIZE(x) (((x) + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1))
@ -159,7 +160,7 @@ static void MidiError(const char *prefix, DWORD dwError)
mmr = midiOutGetErrorTextW(dwError, (LPWSTR)werror, MAXERRORLENGTH);
if (mmr == MMSYSERR_NOERROR)
{
char *error = ConvertWideToUtf8(werror);
char *error = M_ConvertWideToUtf8(werror);
fprintf(stderr, "%s: %s.\n", prefix, error);
free(error);
}
@ -271,8 +272,9 @@ static void SendLongMsg(unsigned int delta_time, const byte *ptr,
WriteBufferPad();
}
static void SendNullRPN(unsigned int delta_time, byte channel)
static void SendNullRPN(unsigned int delta_time, const midi_event_t *event)
{
const byte channel = event->data.channel.channel;
SendShortMsg(delta_time, MIDI_EVENT_CONTROLLER, channel,
MIDI_CONTROLLER_RPN_LSB, MIDI_RPN_NULL);
SendShortMsg(0, MIDI_EVENT_CONTROLLER, channel,
@ -311,9 +313,18 @@ static void UpdateTempo(unsigned int delta_time, const midi_event_t *event)
static void SendManualVolumeMsg(unsigned int delta_time, byte channel,
byte volume)
{
const byte scaled_volume = (byte)(volume * volume_factor + 0.5f) & 0x7F;
unsigned int scaled_volume;
scaled_volume = volume * volume_factor + 0.5f;
if (scaled_volume > 127)
{
scaled_volume = 127;
}
SendShortMsg(delta_time, MIDI_EVENT_CONTROLLER, channel,
MIDI_CONTROLLER_VOLUME_MSB, scaled_volume);
channel_volume[channel] = volume;
}
@ -400,10 +411,6 @@ static void ResetDevice(void)
ResetControllers();
break;
case RESET_TYPE_GM:
SendLongMsg(0, gm_system_on, sizeof(gm_system_on));
break;
case RESET_TYPE_GS:
SendLongMsg(0, gs_reset, sizeof(gs_reset));
use_fallback = (winmm_complevel != COMP_VANILLA);
@ -412,6 +419,10 @@ static void ResetDevice(void)
case RESET_TYPE_XG:
SendLongMsg(0, xg_system_on, sizeof(xg_system_on));
break;
default:
SendLongMsg(0, gm_system_on, sizeof(gm_system_on));
break;
}
// MS GS Wavetable Synth doesn't reset pitch bend sensitivity.
@ -993,7 +1004,7 @@ static boolean AddToBuffer_Standard(unsigned int delta_time,
else
{
// MS GS Wavetable Synth nulls RPN for any NRPN.
SendNullRPN(delta_time, event->data.channel.channel);
SendNullRPN(delta_time, event);
}
break;
@ -1015,7 +1026,7 @@ static boolean AddToBuffer_Standard(unsigned int delta_time,
else
{
// MS GS Wavetable Synth ignores other RPNs.
SendNullRPN(delta_time, event->data.channel.channel);
SendNullRPN(delta_time, event);
}
break;
}
@ -1037,7 +1048,7 @@ static boolean AddToBuffer_Standard(unsigned int delta_time,
else
{
// MS GS Wavetable Synth ignores other RPNs.
SendNullRPN(delta_time, event->data.channel.channel);
SendNullRPN(delta_time, event);
}
break;
}

View File

@ -107,7 +107,7 @@ static wchar_t *ConvertUtf8ToWide(const char *str)
return ConvertMultiByteToWide(str, CP_UTF8);
}
char *ConvertWideToUtf8(const wchar_t *wstr)
char *M_ConvertWideToUtf8(const wchar_t *wstr)
{
return ConvertWideToMultiByte(wstr, CP_UTF8);
}
@ -136,7 +136,7 @@ char *M_ConvertSysNativeMBToUtf8(const char *str)
return NULL;
}
ret = ConvertWideToUtf8(wstr);
ret = M_ConvertWideToUtf8(wstr);
free(wstr);
@ -413,7 +413,7 @@ char *M_getenv(const char *name)
if (wenv)
{
env = ConvertWideToUtf8(wenv);
env = M_ConvertWideToUtf8(wenv);
}
else
{

View File

@ -50,7 +50,7 @@ void M_MakeDirectory(const char *dir);
char *M_getenv(const char *name);
#ifdef _WIN32
char *ConvertWideToUtf8(const wchar_t *wstr);
char *M_ConvertWideToUtf8(const wchar_t *wstr);
#endif
char *M_ConvertSysNativeMBToUtf8(const char *str);