diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index af7482aa2b..83f868cf5a 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -728,6 +728,9 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh /* We're using sections, so use the section name as the top-level sort. */ switch( so ) { + case SORT_GROUP: + SongUtil::SortSongPointerArrayByGroup(arraySongs); + break; case SORT_METER: case SORT_PREFERRED: case SORT_TOP_GRADES: @@ -799,7 +802,7 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh unsigned j; for( j=i; j < arraySongs.size(); j++ ) { - if( SongUtil::GetSectionNameFromSongAndSort( arraySongs[j], so ) != sThisSection ) + if( SONGMAN->GetGroup(arraySongs[j])->GetGroupName() != sThisSection ) break; } iSectionCount = j-i; diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index bf8b5221bc..aaea32d4e5 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -593,31 +593,48 @@ void SongUtil::SortSongPointerArrayByGenre( std::vector &vpSongsInOut ) stable_sort( vpSongsInOut.begin(), vpSongsInOut.end(), CompareSongPointersByGenre ); } +void SongUtil::SortSongPointerArrayByGroup( std::vector &vpSongsInOut ) +{ + stable_sort( vpSongsInOut.begin(), vpSongsInOut.end(), CompareSongPointersByGroup ); +} + int SongUtil::CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2) { - // Check if the sort title exists - if( SONGMAN->GetGroup(pSong1)->GetSortTitle().empty() || SONGMAN->GetGroup(pSong2)->GetSortTitle().empty() ) { + + RString s1 = SONGMAN->GetGroup(pSong1)->GetSortTitle(); + RString s2 = SONGMAN->GetGroup(pSong2)->GetSortTitle(); + // Sort Titles are the same, fall back on group folder name + if( s1 == s2 ) + { return pSong1->m_sGroupName < pSong2->m_sGroupName; - } else { - return SONGMAN->GetGroup(pSong1)->GetSortTitle() < SONGMAN->GetGroup(pSong2)->GetSortTitle(); } + + s1 = SongUtil::MakeSortString(s1); + s2 = SongUtil::MakeSortString(s2); + + int ret = strcmp( s1, s2 ); + return ret < 0; } static int CompareSongPointersByGroupAndTitle( const Song *pSong1, const Song *pSong2 ) { + RString s1 = SONGMAN->GetGroup(pSong1)->GetSortTitle(); + RString s2 = SONGMAN->GetGroup(pSong2)->GetSortTitle(); + // Sort Titles are the same, fall back on group folder name + if( s1 == s2 ) + { + /* Same group; compare by name. */ + if( pSong1->m_sGroupName == pSong2->m_sGroupName ) + return CompareSongPointersByTitle( pSong1, pSong2 ); + else + return pSong1->m_sGroupName < pSong2->m_sGroupName; + } - // Check if the sort title exists - const RString &sGroup1 = SONGMAN->GetGroup(pSong1)->GetSortTitle(); - const RString &sGroup2 = SONGMAN->GetGroup(pSong2)->GetSortTitle(); + s1 = SongUtil::MakeSortString(s1); + s2 = SongUtil::MakeSortString(s2); - if( sGroup1 < sGroup2 ) - return true; - if( sGroup1 > sGroup2 ) - return false; - - /* Same group; compare by name. */ - return CompareSongPointersByTitle( pSong1, pSong2 ); - + int ret = strcmp( s1, s2 ); + return ret < 0; } void SongUtil::SortSongPointerArrayByGroupAndTitle( std::vector &vpSongsInOut ) @@ -653,7 +670,7 @@ RString SongUtil::GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so return SONGMAN->SongToPreferredSortSectionName( pSong ); case SORT_GROUP: // guaranteed not empty - return SONGMAN->GetGroup(pSong)->GetSortTitle(); + return SONGMAN->GetGroup(pSong)->GetGroupName(); case SORT_TITLE: case SORT_ARTIST: { diff --git a/src/SongUtil.h b/src/SongUtil.h index 965ca7c172..daf98664a8 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -162,6 +162,7 @@ namespace SongUtil void SortByMostRecentlyPlayedForMachine( std::vector &vpSongsInOut ); void SortByMostRecentlyPlayedForProfile( std::vector &vpSongsInOut, PlayerNumber pn); void SortSongPointerArrayByLength( std::vector &vpSongsInOut ); + void SortSongPointerArrayByGroup( std::vector &vpSongsInOut ); int CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2);