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
|
|
|
|
2011-05-31 19:39:28 +07: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-06-26 13:43:30 +07:00
|
|
|
{
|
2011-07-14 11:00:43 -04:00
|
|
|
SetRow( ScalePosition( start, length, newLength, this->GetRow() ) );
|
2011-06-26 13:43:30 +07:00
|
|
|
}
|
|
|
|
|
|
2011-09-15 03:28:58 +00:00
|
|
|
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()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetLength());
|
2011-05-31 00:51:25 -04:00
|
|
|
}
|
|
|
|
|
|
2011-06-26 13:43:30 +07: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 );
|
2011-06-26 13:43:30 +07:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetLength());
|
2011-05-31 10:59:18 -04:00
|
|
|
}
|
|
|
|
|
|
2011-06-26 13:43:30 +07: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 );
|
2011-06-26 13:43:30 +07:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetTicks());
|
2011-05-31 15:27:27 -04:00
|
|
|
}
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> ComboSegment::GetValues() const
|
2014-03-09 10:19:52 -06:00
|
|
|
{
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> ret;
|
2014-03-09 10:19:52 -06:00
|
|
|
ret.push_back(GetCombo());
|
|
|
|
|
ret.push_back(GetMissCombo());
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetLabel().c_str());
|
2011-05-31 15:27:27 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetBPM());
|
2011-05-31 15:27:27 -04:00
|
|
|
}
|
2011-05-31 23:41:39 +07:00
|
|
|
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetNum(), GetDen());
|
2011-05-31 15:27:27 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> TimeSignatureSegment::GetValues() const
|
2014-03-09 10:19:52 -06:00
|
|
|
{
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> ret;
|
2014-03-09 10:19:52 -06:00
|
|
|
ret.push_back(GetNum());
|
|
|
|
|
ret.push_back(GetDen());
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetRatio(),
|
2015-11-18 20:07:49 -07:00
|
|
|
GetDelay(), static_cast<unsigned int>(GetUnit()));
|
2011-05-31 15:27:27 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> SpeedSegment::GetValues() const
|
2014-03-09 10:19:52 -06:00
|
|
|
{
|
2022-07-10 18:28:56 +03:00
|
|
|
std::vector<float> ret;
|
2014-03-09 10:19:52 -06:00
|
|
|
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();
|
2011-09-11 17:13:10 +00:00
|
|
|
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);
|
2011-09-11 17:13:10 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetRatio());
|
2011-06-01 08:44:09 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetPause());
|
2011-06-01 08:44:09 -04:00
|
|
|
}
|
2011-05-31 23:41:39 +07:00
|
|
|
|
2011-09-11 17:13:10 +00: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";
|
2011-09-11 17:13:10 +00:00
|
|
|
return ssprintf(str.c_str(), GetBeat(), GetPause());
|
2011-06-01 09:50:34 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-31 00:17:46 -04:00
|
|
|
/**
|
|
|
|
|
* @file
|
2011-09-11 17:13:10 +00:00
|
|
|
* @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.
|
|
|
|
|
*/
|