From 46d215aed3ba9d2bfadcf7a4e9617dd50ae02528 Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Wed, 4 Mar 2015 13:10:51 -0700 Subject: [PATCH] Added preview tag to NotesLoaderBMS. Changed Song to check the preview file for sample length instead of the simfile if the preview file is set. --- Docs/Changelog_sm5.txt | 2 +- src/NotesLoaderBMS.cpp | 6 ++++++ src/Song.cpp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index c46d1855ea..ace7105224 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -8,7 +8,7 @@ ________________________________________________________________________________ ---------- * [SelectMusic] Select Music now plays music file named by #PREVIEW tag if it's not blank, instead of using the song file for the sample music. The - sample length from the simfile is used and the sample start is treated as + sample length is read from the preview file. The sample start is treated as 0. [kyzentun] * [Song] GetPreviewMusicPath added. [kyzentun] * [foreach] foreach_ordered lua function now works on tables that have both diff --git a/src/NotesLoaderBMS.cpp b/src/NotesLoaderBMS.cpp index a51821c5ef..ce73a38057 100644 --- a/src/NotesLoaderBMS.cpp +++ b/src/NotesLoaderBMS.cpp @@ -773,6 +773,7 @@ struct BMSChartInfo { RString stageFile; RString musicFile; RString overrideMusicFile; + RString previewFile; map backgroundChanges; }; @@ -894,6 +895,10 @@ void BMSChartReader::ReadHeaders() { info.overrideMusicFile = it->second; } + else if (it->first == "#preview") + { + info.previewFile = it->second; + } else if (it->first == "#offset") { out->m_Timing.m_fBeat0OffsetInSeconds = -StringToFloat(it->second); @@ -1572,6 +1577,7 @@ void BMSSongLoader::AddToSong() } out->m_sMusicFile = main.info.musicFile; + out->m_PreviewFile= main.info.previewFile; out->m_SongTiming = main.steps->m_Timing; } diff --git a/src/Song.cpp b/src/Song.cpp index 3d7148d13f..420a81828e 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -575,6 +575,22 @@ void Song::TidyUpData( bool fromCache, bool /* duringCache */ ) m_fMusicLengthSeconds); } + if(!m_PreviewFile.empty()) + { + RString error; + RageSoundReader* sample= RageSoundReader_FileReader::OpenFile(GetPreviewMusicPath(), error); + if(sample == NULL) + { + LOG->UserLog( "Preview file", GetPreviewMusicPath(), "couldn't be opened: %s", error.c_str() ); + m_PreviewFile= ""; + } + else + { + m_fMusicSampleLengthSeconds= sample->GetLength() / 1000.0f; + delete sample; + } + } + if( m_fMusicLengthSeconds < 0 ) { LOG->UserLog("Sound file",