diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index 02ef89fc2d..db596bb253 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -1758,13 +1758,6 @@ int StringToInt( const RString &sString ) return ret; } -RString IntToString( const int &iNum ) -{ - stringstream ss; - ss << iNum; - return ss.str(); -} - float StringToFloat( const RString &sString ) { float ret = strtof( sString, nullptr ); diff --git a/src/RageUtil.h b/src/RageUtil.h index 47bd2ab976..3ccc6e57e6 100644 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -410,11 +410,6 @@ void MakeLower( wchar_t *p, size_t iLen ); * @param sString the string to convert. * @return the integer we are after. */ int StringToInt( const RString &sString ); -/** - * @brief Have a standard way of converting integers to Strings. - * @param iNum the integer to convert. - * @return the string we are after. */ -RString IntToString( const int &iNum ); float StringToFloat( const RString &sString ); RString FloatToString( const float &num ); bool StringToFloat( const RString &sString, float &fOut ); diff --git a/src/ScreenMiniMenu.h b/src/ScreenMiniMenu.h index 80aabc148a..a65cd9bc3e 100644 --- a/src/ScreenMiniMenu.h +++ b/src/ScreenMiniMenu.h @@ -98,7 +98,7 @@ struct MenuRowDef { for ( int i = low; i <= high; i++ ) { - choices.push_back(IntToString(i).c_str()); + choices.push_back(std::to_string(i)); } } diff --git a/src/TimingSegments.cpp b/src/TimingSegments.cpp index c8b82e0a52..d34db8451a 100644 --- a/src/TimingSegments.cpp +++ b/src/TimingSegments.cpp @@ -1,267 +1,267 @@ -#include "global.h" -#include "TimingSegments.h" -#include "EnumHelper.h" - -const double TimingSegment::EPSILON = 1e-6; - -static const char *TimingSegmentTypeNames[] = { - "BPM", - "Stop", - "Delay", - "Time Sig", - "Warp", - "Label", - "Tickcount", - "Combo", - "Speed", - "Scroll", - "Fake" -}; -XToString( TimingSegmentType ); - -#define LTCOMPARE(x) if(this->x < other.x) return true; if(this->x > other.x) return false; - -void TimingSegment::Scale( int start, int length, int newLength ) -{ - SetRow( ScalePosition( start, length, newLength, this->GetRow() ) ); -} - -void TimingSegment::DebugPrint() const -{ - LOG->Trace( "\tTimingSegment(%d [%f])", GetRow(), GetBeat() ); -} - -void BPMSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %f)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetBPM() - ); -} - -void StopSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %f)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetPause() - ); -} - -void DelaySegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %f)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetPause() - ); -} - -void TimeSignatureSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %d/%d)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetNum(), GetDen() - ); -} - -void WarpSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %d [%f])", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetLengthRows(), GetLengthBeats() - ); -} - -void LabelSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %s)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetLabel().c_str() - ); -} - -void TickcountSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %d)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetTicks() - ); -} - -void ComboSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %d, %d)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetCombo(), GetMissCombo() - ); -} - -void SpeedSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %f, %f, %d)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetRatio(), GetDelay(), GetUnit() - ); -} - -void ScrollSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %f)", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetRatio() - ); -} - -void FakeSegment::DebugPrint() const -{ - LOG->Trace( "\t%s(%d [%f], %d [%f])", - TimingSegmentTypeToString(GetType()).c_str(), - GetRow(), GetBeat(), GetLengthRows(), GetLengthBeats() - ); -} - -RString FakeSegment::ToString(int dec) const -{ - RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetLength()); -} - -void FakeSegment::Scale( int start, int length, int newLength ) -{ - float startBeat = GetBeat(); - float endBeat = startBeat + GetLength(); - float newStartBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), startBeat ); - float newEndBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), endBeat ); - SetLength( newEndBeat - newStartBeat ); - TimingSegment::Scale( start, length, newLength ); -} - -RString WarpSegment::ToString(int dec) const -{ - RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetLength()); -} - -void WarpSegment::Scale( int start, int length, int newLength ) -{ - // XXX: this function is duplicated, there should be a better way - float startBeat = GetBeat(); - float endBeat = startBeat + GetLength(); - float newStartBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), startBeat ); - float newEndBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), endBeat ); - SetLength( newEndBeat - newStartBeat ); - TimingSegment::Scale( start, length, newLength ); -} - -RString TickcountSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) + "f=%i"; - return ssprintf(str.c_str(), GetBeat(), GetTicks()); -} -RString ComboSegment::ToString(int dec) const -{ - RString str = "%.0" + IntToString(dec) + "f=%i"; - if (GetCombo() == GetMissCombo()) - { - return ssprintf(str.c_str(), GetBeat(), GetCombo()); - } - str += "=%i"; - return ssprintf(str.c_str(), GetBeat(), GetCombo(), GetMissCombo()); -} - -RString LabelSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) + "f=%s"; - return ssprintf(str.c_str(), GetBeat(), GetLabel().c_str()); -} - -RString BPMSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetBPM()); -} - -RString TimeSignatureSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) + "f=%i=%i"; - return ssprintf(str.c_str(), GetBeat(), GetNum(), GetDen()); -} - -RString SpeedSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f=%.0" - + IntToString(dec) + "f=%u"; - return ssprintf(str.c_str(), GetBeat(), GetRatio(), - GetDelay(), GetUnit()); -} - -void SpeedSegment::Scale( int start, int oldLength, int newLength ) -{ - if( GetUnit() == 0 ) - { - // XXX: this function is duplicated, there should be a better way - float startBeat = GetBeat(); - float endBeat = startBeat + GetDelay(); - float newStartBeat = ScalePosition(NoteRowToBeat(start), - NoteRowToBeat(oldLength), - NoteRowToBeat(newLength), - startBeat); - float newEndBeat = ScalePosition(NoteRowToBeat(start), - NoteRowToBeat(oldLength), - NoteRowToBeat(newLength), - endBeat); - SetDelay( newEndBeat - newStartBeat ); - } - TimingSegment::Scale( start, oldLength, newLength ); -} - -RString ScrollSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetRatio()); -} - -RString StopSegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetPause()); -} - -RString DelaySegment::ToString(int dec) const -{ - const RString str = "%.0" + IntToString(dec) - + "f=%.0" + IntToString(dec) + "f"; - return ssprintf(str.c_str(), GetBeat(), GetPause()); -} - -/** - * @file - * @author Jason Felds (c) 2011 - * @section LICENSE - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, and/or sell copies of the Software, and to permit persons to - * whom the Software is furnished to do so, provided that the above - * copyright notice(s) and this permission notice appear in all copies of - * the Software and that both the above copyright notice(s) and this - * permission notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF - * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS - * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT - * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ +#include "global.h" +#include "TimingSegments.h" +#include "EnumHelper.h" + +const double TimingSegment::EPSILON = 1e-6; + +static const char *TimingSegmentTypeNames[] = { + "BPM", + "Stop", + "Delay", + "Time Sig", + "Warp", + "Label", + "Tickcount", + "Combo", + "Speed", + "Scroll", + "Fake" +}; +XToString( TimingSegmentType ); + +#define LTCOMPARE(x) if(this->x < other.x) return true; if(this->x > other.x) return false; + +void TimingSegment::Scale( int start, int length, int newLength ) +{ + SetRow( ScalePosition( start, length, newLength, this->GetRow() ) ); +} + +void TimingSegment::DebugPrint() const +{ + LOG->Trace( "\tTimingSegment(%d [%f])", GetRow(), GetBeat() ); +} + +void BPMSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %f)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetBPM() + ); +} + +void StopSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %f)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetPause() + ); +} + +void DelaySegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %f)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetPause() + ); +} + +void TimeSignatureSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %d/%d)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetNum(), GetDen() + ); +} + +void WarpSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %d [%f])", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetLengthRows(), GetLengthBeats() + ); +} + +void LabelSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %s)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetLabel().c_str() + ); +} + +void TickcountSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %d)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetTicks() + ); +} + +void ComboSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %d, %d)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetCombo(), GetMissCombo() + ); +} + +void SpeedSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %f, %f, %d)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetRatio(), GetDelay(), GetUnit() + ); +} + +void ScrollSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %f)", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetRatio() + ); +} + +void FakeSegment::DebugPrint() const +{ + LOG->Trace( "\t%s(%d [%f], %d [%f])", + TimingSegmentTypeToString(GetType()).c_str(), + GetRow(), GetBeat(), GetLengthRows(), GetLengthBeats() + ); +} + +RString FakeSegment::ToString(int dec) const +{ + RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetLength()); +} + +void FakeSegment::Scale( int start, int length, int newLength ) +{ + float startBeat = GetBeat(); + float endBeat = startBeat + GetLength(); + float newStartBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), startBeat ); + float newEndBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), endBeat ); + SetLength( newEndBeat - newStartBeat ); + TimingSegment::Scale( start, length, newLength ); +} + +RString WarpSegment::ToString(int dec) const +{ + RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetLength()); +} + +void WarpSegment::Scale( int start, int length, int newLength ) +{ + // XXX: this function is duplicated, there should be a better way + float startBeat = GetBeat(); + float endBeat = startBeat + GetLength(); + float newStartBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), startBeat ); + float newEndBeat = ScalePosition( NoteRowToBeat(start), NoteRowToBeat(length), NoteRowToBeat(newLength), endBeat ); + SetLength( newEndBeat - newStartBeat ); + TimingSegment::Scale( start, length, newLength ); +} + +RString TickcountSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + "f=%i"; + return ssprintf(str.c_str(), GetBeat(), GetTicks()); +} +RString ComboSegment::ToString(int dec) const +{ + RString str = "%.0" + std::to_string(dec) + "f=%i"; + if (GetCombo() == GetMissCombo()) + { + return ssprintf(str.c_str(), GetBeat(), GetCombo()); + } + str += "=%i"; + return ssprintf(str.c_str(), GetBeat(), GetCombo(), GetMissCombo()); +} + +RString LabelSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + "f=%s"; + return ssprintf(str.c_str(), GetBeat(), GetLabel().c_str()); +} + +RString BPMSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetBPM()); +} + +RString TimeSignatureSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + "f=%i=%i"; + return ssprintf(str.c_str(), GetBeat(), GetNum(), GetDen()); +} + +RString SpeedSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f=%.0" + + std::to_string(dec) + "f=%u"; + return ssprintf(str.c_str(), GetBeat(), GetRatio(), + GetDelay(), GetUnit()); +} + +void SpeedSegment::Scale( int start, int oldLength, int newLength ) +{ + if( GetUnit() == 0 ) + { + // XXX: this function is duplicated, there should be a better way + float startBeat = GetBeat(); + float endBeat = startBeat + GetDelay(); + float newStartBeat = ScalePosition(NoteRowToBeat(start), + NoteRowToBeat(oldLength), + NoteRowToBeat(newLength), + startBeat); + float newEndBeat = ScalePosition(NoteRowToBeat(start), + NoteRowToBeat(oldLength), + NoteRowToBeat(newLength), + endBeat); + SetDelay( newEndBeat - newStartBeat ); + } + TimingSegment::Scale( start, oldLength, newLength ); +} + +RString ScrollSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetRatio()); +} + +RString StopSegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetPause()); +} + +RString DelaySegment::ToString(int dec) const +{ + const RString str = "%.0" + std::to_string(dec) + + "f=%.0" + std::to_string(dec) + "f"; + return ssprintf(str.c_str(), GetBeat(), GetPause()); +} + +/** + * @file + * @author Jason Felds (c) 2011 + * @section LICENSE + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */