Move sync offset application to song load (as early as possible)

This commit is contained in:
Crash Cringle
2025-03-03 23:25:32 -08:00
committed by teejusb
parent 9d61cb4c06
commit 8f6d5b44b9
2 changed files with 26 additions and 19 deletions
+10
View File
@@ -655,9 +655,19 @@ void Song::TidyUpData( bool from_cache, bool /* duringCache */ )
m_SongTiming.TidyUpData(false);
// Apply the group offset to the song timing before we do anything else.
float fOffset = PREFSMAN->m_fMachineSyncBias;
if (SONGMAN->GetGroupFromName(m_sGroupName) != nullptr)
{
fOffset = SONGMAN->GetGroupFromName(m_sGroupName)->GetSyncOffset();
}
m_SongTiming.m_fBeat0GroupOffsetInSeconds = fOffset;
for (Steps *s : m_vpSteps)
{
s->m_Timing.TidyUpData(true);
// Apply the group offset to the step timing as well.
s->m_Timing.m_fBeat0GroupOffsetInSeconds = fOffset;
}
if(!from_cache)
+16 -19
View File
@@ -341,11 +341,6 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group )
m_sSongGroupBannerPaths.push_back( sBannerPath );
m_sSongGroupNames.push_back( sGroupDirName );
if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end())
{
m_mapNameToGroup[sGroupDirName] = group;
}
// Add the group to its series if the group has one and if the series exists
if( group->GetSeries() != "" )
{
@@ -435,6 +430,12 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
RString group_base_name= Basename(sGroupDirName);
Group* group = new Group(sDir, sGroupDirName);
// Add the group to the group mapping
if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end())
{
m_mapNameToGroup[sGroupDirName] = group;
}
for( unsigned j=0; j< arraySongDirs.size(); ++j ) // for each song dir
{
RString sSongDirName = arraySongDirs[j];
@@ -468,19 +469,6 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
delete pNewSong;
continue;
}
// Apply Group Offset if applicable
if( group->GetSyncOffset() != 0.0f )
{
pNewSong->m_SongTiming.m_fBeat0GroupOffsetInSeconds = group->GetSyncOffset();
const std::vector<Steps*>& vpSteps = pNewSong->GetAllSteps();
for (Steps* s : vpSteps)
{
if( s->m_Timing.empty() )
continue;
s->m_Timing.m_fBeat0GroupOffsetInSeconds = group->GetSyncOffset();
}
}
AddSongToList(pNewSong);
@@ -492,7 +480,16 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio
LOG->Trace("Loaded %i songs from \"%s\"", loaded, (sDir+sGroupDirName).c_str() );
// Don't add the group name if we didn't load any songs in this group.
if(!loaded) continue;
if(!loaded) {
// Remove the group from the group mapping
auto it = m_mapNameToGroup.find(sGroupDirName);
if (it != m_mapNameToGroup.end())
{
m_mapNameToGroup.erase(it);
}
delete group;
continue;
}
// Add this group to the group array.
AddGroup(sDir, sGroupDirName, group);