bool SMLoader::LoadFromSMFile( CString sPath, Song &out ) { LOG->Trace( "Song::LoadFromSMFile(%s)", sPath.c_str() ); MsdFile msd; if( !msd.ReadFile( sPath ) ) RageException::Throw( "Error opening file \"%s\": %s", sPath.c_str(), msd.GetError().c_str() ); out.m_Timing.m_sFile = sPath; LoadTimingFromSMFile( msd, out.m_Timing ); for( unsigned i=0; i<msd.GetNumValues(); i++ ) { int iNumParams = msd.GetNumParams(i); const MsdFile::value_t &sParams = msd.GetValue(i); const CString sValueName = sParams[0]; // handle the data /* Don't use GetMainAndSubTitlesFromFullTitle; that's only for heuristically * splitting other formats that *don't* natively support #SUBTITLE. */ if( 0==stricmp(sValueName,"TITLE") ) out.m_sMainTitle = sParams[1]; else if( 0==stricmp(sValueName,"SUBTITLE") ) out.m_sSubTitle = sParams[1]; else if( 0==stricmp(sValueName,"ARTIST") ) out.m_sArtist = sParams[1]; else if( 0==stricmp(sValueName,"TITLETRANSLIT") ) out.m_sMainTitleTranslit = sParams[1]; else if( 0==stricmp(sValueName,"SUBTITLETRANSLIT") ) out.m_sSubTitleTranslit = sParams[1]; else if( 0==stricmp(sValueName,"ARTISTTRANSLIT") ) out.m_sArtistTranslit = sParams[1]; else if( 0==stricmp(sValueName,"CREDIT") ) out.m_sCredit = sParams[1]; else if( 0==stricmp(sValueName,"BANNER") ) out.m_sBannerFile = sParams[1]; else if( 0==stricmp(sValueName,"BACKGROUND") ) out.m_sBackgroundFile = sParams[1]; /* Save "#LYRICS" for later, so we can add an internal lyrics tag. */ else if( 0==stricmp(sValueName,"LYRICSPATH") ) out.m_sLyricsFile = sParams[1]; else if( 0==stricmp(sValueName,"CDTITLE") ) out.m_sCDTitleFile = sParams[1]; else if( 0==stricmp(sValueName,"MUSIC") ) out.m_sMusicFile = sParams[1]; else if( 0==stricmp(sValueName,"MUSICLENGTH") ) { if(!FromCache) continue; out.m_fMusicLengthSeconds = strtof( sParams[1], NULL ); } else if( 0==stricmp(sValueName,"MUSICBYTES") ) ; /* ignore */ /* We calculate these. Some SMs in circulation have bogus values for * these, so make sure we always calculate it ourself. */ else if( 0==stricmp(sValueName,"FIRSTBEAT") ) { if(!FromCache) continue; out.m_fFirstBeat = strtof( sParams[1], NULL ); } else if( 0==stricmp(sValueName,"LASTBEAT") ) { if(!FromCache) LOG->Trace("Ignored #LASTBEAT (cache only)"); out.m_fLastBeat = strtof( sParams[1], NULL ); } else if( 0==stricmp(sValueName,"SONGFILENAME") ) { if( FromCache ) out.m_sSongFileName = sParams[1]; } else if( 0==stricmp(sValueName,"HASMUSIC") ) { if( FromCache ) out.m_bHasMusic = atoi( sParams[1] ) != 0; } else if( 0==stricmp(sValueName,"HASBANNER") ) { if( FromCache ) out.m_bHasBanner = atoi( sParams[1] ) != 0; } else if( 0==stricmp(sValueName,"SAMPLESTART") ) out.m_fMusicSampleStartSeconds = HHMMSSToSeconds( sParams[1] ); else if( 0==stricmp(sValueName,"SAMPLELENGTH") ) out.m_fMusicSampleLengthSeconds = HHMMSSToSeconds( sParams[1] ); else if( 0==stricmp(sValueName,"DISPLAYBPM") ) { // #DISPLAYBPM:[xxx][xxx:xxx]|[*]; if( sParams[1] == "*" ) out.m_DisplayBPMType = Song::DISPLAY_RANDOM; else { out.m_DisplayBPMType = Song::DISPLAY_SPECIFIED; out.m_fSpecifiedBPMMin = strtof( sParams[1], NULL ); if( sParams[2].empty() ) out.m_fSpecifiedBPMMax = out.m_fSpecifiedBPMMin; else out.m_fSpecifiedBPMMax = strtof( sParams[2], NULL ); } } else if( 0==stricmp(sValueName,"SELECTABLE") ) { if(!stricmp(sParams[1],"YES")) out.m_SelectionDisplay = out.SHOW_ALWAYS; else if(!stricmp(sParams[1],"NO")) out.m_SelectionDisplay = out.SHOW_NEVER; else if(!stricmp(sParams[1],"ROULETTE")) out.m_SelectionDisplay = out.SHOW_ROULETTE; else LOG->Warn( "The song file '%s' has an unknown #SELECTABLE value, '%s'; ignored.", sPath.c_str(), sParams[1].c_str()); } else if( 0==stricmp(sValueName,"BGCHANGES") || 0==stricmp(sValueName,"ANIMATIONS") ) { CStringArray aBGChangeExpressions; split( sParams[1], ",", aBGChangeExpressions ); for( unsigned b=0; b<aBGChangeExpressions.size(); b++ ) { BackgroundChange change; if( LoadFromBGChangesString( change, aBGChangeExpressions[b] ) ) out.AddBackgroundChange( change ); } } else if( 0==stricmp(sValueName,"FGCHANGES") ) { CStringArray aFGChangeExpressions; split( sParams[1], ",", aFGChangeExpressions ); for( unsigned b=0; b<aFGChangeExpressions.size(); b++ ) { BackgroundChange change; if( LoadFromBGChangesString( change, aFGChangeExpressions[b] ) ) out.AddForegroundChange( change ); } } else if( 0==stricmp(sValueName,"NOTES") ) { if( iNumParams < 7 ) { LOG->Trace( "The song file '%s' is has %d fields in a #NOTES tag, but should have at least %d.", sPath.c_str(), iNumParams, 7 ); continue; } Steps* pNewNotes = new Steps; ASSERT( pNewNotes ); LoadFromSMTokens( sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], (iNumParams>=8)?sParams[7]:CString(""), *pNewNotes); out.AddSteps( pNewNotes ); } else if( 0==stricmp(sValueName,"OFFSET") || 0==stricmp(sValueName,"BPMS") || 0==stricmp(sValueName,"STOPS") || 0==stricmp(sValueName,"FREEZES") ) ; else LOG->Trace( "Unexpected value named '%s'", sValueName.c_str() ); } return true; }
void SMSetSampleLength(SMSongTagInfo& info) { info.song->m_fMusicSampleLengthSeconds = HHMMSSToSeconds((*info.params)[1]); }
static bool LoadGlobalData( const RString &sPath, Song &out, bool &bKIUCompliant ) { MsdFile msd; if( !msd.ReadFile( sPath, false ) ) // don't unescape { LOG->UserLog( "Song file", sPath, "couldn't be opened: %s", msd.GetError().c_str() ); return false; } // changed up there in case of something is found inside the SONGFILE tag in the head ksf -DaisuMaster // search for music with song in the file name vector<RString> arrayPossibleMusic; GetDirListing( out.GetSongDir() + RString("song.mp3"), arrayPossibleMusic ); GetDirListing( out.GetSongDir() + RString("song.oga"), arrayPossibleMusic ); GetDirListing( out.GetSongDir() + RString("song.ogg"), arrayPossibleMusic ); GetDirListing( out.GetSongDir() + RString("song.wav"), arrayPossibleMusic ); if( !arrayPossibleMusic.empty() ) // we found a match out.m_sMusicFile = arrayPossibleMusic[0]; // ^this was below, at the end float SMGap1 = 0, SMGap2 = 0, BPM1 = -1, BPMPos2 = -1, BPM2 = -1, BPMPos3 = -1, BPM3 = -1; int iTickCount = -1; bKIUCompliant = false; vector<RString> vNoteRows; for( unsigned i=0; i < msd.GetNumValues(); i++ ) { const MsdFile::value_t &sParams = msd.GetValue(i); RString sValueName = sParams[0]; sValueName.MakeUpper(); // handle the data if( sValueName=="TITLE" ) LoadTags(sParams[1], out); else if( sValueName=="BPM" ) { BPM1 = StringToFloat(sParams[1]); out.m_SongTiming.AddSegment( BPMSegment(0, BPM1) ); } else if( sValueName=="BPM2" ) { bKIUCompliant = true; BPM2 = StringToFloat( sParams[1] ); } else if( sValueName=="BPM3" ) { bKIUCompliant = true; BPM3 = StringToFloat( sParams[1] ); } else if( sValueName=="BUNKI" ) { bKIUCompliant = true; BPMPos2 = StringToFloat( sParams[1] ) / 100.0f; } else if( sValueName=="BUNKI2" ) { bKIUCompliant = true; BPMPos3 = StringToFloat( sParams[1] ) / 100.0f; } else if( sValueName=="STARTTIME" ) { SMGap1 = -StringToFloat( sParams[1] )/100; out.m_SongTiming.m_fBeat0OffsetInSeconds = SMGap1; } // This is currently required for more accurate KIU BPM changes. else if( sValueName=="STARTTIME2" ) { bKIUCompliant = true; SMGap2 = -StringToFloat( sParams[1] )/100; } else if ( sValueName=="STARTTIME3" ) { // STARTTIME3 only ensures this is a KIU compliant simfile. //bKIUCompliant = true; } else if ( sValueName=="TICKCOUNT" ) { ProcessTickcounts(sParams[1], iTickCount, out.m_SongTiming); } else if ( sValueName=="STEP" ) { /* STEP will always be the last header in a KSF file by design. Due to * the Direct Move syntax, it is best to get the rows of notes here. */ RString theSteps = sParams[1]; TrimLeft( theSteps ); split( theSteps, "\n", vNoteRows, true ); } else if( sValueName=="DIFFICULTY" || sValueName=="PLAYER" ) { /* DIFFICULTY and PLAYER are handled only in LoadFromKSFFile. Ignore those here. */ continue; } // New cases noted in Aldo_MX's code: else if( sValueName=="MUSICINTRO" || sValueName=="INTRO" ) { out.m_fMusicSampleStartSeconds = HHMMSSToSeconds( sParams[1] ); } else if( sValueName=="TITLEFILE" ) { out.m_sBackgroundFile = sParams[1]; } else if( sValueName=="DISCFILE" ) { out.m_sBannerFile = sParams[1]; } else if( sValueName=="SONGFILE" ) { out.m_sMusicFile = sParams[1]; } //else if( sValueName=="INTROFILE" ) //{ // nothing to add... //} // end new cases else { LOG->UserLog( "Song file", sPath, "has an unexpected value named \"%s\".", sValueName.c_str() ); } } //intro length in piu mixes is generally 7 seconds out.m_fMusicSampleLengthSeconds = 7.0f; /* BPM Change checks are done here. If bKIUCompliant, it's short and sweet. * Otherwise, the whole file has to be processed. Right now, this is only * called once, for the initial file (often the Crazy steps). Hopefully that * will end up changing soon. */ if( bKIUCompliant ) { if( BPM2 > 0 && BPMPos2 > 0 ) { HandleBunki( out.m_SongTiming, BPM1, BPM2, SMGap1, BPMPos2 ); } if( BPM3 > 0 && BPMPos3 > 0 ) { HandleBunki( out.m_SongTiming, BPM2, BPM3, SMGap2, BPMPos3 ); } } else { float fCurBeat = 0.0f; bool bDMRequired = false; for( unsigned i=0; i < vNoteRows.size(); ++i ) { RString& NoteRowString = vNoteRows[i]; StripCrnl( NoteRowString ); if( NoteRowString == "" ) continue; // ignore empty rows. if( NoteRowString == "2222222222222" ) // Row of 2s = end. Confirm KIUCompliency here. { if (!bDMRequired) bKIUCompliant = true; break; } // This is where the DMRequired test will take place. if ( BeginsWith( NoteRowString, "|" ) ) { // have a static timing for everything bDMRequired = true; continue; } else { // ignore whatever else... //continue; } fCurBeat += 1.0f / iTickCount; } } // Try to fill in missing bits of information from the pathname. { vector<RString> asBits; split( sPath, "/", asBits, true); ASSERT( asBits.size() > 1 ); LoadTags( asBits[asBits.size()-2], out ); } return true; }