Update Music to use correct Resource API

This commit is contained in:
SweetId 2024-03-11 17:15:27 -04:00
parent cc91b8d3b9
commit cc2c36c75d
2 changed files with 31 additions and 16 deletions

View File

@ -25,6 +25,8 @@ namespace Nz
class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter
{ {
public: public:
using Params = SoundStreamParams;
Music(); Music();
Music(AudioDevice& device); Music(AudioDevice& device);
Music(const Music&) = delete; Music(const Music&) = delete;
@ -46,9 +48,9 @@ namespace Nz
bool IsLooping() const override; bool IsLooping() const override;
bool OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params = SoundStreamParams()); static std::shared_ptr<Music> OpenFromFile(const std::filesystem::path& filePath, const Params& params = Params());
bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams()); static std::shared_ptr<Music> OpenFromMemory(const void* data, std::size_t size, const Params& params = Params());
bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams()); static std::shared_ptr<Music> OpenFromStream(Stream& stream, const Params& params = Params());
void Pause() override; void Pause() override;
void Play() override; void Play() override;

View File

@ -240,12 +240,17 @@ namespace Nz
* \param filePath Path to the file * \param filePath Path to the file
* \param params Parameters for the music * \param params Parameters for the music
*/ */
bool Music::OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params) std::shared_ptr<Music> Music::OpenFromFile(const std::filesystem::path& filePath, const Params& params)
{ {
std::shared_ptr<Music> music = std::make_shared<Music>();
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromFile(filePath, params)) if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromFile(filePath, params))
return Create(std::move(soundStream)); {
else std::shared_ptr<Music> music = std::make_shared<Music>();
return false; if (music->Create(std::move(soundStream)))
return music;
}
return {};
} }
/*! /*!
@ -258,12 +263,16 @@ namespace Nz
* *
* \remark The memory pointer must stay valid (accessible) as long as the music is playing * \remark The memory pointer must stay valid (accessible) as long as the music is playing
*/ */
bool Music::OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params) std::shared_ptr<Music> Music::OpenFromMemory(const void* data, std::size_t size, const Params& params)
{ {
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromMemory(data, size, params)) if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromMemory(data, size, params))
return Create(std::move(soundStream)); {
else std::shared_ptr<Music> music = std::make_shared<Music>();
return false; if (music->Create(std::move(soundStream)))
return music;
}
return {};
} }
/*! /*!
@ -275,12 +284,16 @@ namespace Nz
* *
* \remark The stream must stay valid as long as the music is playing * \remark The stream must stay valid as long as the music is playing
*/ */
bool Music::OpenFromStream(Stream& stream, const SoundStreamParams& params) std::shared_ptr<Music> Music::OpenFromStream(Stream& stream, const Params& params)
{ {
if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromStream(stream, params)) if (std::shared_ptr<SoundStream> soundStream = SoundStream::OpenFromStream(stream, params))
return Create(std::move(soundStream)); {
else std::shared_ptr<Music> music = std::make_shared<Music>();
return false; if (music->Create(std::move(soundStream)))
return music;
}
return {};
} }
/*! /*!
@ -439,7 +452,7 @@ namespace Nz
break; // We have reached the end of the stream, there is no use to add new buffers break; // We have reached the end of the stream, there is no use to add new buffers
} }
} }
catch (const std::exception&) catch (const std::exception& e)
{ {
err = std::current_exception(); err = std::current_exception();