-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MIDI mute improvements #2318
MIDI mute improvements #2318
Conversation
ca07728
to
65874f2
Compare
@johnnovak - great improvements and cleanup! Comment here is purely function testing. I'm using: [sdl]
mute_when_inactive = true
pause_when_inactive = false (I realize When I start a game, the DOSBox window opens up active however the music is muted. If I Alt+Tab to send the window to the background then the music starts playing (maybe default state is just flipped?). If I do the same test (start a game, the DOSBox window in foreground) but instead of Alt+Tab, I press Ctrl+F8 to switch "mute on", then the log shows If you can try
|
65874f2
to
70288bf
Compare
Yep, my bad; I flipped But this is a regression actually, so just pushed a fix. |
...and thanks for testing it, @kcgen 👍🏻 |
(small tweak to commit wording.. |
556b5ca
to
f413d76
Compare
Done! Pushed a few more small and hopefully non-controversial cleanups. |
Retesting - 👍 Starts up playing now - so that's done! For the Ctrl+F8 manual control, that state is lost across the active/inactive window transition. Repro:
(No worries if the plan is to include that handling in the next round!) |
UBSAN also running clean. |
…ltSequence for now
f413d76
to
0644900
Compare
Thanks again, that was an oversight on my part. Now I understood why you needed I've reinstated the correct manual muting behaviour in my last commit. |
Confirmed and running nice. |
Currently, the when muting the audio, all MIDI devices are sent Note Off messages, which is problematic when long-held notes are used in a composition. E.g. load up Space Quest V and toggle mute every 1-2 seconds during the logo music, and then at the start of the intro and you'll hear what I mean (you'll get missing notes after unmuting; the slower the tempo of the music is, the more annoying this problem becomes...)
This is unnecessary for built-in MIDI synthesizers, and not ideal for external devices. For internal synths, we don't need to send note offs at all; it's better to keep feeding them MIDI data and simply let the mixer handle the muting.
For external devices, we need to be a bit more clever. Instead of sending Note Offs and stopping sending the MIDI data, we keep sending the data and perform MIDI muting by setting all 16 MIDI channel volumes to zero, then unmute by restoring their current volume level. Of course, to be able to restore the volumes we need to track Channel Volume Control Change messages in the new MidiState thingy I added in my recent PR. In my view, this is a rather neat solution because we continue feeding the external device with MIDI data so the "music keeps running" and we're literally just muting it! It's very similar to the situation when your CD player keeps playing and you only mute/unmute the amplifier, but don't mess about with the CD player!
The PR also contains tons of cleanup changes. Specifically, I found the API of the MIDI module a bit too abstract which made it difficult to control things precisely (e.g. different vaguely related but ultimately different things, such as stopping/restarting/muting/resetting/initialising, were conflated into the abstract
MIDI_HaltSequence
/MIDI_ResumeSequence
functions). I've also simplified the mixer's interface; the mixer's own internal state is no one else's business now, you can only instruct it to mute or unmute from the outside and that's it. Plus lots of other improvements, changes, fixes, etc... They all belong together, and I did not want to raise 10 small PRs...Every commit should be individually compilable and testable, and reviewing commit by commit should make the thought process behind these changes clear.
If you're wondering how these changes affect the pause function, well, it's badly broken in main currently in a variety of interesting ways anyway... My next PR will fix all that stuff up, and I will make further tweaks so pausing and muting work together correctly as they should.