Codechange: Pass std::string_view from drivers instead of char *.

This commit is contained in:
Peter Nelson
2024-04-09 02:47:14 +01:00
committed by Peter Nelson
parent a42aa1a086
commit 332cbca36e
52 changed files with 161 additions and 161 deletions

View File

@@ -26,7 +26,7 @@ static MIDI *_midi = nullptr;
*/
extern int _allegro_instance_count;
const char *MusicDriver_Allegro::Start(const StringList &)
std::optional<std::string_view> MusicDriver_Allegro::Start(const StringList &)
{
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
Debug(driver, 0, "allegro: install_allegro failed '{}'", allegro_error);
@@ -46,7 +46,7 @@ const char *MusicDriver_Allegro::Start(const StringList &)
return "No sound card found";
}
return nullptr;
return std::nullopt;
}
void MusicDriver_Allegro::Stop()

View File

@@ -15,7 +15,7 @@
/** Allegro's music player. */
class MusicDriver_Allegro : public MusicDriver {
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -26,7 +26,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "allegro"; }
std::string_view GetName() const override { return "allegro"; }
};
/** Factory for allegro's music player. */

View File

@@ -18,9 +18,9 @@
/** Factory for BeOS' midi player. */
static FMusicDriver_BeMidi iFMusicDriver_BeMidi;
const char *MusicDriver_BeMidi::Start(const StringList &parm)
std::optional<std::string_view> MusicDriver_BeMidi::Start(const StringList &parm)
{
return nullptr;
return std::nullopt;
}
void MusicDriver_BeMidi::Stop()

View File

@@ -18,7 +18,7 @@
/** The midi player for BeOS. */
class MusicDriver_BeMidi : public MusicDriver {
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -29,7 +29,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "bemidi"; }
std::string_view GetName() const override { return "bemidi"; }
private:
BMidiSynthFile *midi_synth_file = nullptr;

View File

@@ -79,11 +79,11 @@ static void DoSetVolume()
/**
* Initialized the MIDI player, including QuickTime initialization.
*/
const char *MusicDriver_Cocoa::Start(const StringList &)
std::optional<std::string_view> MusicDriver_Cocoa::Start(const StringList &)
{
if (NewMusicPlayer(&_player) != noErr) return "failed to create music player";
return nullptr;
return std::nullopt;
}

View File

@@ -14,7 +14,7 @@
class MusicDriver_Cocoa : public MusicDriver {
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -25,7 +25,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "cocoa"; }
std::string_view GetName() const override { return "cocoa"; }
};
class FMusicDriver_Cocoa : public DriverFactoryBase {

View File

@@ -1072,7 +1072,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
}
const char *MusicDriver_DMusic::Start(const StringList &parm)
std::optional<std::string_view> MusicDriver_DMusic::Start(const StringList &parm)
{
/* Initialize COM */
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) return "COM initialization failed";
@@ -1153,7 +1153,7 @@ const char *MusicDriver_DMusic::Start(const StringList &parm)
if (!StartNewThread(&_dmusic_thread, "ottd:dmusic", &MidiThreadProc)) return "Can't create MIDI output thread";
return nullptr;
return std::nullopt;
}

View File

@@ -17,7 +17,7 @@ class MusicDriver_DMusic : public MusicDriver {
public:
virtual ~MusicDriver_DMusic();
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -28,7 +28,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "dmusic"; }
std::string_view GetName() const override { return "dmusic"; }
};
/** Factory for the DirectX music player. */

View File

@@ -35,10 +35,10 @@
/** Factory for the midi player that uses external players. */
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
const char *MusicDriver_ExtMidi::Start(const StringList &parm)
std::optional<std::string_view> MusicDriver_ExtMidi::Start(const StringList &parm)
{
if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
if (VideoDriver::GetInstance()->GetName() == "allegro" ||
SoundDriver::GetInstance()->GetName() == "allegro") {
return "the extmidi driver does not work when Allegro is loaded.";
}
@@ -62,7 +62,7 @@ const char *MusicDriver_ExtMidi::Start(const StringList &parm)
this->song.clear();
this->pid = -1;
return nullptr;
return std::nullopt;
}
void MusicDriver_ExtMidi::Stop()

View File

@@ -22,7 +22,7 @@ private:
void DoStop();
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -33,7 +33,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "extmidi"; }
std::string_view GetName() const override { return "extmidi"; }
};
class FMusicDriver_ExtMidi : public DriverFactoryBase {

View File

@@ -58,7 +58,7 @@ static void RenderMusicStream(int16_t *buffer, size_t samples)
fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2);
}
const char *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 };
@@ -110,7 +110,7 @@ const char *MusicDriver_FluidSynth::Start(const StringList &param)
_midi.player = nullptr;
return nullptr;
return std::nullopt;
}
void MusicDriver_FluidSynth::Stop()

View File

@@ -15,7 +15,7 @@
/** Music driver making use of FluidSynth. */
class MusicDriver_FluidSynth : public MusicDriver {
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -26,7 +26,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "fluidsynth"; }
std::string_view GetName() const override { return "fluidsynth"; }
};
/** Factory for the fluidsynth driver. */

View File

@@ -15,7 +15,7 @@
/** The music player that does nothing. */
class MusicDriver_Null : public MusicDriver {
public:
const char *Start(const StringList &) override { return nullptr; }
std::optional<std::string_view> Start(const StringList &) override { return std::nullopt; }
void Stop() override { }
@@ -26,7 +26,7 @@ public:
bool IsSongPlaying() override { return true; }
void SetVolume(uint8_t) override { }
const char *GetName() const override { return "null"; }
std::string_view GetName() const override { return "null"; }
};
/** Factory for the null music player. */

View File

@@ -367,7 +367,7 @@ void MusicDriver_Win32::SetVolume(uint8_t vol)
_midi.new_volume = vol;
}
const char *MusicDriver_Win32::Start(const StringList &parm)
std::optional<std::string_view> MusicDriver_Win32::Start(const StringList &parm)
{
Debug(driver, 2, "Win32-MIDI: Start: initializing");
@@ -416,7 +416,7 @@ const char *MusicDriver_Win32::Start(const StringList &parm)
if (timeBeginPeriod(_midi.time_period) == MMSYSERR_NOERROR) {
/* success */
Debug(driver, 2, "Win32-MIDI: Start: timer resolution is {}", _midi.time_period);
return nullptr;
return std::nullopt;
}
}
midiOutClose(_midi.midi_out);

View File

@@ -15,7 +15,7 @@
/** The Windows music player. */
class MusicDriver_Win32 : public MusicDriver {
public:
const char *Start(const StringList &param) override;
std::optional<std::string_view> Start(const StringList &param) override;
void Stop() override;
@@ -26,7 +26,7 @@ public:
bool IsSongPlaying() override;
void SetVolume(uint8_t vol) override;
const char *GetName() const override { return "win32"; }
std::string_view GetName() const override { return "win32"; }
};
/** Factory for Windows' music player. */