From 848374b5efe6641abf43cf042420b52e083115e3 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 30 Aug 2016 21:25:46 +0300 Subject: [PATCH] Changed: Also return song length with title --- code/nel/include/nel/sound/audio_decoder.h | 2 +- code/nel/include/nel/sound/audio_decoder_vorbis.h | 2 +- code/nel/include/nel/sound/audio_mixer_user.h | 2 +- code/nel/include/nel/sound/u_audio_mixer.h | 2 +- code/nel/src/sound/audio_decoder.cpp | 4 ++-- code/nel/src/sound/audio_decoder_vorbis.cpp | 3 ++- code/nel/src/sound/audio_mixer_user.cpp | 5 +++-- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/code/nel/include/nel/sound/audio_decoder.h b/code/nel/include/nel/sound/audio_decoder.h index f7ae5ab31..f1dfdfc2c 100644 --- a/code/nel/include/nel/sound/audio_decoder.h +++ b/code/nel/include/nel/sound/audio_decoder.h @@ -67,7 +67,7 @@ public: static IAudioDecoder *createAudioDecoder(const std::string &type, NLMISC::IStream *stream, bool loop); /// Get information on a music file (only artist and title at the moment). - static bool getInfo(const std::string &filepath, std::string &artist, std::string &title); + static bool getInfo(const std::string &filepath, std::string &artist, std::string &title, float &length); /// Get audio/container extensions that are currently supported by the nel sound library. static void getMusicExtensions(std::vector &extensions); diff --git a/code/nel/include/nel/sound/audio_decoder_vorbis.h b/code/nel/include/nel/sound/audio_decoder_vorbis.h index 19d058d4a..4efcba255 100644 --- a/code/nel/include/nel/sound/audio_decoder_vorbis.h +++ b/code/nel/include/nel/sound/audio_decoder_vorbis.h @@ -77,7 +77,7 @@ public: inline sint32 getStreamOffset() { return _StreamOffset; } /// Get information on a music file (only artist and title at the moment). - static bool getInfo(NLMISC::IStream *stream, std::string &artist, std::string &title); + static bool getInfo(NLMISC::IStream *stream, std::string &artist, std::string &title, float &length); /// Get how many bytes the music buffer requires for output minimum. virtual uint32 getRequiredBytes(); diff --git a/code/nel/include/nel/sound/audio_mixer_user.h b/code/nel/include/nel/sound/audio_mixer_user.h index d8949c3d3..4163bf616 100644 --- a/code/nel/include/nel/sound/audio_mixer_user.h +++ b/code/nel/include/nel/sound/audio_mixer_user.h @@ -332,7 +332,7 @@ public: virtual bool isMusicEnded(); virtual void setMusicVolume(float gain); virtual float getMusicLength(); - virtual bool getSongTitle(const std::string &filename, std::string &result); + virtual bool getSongTitle(const std::string &filename, std::string &result, float &length); virtual void enableBackgroundMusic(bool enable); virtual void enableBackgroundMusicTimeConstraint(bool enable); CMusicSoundManager *getBackgroundMusicManager() const {return _BackgroundMusicManager;} diff --git a/code/nel/include/nel/sound/u_audio_mixer.h b/code/nel/include/nel/sound/u_audio_mixer.h index 0d845f9c3..c3059152c 100644 --- a/code/nel/include/nel/sound/u_audio_mixer.h +++ b/code/nel/include/nel/sound/u_audio_mixer.h @@ -432,7 +432,7 @@ public: /** Get the song title. Returns false if the song is not found or the function is not implemented. * If the song as no name, result is filled with the filename. */ - virtual bool getSongTitle(const std::string &filename, std::string &result) =0; + virtual bool getSongTitle(const std::string &filename, std::string &result, float &length) =0; /** enable or disable the background music system. disable it when you want to play your own mp3 for instance */ virtual void enableBackgroundMusic(bool enable) =0; diff --git a/code/nel/src/sound/audio_decoder.cpp b/code/nel/src/sound/audio_decoder.cpp index f4884a427..6e9e42b61 100644 --- a/code/nel/src/sound/audio_decoder.cpp +++ b/code/nel/src/sound/audio_decoder.cpp @@ -94,7 +94,7 @@ IAudioDecoder *IAudioDecoder::createAudioDecoder(const std::string &type, NLMISC } } -bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, std::string &title) +bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, std::string &title, float &length) { std::string lookup = CPath::lookup(filepath, false); if (lookup.empty()) @@ -111,7 +111,7 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st ifile.setCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false); if (ifile.open(lookup)) - return CAudioDecoderVorbis::getInfo(&ifile, artist, title); + return CAudioDecoderVorbis::getInfo(&ifile, artist, title, length); nlwarning("Unable to open: '%s'", filepath.c_str()); } diff --git a/code/nel/src/sound/audio_decoder_vorbis.cpp b/code/nel/src/sound/audio_decoder_vorbis.cpp index 1c11c32d7..fdda6e742 100644 --- a/code/nel/src/sound/audio_decoder_vorbis.cpp +++ b/code/nel/src/sound/audio_decoder_vorbis.cpp @@ -117,7 +117,7 @@ CAudioDecoderVorbis::~CAudioDecoderVorbis() } /// Get information on a music file (only artist and title at the moment). -bool CAudioDecoderVorbis::getInfo(NLMISC::IStream *stream, std::string &artist, std::string &title) +bool CAudioDecoderVorbis::getInfo(NLMISC::IStream *stream, std::string &artist, std::string &title, float &length) { CAudioDecoderVorbis mbv(stream, false); // just opens and closes the oggvorbisfile thing :) vorbis_comment *vc = ov_comment(&mbv._OggVorbisFile, -1); @@ -125,6 +125,7 @@ bool CAudioDecoderVorbis::getInfo(NLMISC::IStream *stream, std::string &artist, if (title_c) title = title_c; else title.clear(); char *artist_c = vorbis_comment_query(vc, "artist", 0); if (artist_c) artist = artist_c; else artist.clear(); + length = (float)ov_time_total(&mbv._OggVorbisFile, -1); return true; } diff --git a/code/nel/src/sound/audio_mixer_user.cpp b/code/nel/src/sound/audio_mixer_user.cpp index 9ac90b3c7..96cfdf268 100644 --- a/code/nel/src/sound/audio_mixer_user.cpp +++ b/code/nel/src/sound/audio_mixer_user.cpp @@ -2684,7 +2684,7 @@ float CAudioMixerUser::getMusicLength() } // *************************************************************************** -bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &result) +bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &result, float &length) { if (_SoundDriver) { @@ -2694,7 +2694,7 @@ bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &res if (!_SoundDriver->getMusicInfo(filename, artist, title)) { // use 3rd party libraries supported formats - IAudioDecoder::getInfo(filename, artist, title); + IAudioDecoder::getInfo(filename, artist, title, length); } if (!title.empty()) @@ -2715,6 +2715,7 @@ bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &res } result = "???"; + length = 0; return false; }