From d692834d07c70aafd856247e17a8b75bafd8e783 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 25 Sep 2003 00:34:01 +0000 Subject: [PATCH] Make GetLength and GetLength_Fast really const --- stepmania/src/RageSoundReader_MP3.cpp | 19 ++++++++++++------- stepmania/src/RageSoundReader_MP3.h | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index 5ca8ddebf4..053fd9e9a4 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -904,12 +904,8 @@ int RageSoundReader_MP3::SetPosition_Fast( int ms ) return SetPosition_estimate( ms ); } -/* XXX: This should be const, but there doesn't appear to be a way to copy MAD's - * internal structures, so we can scan length without moving the stream around. */ int RageSoundReader_MP3::GetLengthInternal( bool fast ) { - int ret; - if( mad->has_xing && mad->length != -1 ) return mad->length; /* should be accurate */ @@ -947,10 +943,19 @@ int RageSoundReader_MP3::GetLengthInternal( bool fast ) } /* Count milliseconds. */ - ret = mad_timer_count( mad->Timer, MAD_UNITS_MILLISECONDS ); + return mad_timer_count( mad->Timer, MAD_UNITS_MILLISECONDS ); +} - MADLIB_rewind(); - return ret; +int RageSoundReader_MP3::GetLengthConst( bool fast ) const +{ + RageSoundReader_MP3 *cpy = new RageSoundReader_MP3; + SoundReader_FileReader::OpenResult ret = cpy->Open( filename ); + ASSERT( ret == OPEN_OK ); + + int length = cpy->GetLengthInternal( fast ); + + delete cpy; + return length; } SoundReader *RageSoundReader_MP3::Copy() const diff --git a/stepmania/src/RageSoundReader_MP3.h b/stepmania/src/RageSoundReader_MP3.h index 150ad4e82b..7ca51d9597 100644 --- a/stepmania/src/RageSoundReader_MP3.h +++ b/stepmania/src/RageSoundReader_MP3.h @@ -29,12 +29,13 @@ public: int seek_stream_to_byte( int byte ); int handle_first_frame(); int GetLengthInternal( bool fast ); + int GetLengthConst( bool fast ) const; public: OpenResult Open(CString filename); void Close(); - int GetLength() const { return ((RageSoundReader_MP3*)this)->GetLengthInternal(false); } - int GetLength_Fast() const { return ((RageSoundReader_MP3*)this)->GetLengthInternal(true); } + int GetLength() const { return GetLengthConst(false); } + int GetLength_Fast() const { return GetLengthConst(true); } int SetPosition_Accurate(int ms); int SetPosition_Fast(int ms); int Read(char *buf, unsigned len);