From ac13cda6a910097f13870605a1f92dbe039a59be Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 4 Dec 2003 22:20:41 +0000 Subject: [PATCH] use RageFile --- stepmania/src/NotesWriterDWI.cpp | 103 +++++++++++++++---------------- stepmania/src/NotesWriterDWI.h | 5 +- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/stepmania/src/NotesWriterDWI.cpp b/stepmania/src/NotesWriterDWI.cpp index 47f0d96fea..9c723cf696 100644 --- a/stepmania/src/NotesWriterDWI.cpp +++ b/stepmania/src/NotesWriterDWI.cpp @@ -6,6 +6,7 @@ #include "RageLog.h" #include "RageFile.h" #include "NoteDataUtil.h" +#include "RageFile.h" /* Output is an angle bracket expression without angle brackets, eg. "468". */ CString NotesWriterDWI::NotesToDWIString( const TapNote cNoteCols[6] ) @@ -182,7 +183,7 @@ CString NotesWriterDWI::OptimizeDWIString( CString holds, CString taps ) return ssprintf( "<%s>", ret.c_str() ); } -void NotesWriterDWI::WriteDWINotesField( FILE* fp, const Steps &out, int start ) +void NotesWriterDWI::WriteDWINotesField( RageFile &f, const Steps &out, int start ) { NoteData notedata; out.GetNoteData( ¬edata ); @@ -202,16 +203,16 @@ void NotesWriterDWI::WriteDWINotesField( FILE* fp, const Steps &out, int start ) break; case NOTE_TYPE_12TH: case NOTE_TYPE_24TH: - fprintf( fp, "[" ); + f.Write( "[" ); fCurrentIncrementer = 1.0/24 * BEATS_PER_MEASURE; break; case NOTE_TYPE_16TH: - fprintf( fp, "(" ); + f.Write( "(" ); fCurrentIncrementer = 1.0/16 * BEATS_PER_MEASURE; break; case NOTE_TYPE_32ND: case NOTE_TYPE_64TH: - fprintf( fp, "{" ); + f.Write( "{" ); fCurrentIncrementer = 1.0/64 * BEATS_PER_MEASURE; break; case NOTE_TYPE_48TH: @@ -219,7 +220,7 @@ void NotesWriterDWI::WriteDWINotesField( FILE* fp, const Steps &out, int start ) case NOTE_TYPE_INVALID: // since, for whatever reason, the only way to do // 48ths is through a block of 192nds... - fprintf( fp, "`" ); + f.Write( "`" ); fCurrentIncrementer = 1.0/192 * BEATS_PER_MEASURE; break; default: @@ -272,7 +273,7 @@ void NotesWriterDWI::WriteDWINotesField( FILE* fp, const Steps &out, int start ) default: ASSERT(0); // not a type supported by DWI. We shouldn't have called in here if that's the case } - fprintf( fp, "%s", str.c_str() ); + f.Write( str ); } switch( nt ) @@ -282,29 +283,29 @@ void NotesWriterDWI::WriteDWINotesField( FILE* fp, const Steps &out, int start ) break; case NOTE_TYPE_12TH: case NOTE_TYPE_24TH: - fprintf( fp, "]" ); + f.Write( "]" ); break; case NOTE_TYPE_16TH: - fprintf( fp, ")" ); + f.Write( ")" ); break; case NOTE_TYPE_32ND: case NOTE_TYPE_64TH: - fprintf( fp, "}" ); + f.Write( "}" ); break; case NOTE_TYPE_48TH: case NOTE_TYPE_192ND: case NOTE_TYPE_INVALID: - fprintf( fp, "'" ); + f.Write( "'" ); break; default: ASSERT(0); // fall though } - fprintf( fp, "\n" ); + f.PutLine( "" ); } } -bool NotesWriterDWI::WriteDWINotesTag( FILE* fp, const Steps &out ) +bool NotesWriterDWI::WriteDWINotesTag( RageFile &f, const Steps &out ) { /* Flush dir cache when writing steps, so the old size isn't cached. */ FlushDirCache(); @@ -313,44 +314,44 @@ bool NotesWriterDWI::WriteDWINotesTag( FILE* fp, const Steps &out ) switch( out.m_StepsType ) { - case STEPS_TYPE_DANCE_SINGLE: fprintf( fp, "#SINGLE:" ); break; - case STEPS_TYPE_DANCE_COUPLE: fprintf( fp, "#COUPLE:" ); break; - case STEPS_TYPE_DANCE_DOUBLE: fprintf( fp, "#DOUBLE:" ); break; - case STEPS_TYPE_DANCE_SOLO: fprintf( fp, "#SOLO:" ); break; + case STEPS_TYPE_DANCE_SINGLE: f.Write( "#SINGLE:" ); break; + case STEPS_TYPE_DANCE_COUPLE: f.Write( "#COUPLE:" ); break; + case STEPS_TYPE_DANCE_DOUBLE: f.Write( "#DOUBLE:" ); break; + case STEPS_TYPE_DANCE_SOLO: f.Write( "#SOLO:" ); break; default: return false; // not a type supported by DWI } switch( out.GetDifficulty() ) { - case DIFFICULTY_BEGINNER: fprintf( fp, "BEGINNER:" ); break; - case DIFFICULTY_EASY: fprintf( fp, "BASIC:" ); break; - case DIFFICULTY_MEDIUM: fprintf( fp, "ANOTHER:" ); break; - case DIFFICULTY_HARD: fprintf( fp, "MANIAC:" ); break; - case DIFFICULTY_CHALLENGE: fprintf( fp, "SMANIAC:" ); break; + case DIFFICULTY_BEGINNER: f.Write( "BEGINNER:" ); break; + case DIFFICULTY_EASY: f.Write( "BASIC:" ); break; + case DIFFICULTY_MEDIUM: f.Write( "ANOTHER:" ); break; + case DIFFICULTY_HARD: f.Write( "MANIAC:" ); break; + case DIFFICULTY_CHALLENGE: f.Write( "SMANIAC:" ); break; default: ASSERT(0); return false; } - fprintf( fp, "%d:\n", out.GetMeter() ); + f.PutLine( ssprintf("%d:", out.GetMeter()) ); return true; } bool NotesWriterDWI::Write( CString sPath, const Song &out ) { - FILE* fp = fopen( sPath, "w" ); - if( fp == NULL ) - RageException::Throw( "Error opening song file '%s' for writing.", sPath.c_str() ); + RageFile f; + if( !f.Open( sPath, RageFile::WRITE ) ) + RageException::Throw( "Error opening song file '%s' for writing.", f.GetError().c_str() ); /* Write transliterations, if we have them, since DWI doesn't support UTF-8. */ - fprintf( fp, "#TITLE:%s;\n", out.GetFullTranslitTitle().c_str() ); - fprintf( fp, "#ARTIST:%s;\n", out.GetTranslitArtist().c_str() ); + f.PutLine( ssprintf("#TITLE:%s;", out.GetFullTranslitTitle().c_str()) ); + f.PutLine( ssprintf("#ARTIST:%s;", out.GetTranslitArtist().c_str()) ); ASSERT( out.m_BPMSegments[0].m_fStartBeat == 0 ); - fprintf( fp, "#FILE:%s;\n", out.m_sMusicFile.c_str() ); - fprintf( fp, "#BPM:%.3f;\n", out.m_BPMSegments[0].m_fBPM ); - fprintf( fp, "#GAP:%d;\n", int(-roundf( out.m_fBeat0OffsetInSeconds*1000 )) ); - fprintf( fp, "#SAMPLESTART:%.3f;\n", out.m_fMusicSampleStartSeconds ); - fprintf( fp, "#SAMPLELENGTH:%.3f;\n", out.m_fMusicSampleLengthSeconds ); + f.PutLine( ssprintf("#FILE:%s;", out.m_sMusicFile.c_str()) ); + f.PutLine( ssprintf("#BPM:%.3f;", out.m_BPMSegments[0].m_fBPM) ); + f.PutLine( ssprintf("#GAP:%d;", int(-roundf( out.m_fBeat0OffsetInSeconds*1000 ))) ); + f.PutLine( ssprintf("#SAMPLESTART:%.3f;", out.m_fMusicSampleStartSeconds) ); + f.PutLine( ssprintf("#SAMPLELENGTH:%.3f;", out.m_fMusicSampleLengthSeconds) ); if( out.m_sCDTitleFile.size() ) - fprintf( fp, "#CDTITLE:%s;\n", out.m_sCDTitleFile.c_str() ); + f.PutLine( ssprintf("#CDTITLE:%s;", out.m_sCDTitleFile.c_str()) ); switch( out.m_DisplayBPMType ) { case Song::DISPLAY_ACTUAL: @@ -358,41 +359,41 @@ bool NotesWriterDWI::Write( CString sPath, const Song &out ) break; case Song::DISPLAY_SPECIFIED: if( out.m_fSpecifiedBPMMin == out.m_fSpecifiedBPMMax ) - fprintf( fp, "#DISPLAYBPM:%i;\n", (int) out.m_fSpecifiedBPMMin ); + f.PutLine( ssprintf("#DISPLAYBPM:%i;\n", (int) out.m_fSpecifiedBPMMin) ); else - fprintf( fp, "#DISPLAYBPM:%i..%i;\n", (int) out.m_fSpecifiedBPMMin, (int) out.m_fSpecifiedBPMMax ); + f.PutLine( ssprintf("#DISPLAYBPM:%i..%i;\n", (int) out.m_fSpecifiedBPMMin, (int) out.m_fSpecifiedBPMMax) ); break; case Song::DISPLAY_RANDOM: - fprintf( fp, "#DISPLAYBPM:*" ); + f.PutLine( "#DISPLAYBPM:*" ); break; } if( !out.m_StopSegments.empty() ) { - fprintf( fp, "#FREEZE:" ); + f.Write( "#FREEZE:" ); for( unsigned i=0; i 1) { - fprintf( fp, "#CHANGEBPM:" ); + f.Write( "#CHANGEBPM:" ); for( unsigned i=1; iIsAutogen() ) continue; // don't save autogen notes - if(!WriteDWINotesTag( fp, *out.m_apNotes[i] )) + if(!WriteDWINotesTag( f, *out.m_apNotes[i] )) continue; - WriteDWINotesField( fp, *out.m_apNotes[i], 0 ); + WriteDWINotesField( f, *out.m_apNotes[i], 0 ); if(out.m_apNotes[i]->m_StepsType==STEPS_TYPE_DANCE_DOUBLE || out.m_apNotes[i]->m_StepsType==STEPS_TYPE_DANCE_COUPLE) { - fprintf( fp, ":\n" ); - WriteDWINotesField( fp, *out.m_apNotes[i], 4 ); + f.PutLine( ":" ); + WriteDWINotesField( f, *out.m_apNotes[i], 4 ); } - fprintf( fp, ";\n" ); + f.PutLine( ";" ); } - fclose( fp ); - return true; } /* diff --git a/stepmania/src/NotesWriterDWI.h b/stepmania/src/NotesWriterDWI.h index de9ba32029..a7cb82fe3e 100644 --- a/stepmania/src/NotesWriterDWI.h +++ b/stepmania/src/NotesWriterDWI.h @@ -5,12 +5,13 @@ #include "Steps.h" #include "NoteTypes.h" +class RageFile; class NotesWriterDWI { CString NotesToDWIString( TapNote cNoteCol1, TapNote cNoteCol2, TapNote cNoteCol3, TapNote cNoteCol4, TapNote cNoteCol5, TapNote cNoteCol6 ); CString NotesToDWIString( TapNote cNoteCol1, TapNote cNoteCol2, TapNote cNoteCol3, TapNote cNoteCol4 ); - void WriteDWINotesField( FILE* fp, const Steps &out, int start ); - bool WriteDWINotesTag( FILE* fp, const Steps &out ); + void WriteDWINotesField( RageFile &f, const Steps &out, int start ); + bool WriteDWINotesTag( RageFile &f, const Steps &out ); CString NotesToDWIString( const TapNote cNoteCols[6] ); CString OptimizeDWIString( CString holds, CString taps ); char OptimizeDWIPair( char c1, char c2 );