Files
itgmania212121/src/TimingSegments.cpp
T

293 lines
8.1 KiB
C++
Raw Normal View History

2011-05-31 22:25:53 -04:00
#include "global.h"
2011-05-31 00:17:46 -04:00
#include "TimingSegments.h"
2011-07-14 23:54:06 -04:00
#include "EnumHelper.h"
2023-04-20 19:02:13 +02:00
#include <vector>
2011-07-14 23:54:06 -04:00
static const char *TimingSegmentTypeNames[] = {
"BPM",
2011-07-27 22:20:52 -04:00
"Stop",
"Delay",
2011-07-14 23:54:06 -04:00
"Time Sig",
"Warp",
"Label",
"Tickcount",
"Combo",
"Speed",
"Scroll",
"Fake"
};
XToString( TimingSegmentType );
2011-05-31 00:17:46 -04:00
#define LTCOMPARE(x) if(this->x < other.x) return true; if(this->x > other.x) return false;
2011-05-31 00:17:46 -04:00
2011-07-14 11:00:43 -04:00
void TimingSegment::Scale( int start, int length, int newLength )
{
2011-07-14 11:00:43 -04:00
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
2011-05-31 00:51:25 -04:00
{
2019-06-22 12:35:38 -07:00
RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetLength());
2011-05-31 00:51:25 -04:00
}
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 );
2011-07-14 11:00:43 -04:00
TimingSegment::Scale( start, length, newLength );
}
RString WarpSegment::ToString(int dec) const
2011-05-31 10:59:18 -04:00
{
2019-06-22 12:35:38 -07:00
RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetLength());
2011-05-31 10:59:18 -04:00
}
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 );
2011-07-14 11:00:43 -04:00
TimingSegment::Scale( start, length, newLength );
}
RString TickcountSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec) + "f=%i";
return ssprintf(str.c_str(), GetBeat(), GetTicks());
2011-05-31 15:27:27 -04:00
}
RString ComboSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
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());
2011-05-31 15:27:27 -04:00
}
std::vector<float> ComboSegment::GetValues() const
{
std::vector<float> ret;
ret.push_back(GetCombo());
ret.push_back(GetMissCombo());
return ret;
}
RString LabelSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec) + "f=%s";
return ssprintf(str.c_str(), GetBeat(), GetLabel().c_str());
2011-05-31 15:27:27 -04:00
}
RString BPMSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetBPM());
2011-05-31 15:27:27 -04:00
}
2011-05-31 23:41:39 +07:00
RString TimeSignatureSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec) + "f=%i=%i";
return ssprintf(str.c_str(), GetBeat(), GetNum(), GetDen());
2011-05-31 15:27:27 -04:00
}
std::vector<float> TimeSignatureSegment::GetValues() const
{
std::vector<float> ret;
ret.push_back(GetNum());
ret.push_back(GetDen());
return ret;
}
RString SpeedSegment::ToString(int dec) const
2011-05-31 15:27:27 -04:00
{
2019-06-22 12:35:38 -07:00
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(), static_cast<unsigned int>(GetUnit()));
2011-05-31 15:27:27 -04:00
}
std::vector<float> SpeedSegment::GetValues() const
{
std::vector<float> ret;
ret.push_back(GetRatio());
ret.push_back(GetDelay());
ret.push_back(GetUnit());
return ret;
}
2011-07-04 21:22:05 -04:00
void SpeedSegment::Scale( int start, int oldLength, int newLength )
2011-07-01 22:40:57 +07:00
{
if( GetUnit() == 0 )
{
// XXX: this function is duplicated, there should be a better way
float startBeat = GetBeat();
float endBeat = startBeat + GetDelay();
2011-07-04 21:22:05 -04:00
float newStartBeat = ScalePosition(NoteRowToBeat(start),
NoteRowToBeat(oldLength),
NoteRowToBeat(newLength),
startBeat);
float newEndBeat = ScalePosition(NoteRowToBeat(start),
NoteRowToBeat(oldLength),
NoteRowToBeat(newLength),
endBeat);
SetDelay( newEndBeat - newStartBeat );
2011-07-01 22:40:57 +07:00
}
2011-07-14 11:00:43 -04:00
TimingSegment::Scale( start, oldLength, newLength );
2011-07-01 22:40:57 +07:00
}
RString ScrollSegment::ToString(int dec) const
2011-06-01 08:44:09 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetRatio());
2011-06-01 08:44:09 -04:00
}
RString StopSegment::ToString(int dec) const
2011-06-01 08:44:09 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetPause());
2011-06-01 08:44:09 -04:00
}
2011-05-31 23:41:39 +07:00
RString DelaySegment::ToString(int dec) const
2011-06-01 09:50:34 -04:00
{
2019-06-22 12:35:38 -07:00
const RString str = "%.0" + std::to_string(dec)
+ "f=%.0" + std::to_string(dec) + "f";
return ssprintf(str.c_str(), GetBeat(), GetPause());
2011-06-01 09:50:34 -04:00
}
2011-05-31 00:17:46 -04:00
/**
* @file
* @author Jason Felds (c) 2011
2011-05-31 00:17:46 -04:00
* @section LICENSE
* All rights reserved.
2023-04-20 19:02:13 +02:00
*
2011-05-31 00:17:46 -04:00
* 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.
2023-04-20 19:02:13 +02:00
*
2011-05-31 00:17:46 -04:00
* 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.
*/