shithub: choc

Download patch

ref: bc9e801e9b968df968c93252f34fa658c8f4711b
parent: f8ee575d83b1824ef752a1f4ade4171e43af68ea
author: Roman Fomin <rfomin@gmail.com>
date: Sun Dec 12 08:24:28 EST 2021

win midi: Update the volume when the song starts playing to fix some silent MIDIs

--- a/src/i_winmusic.c
+++ b/src/i_winmusic.c
@@ -338,6 +338,24 @@
     }
 }
 
+static void UpdateVolume(void)
+{
+    int i;
+
+    // Send MIDI controller events to adjust the volume.
+    for (i = 0; i < MIDI_CHANNELS_PER_TRACK; ++i)
+    {
+        DWORD msg = 0;
+
+        int value = channel_volume[i] * volume_factor;
+
+        msg = MIDI_EVENT_CONTROLLER | i | (MIDI_CONTROLLER_MAIN_VOLUME << 8) |
+              (value << 16);
+
+        midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+    }
+}
+
 boolean I_WIN_InitMusic(void)
 {
     UINT MidiDevice = MIDI_MAPPER;
@@ -374,24 +392,9 @@
 
 void I_WIN_SetMusicVolume(int volume)
 {
-    int i;
-
     volume_factor = (float)volume / 127;
 
-    // Send MIDI controller events to adjust the volume.
-    for (i = 0; i < MIDI_CHANNELS_PER_TRACK; ++i)
-    {
-        DWORD msg = 0;
-
-        int value = channel_volume[i] * volume_factor;
-
-        value = volume_correction[value];
-
-        msg = MIDI_EVENT_CONTROLLER | i | (MIDI_CONTROLLER_MAIN_VOLUME << 8) |
-              (value << 16);
-
-        midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
-    }
+    UpdateVolume();
 }
 
 void I_WIN_StopSong(void)
@@ -458,6 +461,8 @@
     {
         MidiErrorMessageBox(mmr);
     }
+
+    UpdateVolume();
 }
 
 boolean I_WIN_RegisterSong(char *filename)