From: <sv...@op...> - 2024-03-05 19:27:01
|
Author: sagamusix Date: Tue Mar 5 20:26:54 2024 New Revision: 20254 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20254 Log: Merged revision(s) 20253 from trunk/OpenMPT: [Fix] xmp-openmpt: Song metadata retrieval was completely broken for playlist entries. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/libopenmpt/xmp-openmpt/xmp-openmpt.cpp Modified: branches/OpenMPT-1.31/libopenmpt/xmp-openmpt/xmp-openmpt.cpp ============================================================================== --- branches/OpenMPT-1.31/libopenmpt/xmp-openmpt/xmp-openmpt.cpp Tue Mar 5 20:25:55 2024 (r20253) +++ branches/OpenMPT-1.31/libopenmpt/xmp-openmpt/xmp-openmpt.cpp Tue Mar 5 20:26:54 2024 (r20254) @@ -731,17 +731,38 @@ return result; } -static float * build_xmplay_length( const openmpt::module & /* mod */ ) { - float * result = static_cast<float*>( xmpfmisc->Alloc( sizeof( float ) * self->subsong_lengths.size() ) ); +static std::vector<double> build_subsong_lengths( openmpt::module & mod ) { + std::int32_t num_subsongs = mod.get_num_subsongs(); + std::vector<double> subsong_lengths( num_subsongs ); + for ( std::int32_t i = 0; i < num_subsongs; ++i ) { + mod.select_subsong( i ); + subsong_lengths[i] = mod.get_duration_seconds(); + } + return subsong_lengths; +} + +static float * build_xmplay_length( openmpt::module & mod ) { + const auto subsong_lengths = build_subsong_lengths( mod ); + float * result = static_cast<float*>( xmpfmisc->Alloc( sizeof( float ) * subsong_lengths.size() ) ); if ( !result ) { return nullptr; } - for ( std::size_t i = 0; i < self->subsong_lengths.size(); ++i ) { - result[i] = static_cast<float>( self->subsong_lengths[i] ); + for ( std::size_t i = 0; i < subsong_lengths.size(); ++i ) { + result[i] = static_cast<float>( subsong_lengths[i] ); } return result; } +static DWORD build_xmplay_file_info( openmpt::module & mod, float ** length, char ** tags ) { + if ( length ) { + *length = build_xmplay_length( mod ); + } + if ( tags ) { + *tags = build_xmplay_tags( mod ); + } + return static_cast<DWORD>( mod.get_num_subsongs() ); +} + static void clear_xmplay_string( char * str ) { if ( !str ) { return; @@ -851,6 +872,7 @@ static DWORD WINAPI openmpt_GetFileInfo( const char * filename, XMPFILE file, float * * length, char * * tags ) { static_cast<void>( filename ); + DWORD subsongs = 0; try { std::map< std::string, std::string > ctls { @@ -863,12 +885,7 @@ case XMPFILE_TYPE_MEMORY: { openmpt::module mod( xmpffile->GetMemory( file ), xmpffile->GetSize( file ), std::clog, ctls ); - if ( length ) { - *length = build_xmplay_length( mod ); - } - if ( tags ) { - *tags = build_xmplay_tags( mod ); - } + subsongs = build_xmplay_file_info( mod, length, tags ); } break; case XMPFILE_TYPE_FILE: @@ -878,50 +895,30 @@ { xmplay_istream s( file ); openmpt::module mod( s, std::clog, ctls ); - if ( length ) { - *length = build_xmplay_length( mod ); - } - if ( tags ) { - *tags = build_xmplay_tags( mod ); - } + subsongs = build_xmplay_file_info( mod, length, tags ); } break; } #else if ( xmpffile->GetType( file ) == XMPFILE_TYPE_MEMORY ) { openmpt::module mod( xmpffile->GetMemory( file ), xmpffile->GetSize( file ), std::clog, ctls ); - if ( length ) { - *length = build_xmplay_length( mod ); - } - if ( tags ) { - *tags = build_xmplay_tags( mod ); - } + subsongs = build_xmplay_file_info( mod, length, tags ); } else { openmpt::module mod( read_XMPFILE_vector( file ), std::clog, ctls ); - if ( length ) { - *length = build_xmplay_length( mod ); - } - if ( tags ) { - *tags = build_xmplay_tags( mod ); - } + subsongs = build_xmplay_file_info( mod, length, tags ); } #endif #else std::ifstream s( filename, std::ios_base::binary ); openmpt::module mod( s, std::clog, ctls ); - if ( length ) { - *length = build_xmplay_length( mod ); - } - if ( tags ) { - *tags = build_xmplay_tags( mod ); - } - #endif + subsongs = build_xmplay_file_info( mod, length, tags ); +#endif } catch ( ... ) { if ( length ) *length = nullptr; if ( tags ) *tags = nullptr; return 0; } - return self->subsong_lengths.size() + XMPIN_INFO_NOSUBTAGS; + return subsongs; } // open a file for playback @@ -967,12 +964,7 @@ reset_timeinfos(); apply_options(); - std::int32_t num_subsongs = self->mod->get_num_subsongs(); - self->subsong_lengths.resize( num_subsongs ); - for ( std::int32_t i = 0; i < num_subsongs; ++i ) { - self->mod->select_subsong( i ); - self->subsong_lengths[i] = self->mod->get_duration_seconds(); - } + self->subsong_lengths = build_subsong_lengths( *self->mod ); self->subsong_names = self->mod->get_subsong_names(); self->mod->select_subsong( 0 ); self->tempo_factor = 0; |