2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-12-13 23:56:13 +00:00
|
|
|
#include "NotesWriterSM.h"
|
2003-08-03 00:13:55 +00:00
|
|
|
#include "Steps.h"
|
2002-12-14 21:36:52 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "GameManager.h"
|
2003-01-11 19:11:55 +00:00
|
|
|
#include "RageLog.h"
|
2003-07-22 07:56:46 +00:00
|
|
|
#include "RageFile.h"
|
2004-04-19 20:57:54 +00:00
|
|
|
#include "RageFileManager.h"
|
2004-04-05 05:22:32 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
#include <cerrno>
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
void NotesWriterSM::WriteGlobalTags( RageFile &f, const Song &out )
|
2002-12-13 23:56:13 +00:00
|
|
|
{
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "#TITLE:%s;", out.m_sMainTitle.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#SUBTITLE:%s;", out.m_sSubTitle.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#ARTIST:%s;", out.m_sArtist.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#TITLETRANSLIT:%s;", out.m_sMainTitleTranslit.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#SUBTITLETRANSLIT:%s;", out.m_sSubTitleTranslit.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#ARTISTTRANSLIT:%s;", out.m_sArtistTranslit.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#CREDIT:%s;", out.m_sCredit.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#BANNER:%s;", out.m_sBannerFile.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#BACKGROUND:%s;", out.m_sBackgroundFile.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#LYRICSPATH:%s;", out.m_sLyricsFile.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#CDTITLE:%s;", out.m_sCDTitleFile.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#MUSIC:%s;", out.m_sMusicFile.c_str() ) );
|
2003-12-18 04:48:26 +00:00
|
|
|
f.PutLine( ssprintf( "#OFFSET:%.3f;", out.m_Timing.m_fBeat0OffsetInSeconds ) );
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "#SAMPLESTART:%.3f;", out.m_fMusicSampleStartSeconds ) );
|
|
|
|
|
f.PutLine( ssprintf( "#SAMPLELENGTH:%.3f;", out.m_fMusicSampleLengthSeconds ) );
|
|
|
|
|
|
|
|
|
|
f.Write( "#SELECTABLE:" );
|
2003-06-05 19:27:30 +00:00
|
|
|
switch(out.m_SelectionDisplay) {
|
|
|
|
|
default: ASSERT(0); /* fallthrough */
|
|
|
|
|
case Song::SHOW_ALWAYS:
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "YES" ); break;
|
2003-06-05 19:27:30 +00:00
|
|
|
case Song::SHOW_NEVER:
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "NO" ); break;
|
2003-06-05 19:27:30 +00:00
|
|
|
case Song::SHOW_ROULETTE:
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "ROULETTE" ); break;
|
2003-06-05 19:27:30 +00:00
|
|
|
}
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ";" );
|
2003-06-05 19:27:30 +00:00
|
|
|
|
2003-05-23 01:14:43 +00:00
|
|
|
switch( out.m_DisplayBPMType )
|
|
|
|
|
{
|
|
|
|
|
case Song::DISPLAY_ACTUAL:
|
|
|
|
|
// write nothing
|
|
|
|
|
break;
|
|
|
|
|
case Song::DISPLAY_SPECIFIED:
|
2003-06-16 17:28:58 +00:00
|
|
|
if( out.m_fSpecifiedBPMMin == out.m_fSpecifiedBPMMax )
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "#DISPLAYBPM:%.3f;", out.m_fSpecifiedBPMMin ) );
|
2003-05-23 01:14:43 +00:00
|
|
|
else
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "#DISPLAYBPM:%.3f:%.3f;", out.m_fSpecifiedBPMMin, out.m_fSpecifiedBPMMax ) );
|
2003-05-23 01:14:43 +00:00
|
|
|
break;
|
|
|
|
|
case Song::DISPLAY_RANDOM:
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "#DISPLAYBPM:*;" ) );
|
2003-05-23 01:14:43 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "#BPMS:" );
|
2002-12-13 23:56:13 +00:00
|
|
|
unsigned i;
|
2003-12-18 04:48:26 +00:00
|
|
|
for( i=0; i<out.m_Timing.m_BPMSegments.size(); i++ )
|
2002-12-13 23:56:13 +00:00
|
|
|
{
|
2003-12-18 04:48:26 +00:00
|
|
|
const BPMSegment &bs = out.m_Timing.m_BPMSegments[i];
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( ssprintf( "%.3f=%.3f", bs.m_fStartBeat, bs.m_fBPM ) );
|
2003-12-18 04:48:26 +00:00
|
|
|
if( i != out.m_Timing.m_BPMSegments.size()-1 )
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "," );
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ";" );
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "#STOPS:" );
|
2003-12-18 04:48:26 +00:00
|
|
|
for( i=0; i<out.m_Timing.m_StopSegments.size(); i++ )
|
2002-12-13 23:56:13 +00:00
|
|
|
{
|
2003-12-18 04:48:26 +00:00
|
|
|
const StopSegment &fs = out.m_Timing.m_StopSegments[i];
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "%.3f=%.3f", fs.m_fStartBeat, fs.m_fStopSeconds ) );
|
2003-12-18 04:48:26 +00:00
|
|
|
if( i != out.m_Timing.m_StopSegments.size()-1 )
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "," );
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ";" );
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "#BGCHANGES:" );
|
2002-12-13 23:56:13 +00:00
|
|
|
for( i=0; i<out.m_BackgroundChanges.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
const BackgroundChange &seg = out.m_BackgroundChanges[i];
|
|
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) );
|
2002-12-13 23:56:13 +00:00
|
|
|
if( i != out.m_BackgroundChanges.size()-1 )
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( "," );
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ";" );
|
2004-01-07 00:13:32 +00:00
|
|
|
|
2004-01-07 01:06:58 +00:00
|
|
|
if( out.m_ForegroundChanges.size() )
|
2004-01-07 00:13:32 +00:00
|
|
|
{
|
2004-01-07 01:06:58 +00:00
|
|
|
f.Write( "#FGCHANGES:" );
|
|
|
|
|
for( i=0; i<out.m_ForegroundChanges.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
const BackgroundChange &seg = out.m_ForegroundChanges[i];
|
2004-01-07 00:13:32 +00:00
|
|
|
|
2004-01-07 01:06:58 +00:00
|
|
|
f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) );
|
|
|
|
|
if( i != out.m_ForegroundChanges.size()-1 )
|
|
|
|
|
f.Write( "," );
|
|
|
|
|
}
|
|
|
|
|
f.PutLine( ";" );
|
2004-01-07 00:13:32 +00:00
|
|
|
}
|
2003-12-04 22:58:18 +00:00
|
|
|
}
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
static void WriteLineList( RageFile &f, vector<CString> &lines, bool SkipLeadingBlankLines, bool OmitLastNewline )
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i = 0; i < lines.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
TrimRight( lines[i] );
|
|
|
|
|
if( SkipLeadingBlankLines )
|
|
|
|
|
{
|
|
|
|
|
if( lines.size() == 0 )
|
|
|
|
|
continue;
|
|
|
|
|
SkipLeadingBlankLines = false;
|
|
|
|
|
}
|
|
|
|
|
f.Write( lines[i] );
|
|
|
|
|
|
|
|
|
|
if( !OmitLastNewline || i+1 < lines.size() )
|
|
|
|
|
f.PutLine( "" ); /* newline */
|
|
|
|
|
}
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
void NotesWriterSM::WriteSMNotesTag( const Steps &in, RageFile &f, bool bSavingCache )
|
2002-12-14 21:36:52 +00:00
|
|
|
{
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( "" );
|
|
|
|
|
f.PutLine( ssprintf( "//---------------%s - %s----------------",
|
|
|
|
|
GameManager::NotesTypeToString(in.m_StepsType).c_str(), in.GetDescription().c_str() ) );
|
|
|
|
|
f.PutLine( "#NOTES:" );
|
|
|
|
|
f.PutLine( ssprintf( " %s:", GameManager::NotesTypeToString(in.m_StepsType).c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( " %s:", in.GetDescription().c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( " %s:", DifficultyToString(in.GetDifficulty()).c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( " %d:", in.GetMeter() ) );
|
2002-12-14 21:36:52 +00:00
|
|
|
|
2003-11-26 17:41:32 +00:00
|
|
|
int MaxRadar = bSavingCache? NUM_RADAR_CATEGORIES:5;
|
2002-12-14 21:36:52 +00:00
|
|
|
CStringArray asRadarValues;
|
2003-11-26 17:41:32 +00:00
|
|
|
for( int r=0; r < MaxRadar; r++ )
|
2003-01-02 22:10:51 +00:00
|
|
|
asRadarValues.push_back( ssprintf("%.3f", in.GetRadarValues()[r]) );
|
2003-09-15 06:22:36 +00:00
|
|
|
/* Don't append a newline here; it's added in NoteDataUtil::GetSMNoteDataString.
|
|
|
|
|
* If we add it here, then every time we write unmodified data we'll add an extra
|
|
|
|
|
* newline and they'll accumulate. */
|
2003-12-04 22:58:18 +00:00
|
|
|
f.Write( ssprintf( " %s:", join(",",asRadarValues).c_str() ) );
|
2002-12-14 21:36:52 +00:00
|
|
|
|
2003-11-17 03:38:24 +00:00
|
|
|
CString sNoteData;
|
|
|
|
|
CString sAttackData;
|
|
|
|
|
in.GetSMNoteData( sNoteData, sAttackData );
|
|
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
vector<CString> lines;
|
|
|
|
|
|
|
|
|
|
split( sNoteData, "\n", lines, false );
|
|
|
|
|
WriteLineList( f, lines, true, true );
|
2003-11-17 03:38:24 +00:00
|
|
|
|
|
|
|
|
if( sAttackData.empty() )
|
2003-12-04 22:58:18 +00:00
|
|
|
f.PutLine( ";" );
|
2003-11-17 03:38:24 +00:00
|
|
|
else
|
2003-12-04 22:58:18 +00:00
|
|
|
{
|
|
|
|
|
f.PutLine( ":" );
|
|
|
|
|
|
|
|
|
|
lines.clear();
|
|
|
|
|
split( sAttackData, "\n", lines, false );
|
|
|
|
|
WriteLineList( f, lines, true, true );
|
|
|
|
|
|
|
|
|
|
f.PutLine( ";" );
|
|
|
|
|
}
|
2002-12-14 21:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-13 23:56:13 +00:00
|
|
|
bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache)
|
|
|
|
|
{
|
2003-11-01 22:09:56 +00:00
|
|
|
/* Flush dir cache when writing steps, so the old size isn't cached. */
|
2004-04-19 20:57:54 +00:00
|
|
|
FILEMAN->FlushDirCache( Dirname(sPath) );
|
2003-11-01 22:09:56 +00:00
|
|
|
|
2002-12-13 23:56:13 +00:00
|
|
|
unsigned i;
|
|
|
|
|
|
2004-04-19 22:20:38 +00:00
|
|
|
int flags = RageFile::WRITE;
|
|
|
|
|
|
|
|
|
|
/* If we're not saving cache, we're saving real data, so enable SLOW_FLUSH
|
|
|
|
|
* to prevent data loss. If we're saving cache, this will slow things down
|
|
|
|
|
* too much. */
|
|
|
|
|
if( !bSavingCache )
|
|
|
|
|
flags |= RageFile::SLOW_FLUSH;
|
|
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
RageFile f;
|
2004-04-19 22:20:38 +00:00
|
|
|
if( !f.Open( sPath, flags ) )
|
2003-01-11 19:11:55 +00:00
|
|
|
{
|
2003-12-04 22:58:18 +00:00
|
|
|
LOG->Warn( "Error opening song file '%s' for writing: %s", sPath.c_str(), f.GetError().c_str() );
|
2003-01-11 19:11:55 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2002-12-13 23:56:13 +00:00
|
|
|
|
2003-12-04 22:58:18 +00:00
|
|
|
WriteGlobalTags( f, out );
|
|
|
|
|
if( bSavingCache )
|
|
|
|
|
{
|
2004-02-20 05:28:34 +00:00
|
|
|
f.PutLine( ssprintf( "// cache tags:" ) );
|
|
|
|
|
f.PutLine( ssprintf( "#FIRSTBEAT:%.3f;", out.m_fFirstBeat ) );
|
|
|
|
|
f.PutLine( ssprintf( "#LASTBEAT:%.3f;", out.m_fLastBeat ) );
|
|
|
|
|
f.PutLine( ssprintf( "#SONGFILENAME:%s;", out.m_sSongFileName.c_str() ) );
|
|
|
|
|
f.PutLine( ssprintf( "#HASMUSIC:%i;", out.m_bHasMusic ) );
|
|
|
|
|
f.PutLine( ssprintf( "#HASBANNER:%i;", out.m_bHasBanner ) );
|
2004-02-02 10:06:26 +00:00
|
|
|
f.PutLine( ssprintf( "#MUSICLENGTH:%.3f;", out.m_fMusicLengthSeconds ) );
|
2004-02-20 05:28:34 +00:00
|
|
|
f.PutLine( ssprintf( "// end cache tags" ) );
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2003-08-03 00:13:55 +00:00
|
|
|
// Save all Steps for this file
|
2002-12-13 23:56:13 +00:00
|
|
|
//
|
2004-05-24 03:41:39 +00:00
|
|
|
for( i=0; i<out.m_vpSteps.size(); i++ )
|
2002-12-13 23:56:13 +00:00
|
|
|
{
|
2004-05-24 03:41:39 +00:00
|
|
|
Steps* pSteps = out.m_vpSteps[i];
|
|
|
|
|
if( pSteps->IsAutogen() )
|
2003-01-02 22:10:51 +00:00
|
|
|
continue; /* don't write autogen notes */
|
2002-12-14 21:36:52 +00:00
|
|
|
|
2004-02-25 23:48:45 +00:00
|
|
|
/* Only save steps that weren't loaded from a profile. */
|
2004-05-24 03:41:39 +00:00
|
|
|
if( pSteps->WasLoadedFromProfile() )
|
2004-02-25 23:48:45 +00:00
|
|
|
continue;
|
|
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
WriteSMNotesTag( *out.m_vpSteps[i], f, bSavingCache );
|
2002-12-13 23:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|