From dd88ab208c96abb29dd10a8703772073434637d1 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 3 Sep 2016 10:03:33 +0200 Subject: [PATCH] Changed: Get length of song in FMod driver too (issue #59) --- code/nel/include/nel/sound/driver/sound_driver.h | 2 +- code/nel/src/sound/audio_mixer_user.cpp | 2 +- code/nel/src/sound/driver/dsound/sound_driver_dsound.h | 2 +- code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp | 4 +++- code/nel/src/sound/driver/fmod/sound_driver_fmod.h | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/nel/include/nel/sound/driver/sound_driver.h b/code/nel/include/nel/sound/driver/sound_driver.h index b5549e5bf..e38126fff 100644 --- a/code/nel/include/nel/sound/driver/sound_driver.h +++ b/code/nel/include/nel/sound/driver/sound_driver.h @@ -192,7 +192,7 @@ public: * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ - virtual bool getMusicInfo(const std::string &/* filepath */, std::string &artist, std::string &title) { artist.clear(); title.clear(); return false; } + virtual bool getMusicInfo(const std::string &/* filepath */, std::string &artist, std::string &title, float &length) { artist.clear(); title.clear(); length = 0.f; return false; } /// Get audio/container extensions that are supported natively by the driver implementation. virtual void getMusicExtensions(std::vector &extensions) const = 0; /// Return if a music extension is supported by the driver's music channel. diff --git a/code/nel/src/sound/audio_mixer_user.cpp b/code/nel/src/sound/audio_mixer_user.cpp index 96cfdf268..6f2c2b449 100644 --- a/code/nel/src/sound/audio_mixer_user.cpp +++ b/code/nel/src/sound/audio_mixer_user.cpp @@ -2691,7 +2691,7 @@ bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &res std::string artist; std::string title; - if (!_SoundDriver->getMusicInfo(filename, artist, title)) + if (!_SoundDriver->getMusicInfo(filename, artist, title, length)) { // use 3rd party libraries supported formats IAudioDecoder::getInfo(filename, artist, title, length); diff --git a/code/nel/src/sound/driver/dsound/sound_driver_dsound.h b/code/nel/src/sound/driver/dsound/sound_driver_dsound.h index 14872c1e1..e928cf137 100644 --- a/code/nel/src/sound/driver/dsound/sound_driver_dsound.h +++ b/code/nel/src/sound/driver/dsound/sound_driver_dsound.h @@ -115,7 +115,7 @@ public: * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ - virtual bool getMusicInfo(const std::string & /* filepath */, std::string &artist, std::string &title) { artist.clear(); title.clear(); return false; } + virtual bool getMusicInfo(const std::string & /* filepath */, std::string &artist, std::string &title, float &length) { artist.clear(); title.clear(); length = 0.f; return false; } private: diff --git a/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp b/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp index 6ca480ce7..07455b963 100644 --- a/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp +++ b/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp @@ -496,7 +496,7 @@ bool getTag (std::string &result, const char *tag, FSOUND_STREAM *stream) * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ -bool CSoundDriverFMod::getMusicInfo(const std::string &filepath, std::string &artist, std::string &title) +bool CSoundDriverFMod::getMusicInfo(const std::string &filepath, std::string &artist, std::string &title, float &length) { /* Open a stream, get the tag if it exists, close the stream */ string pathName = CPath::lookup(filepath, false); @@ -526,6 +526,8 @@ bool CSoundDriverFMod::getMusicInfo(const std::string &filepath, std::string &ar { getTag(artist, "ARTIST", stream); getTag(title, "TITLE", stream); + // get length of the music in seconds + length = (float)FSOUND_Stream_GetLengthMs(stream) / 1000.f; FSOUND_Stream_Close(stream); return true; } diff --git a/code/nel/src/sound/driver/fmod/sound_driver_fmod.h b/code/nel/src/sound/driver/fmod/sound_driver_fmod.h index 8beabe562..db82cde6e 100644 --- a/code/nel/src/sound/driver/fmod/sound_driver_fmod.h +++ b/code/nel/src/sound/driver/fmod/sound_driver_fmod.h @@ -116,7 +116,7 @@ public: * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ - virtual bool getMusicInfo(const std::string &filepath, std::string &artist, std::string &title); + virtual bool getMusicInfo(const std::string &filepath, std::string &artist, std::string &title, float &length); // also check that the channel still exist (avoid any free problem) void markMusicChannelEnded(void *stream, CMusicChannelFMod *musicChannel);