1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codechange: Auto-reformat fluidsynth.cpp.

This commit is contained in:
Peter Nelson
2025-12-08 21:45:53 +00:00
committed by Peter Nelson
parent 8e35553208
commit 2162983054

View File

@@ -8,21 +8,23 @@
/** @file fluidsynth.cpp Playing music via the fluidsynth library. */ /** @file fluidsynth.cpp Playing music via the fluidsynth library. */
#include "../stdafx.h" #include "../stdafx.h"
#include "../openttd.h"
#include "../sound_type.h"
#include "../debug.h"
#include "fluidsynth.h" #include "fluidsynth.h"
#include "midifile.hpp"
#include <fluidsynth.h> #include <fluidsynth.h>
#include "../mixer.h"
#include <mutex> #include <mutex>
#include "../debug.h"
#include "../mixer.h"
#include "midifile.hpp"
#include "../safeguards.h" #include "../safeguards.h"
static struct { static struct {
fluid_settings_t *settings; ///< FluidSynth settings handle fluid_settings_t *settings; ///< FluidSynth settings handle
fluid_synth_t *synth; ///< FluidSynth synthesizer handle fluid_synth_t *synth; ///< FluidSynth synthesizer handle
fluid_player_t *player; ///< FluidSynth MIDI player handle fluid_player_t *player; ///< FluidSynth MIDI player handle
std::mutex synth_mutex; ///< Guard mutex for synth access std::mutex synth_mutex; ///< Guard mutex for synth access
} _midi; ///< Metadata about the midi we're playing. } _midi; ///< Metadata about the midi we're playing.
/** Factory for the FluidSynth driver. */ /** Factory for the FluidSynth driver. */
@@ -53,7 +55,7 @@ static const char *default_sf[] = {
static void RenderMusicStream(int16_t *buffer, size_t samples) static void RenderMusicStream(int16_t *buffer, size_t samples)
{ {
std::unique_lock<std::mutex> lock{ _midi.synth_mutex, std::try_to_lock }; std::unique_lock<std::mutex> lock{_midi.synth_mutex, std::try_to_lock};
if (!lock.owns_lock() || _midi.synth == nullptr || _midi.player == nullptr) return; if (!lock.owns_lock() || _midi.synth == nullptr || _midi.player == nullptr) return;
fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2); fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2);
@@ -61,7 +63,7 @@ static void RenderMusicStream(int16_t *buffer, size_t samples)
std::optional<std::string_view> MusicDriver_FluidSynth::Start(const StringList &param) std::optional<std::string_view> MusicDriver_FluidSynth::Start(const StringList &param)
{ {
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
auto sfont_name = GetDriverParam(param, "soundfont"); auto sfont_name = GetDriverParam(param, "soundfont");
int sfont_id; int sfont_id;
@@ -119,7 +121,7 @@ void MusicDriver_FluidSynth::Stop()
{ {
MxSetMusicSource(nullptr); MxSetMusicSource(nullptr);
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
if (_midi.player != nullptr) delete_fluid_player(_midi.player); if (_midi.player != nullptr) delete_fluid_player(_midi.player);
_midi.player = nullptr; _midi.player = nullptr;
@@ -141,7 +143,7 @@ void MusicDriver_FluidSynth::PlaySong(const MusicSongInfo &song)
return; return;
} }
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
_midi.player = new_fluid_player(_midi.synth); _midi.player = new_fluid_player(_midi.synth);
if (_midi.player == nullptr) { if (_midi.player == nullptr) {
@@ -165,7 +167,7 @@ void MusicDriver_FluidSynth::PlaySong(const MusicSongInfo &song)
void MusicDriver_FluidSynth::StopSong() void MusicDriver_FluidSynth::StopSong()
{ {
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
if (_midi.player == nullptr) return; if (_midi.player == nullptr) return;
@@ -179,7 +181,7 @@ void MusicDriver_FluidSynth::StopSong()
bool MusicDriver_FluidSynth::IsSongPlaying() bool MusicDriver_FluidSynth::IsSongPlaying()
{ {
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
if (_midi.player == nullptr) return false; if (_midi.player == nullptr) return false;
return fluid_player_get_status(_midi.player) == FLUID_PLAYER_PLAYING; return fluid_player_get_status(_midi.player) == FLUID_PLAYER_PLAYING;
@@ -187,7 +189,7 @@ bool MusicDriver_FluidSynth::IsSongPlaying()
void MusicDriver_FluidSynth::SetVolume(uint8_t vol) void MusicDriver_FluidSynth::SetVolume(uint8_t vol)
{ {
std::lock_guard<std::mutex> lock{ _midi.synth_mutex }; std::lock_guard<std::mutex> lock{_midi.synth_mutex};
if (_midi.settings == nullptr) return; if (_midi.settings == nullptr) return;
/* Allowed range of synth.gain is 0.0 to 10.0 */ /* Allowed range of synth.gain is 0.0 to 10.0 */