mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-30 07:35:59 +00:00
Changed: Also return song length with title
This commit is contained in:
parent
6487bc4dd9
commit
f3ea058c80
7 changed files with 11 additions and 9 deletions
|
@ -67,7 +67,7 @@ public:
|
||||||
static IAudioDecoder *createAudioDecoder(const std::string &type, NLMISC::IStream *stream, bool loop);
|
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).
|
/// 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.
|
/// Get audio/container extensions that are currently supported by the nel sound library.
|
||||||
static void getMusicExtensions(std::vector<std::string> &extensions);
|
static void getMusicExtensions(std::vector<std::string> &extensions);
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
inline sint32 getStreamOffset() { return _StreamOffset; }
|
inline sint32 getStreamOffset() { return _StreamOffset; }
|
||||||
|
|
||||||
/// Get information on a music file (only artist and title at the moment).
|
/// 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.
|
/// Get how many bytes the music buffer requires for output minimum.
|
||||||
virtual uint32 getRequiredBytes();
|
virtual uint32 getRequiredBytes();
|
||||||
|
|
|
@ -332,7 +332,7 @@ public:
|
||||||
virtual bool isMusicEnded();
|
virtual bool isMusicEnded();
|
||||||
virtual void setMusicVolume(float gain);
|
virtual void setMusicVolume(float gain);
|
||||||
virtual float getMusicLength();
|
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 enableBackgroundMusic(bool enable);
|
||||||
virtual void enableBackgroundMusicTimeConstraint(bool enable);
|
virtual void enableBackgroundMusicTimeConstraint(bool enable);
|
||||||
CMusicSoundManager *getBackgroundMusicManager() const {return _BackgroundMusicManager;}
|
CMusicSoundManager *getBackgroundMusicManager() const {return _BackgroundMusicManager;}
|
||||||
|
|
|
@ -432,7 +432,7 @@ public:
|
||||||
/** Get the song title. Returns false if the song is not found or the function is not implemented.
|
/** 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.
|
* 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
|
/** 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;
|
virtual void enableBackgroundMusic(bool enable) =0;
|
||||||
|
|
|
@ -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);
|
std::string lookup = CPath::lookup(filepath, false);
|
||||||
if (lookup.empty())
|
if (lookup.empty())
|
||||||
|
@ -111,7 +111,7 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st
|
||||||
ifile.setCacheFileOnOpen(false);
|
ifile.setCacheFileOnOpen(false);
|
||||||
ifile.allowBNPCacheFileOnOpen(false);
|
ifile.allowBNPCacheFileOnOpen(false);
|
||||||
if (ifile.open(lookup))
|
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());
|
nlwarning("Unable to open: '%s'", filepath.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ CAudioDecoderVorbis::~CAudioDecoderVorbis()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get information on a music file (only artist and title at the moment).
|
/// 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 :)
|
CAudioDecoderVorbis mbv(stream, false); // just opens and closes the oggvorbisfile thing :)
|
||||||
vorbis_comment *vc = ov_comment(&mbv._OggVorbisFile, -1);
|
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();
|
if (title_c) title = title_c; else title.clear();
|
||||||
char *artist_c = vorbis_comment_query(vc, "artist", 0);
|
char *artist_c = vorbis_comment_query(vc, "artist", 0);
|
||||||
if (artist_c) artist = artist_c; else artist.clear();
|
if (artist_c) artist = artist_c; else artist.clear();
|
||||||
|
length = (float)ov_time_total(&mbv._OggVorbisFile, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
if (_SoundDriver)
|
||||||
{
|
{
|
||||||
|
@ -2694,7 +2694,7 @@ bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &res
|
||||||
if (!_SoundDriver->getMusicInfo(filename, artist, title))
|
if (!_SoundDriver->getMusicInfo(filename, artist, title))
|
||||||
{
|
{
|
||||||
// use 3rd party libraries supported formats
|
// use 3rd party libraries supported formats
|
||||||
IAudioDecoder::getInfo(filename, artist, title);
|
IAudioDecoder::getInfo(filename, artist, title, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!title.empty())
|
if (!title.empty())
|
||||||
|
@ -2715,6 +2715,7 @@ bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &res
|
||||||
}
|
}
|
||||||
|
|
||||||
result = "???";
|
result = "???";
|
||||||
|
length = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue