Refactor TimingData::ScaleRegion(), fixes 297.

This commit is contained in:
Thai Pangsakulyanont
2011-06-26 13:43:30 +07:00
parent c71789b7e7
commit 68f95ce056
4 changed files with 70 additions and 124 deletions
+27 -2
View File
@@ -5,7 +5,6 @@
BaseTimingSegment::~BaseTimingSegment() {}
void BaseTimingSegment::SetRow(const int s)
{
this->startingRow = s;
@@ -26,6 +25,11 @@ float BaseTimingSegment::GetBeat() const
return NoteRowToBeat(GetRow());
}
void BaseTimingSegment::Scale( int start, int length, int newLength )
{
SetRow( ScalePosition( start, length, newLength, GetRow() ) );
}
/* ======================================================
Here comes the actual timing segments implementation!! */
@@ -40,6 +44,16 @@ void FakeSegment::SetLength(const float b)
this->lengthBeats = b;
}
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<FakeSegment>::Scale( start, length, newLength );
}
bool FakeSegment::operator<( const FakeSegment &other ) const
{
LTCOMPARE(GetRow());
@@ -60,8 +74,19 @@ void WarpSegment::SetLength(const float b)
this->lengthBeats = b;
}
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<WarpSegment>::Scale( start, length, newLength );
}
bool WarpSegment::operator<( const WarpSegment &other ) const
{
{
LTCOMPARE(GetRow());
LTCOMPARE(GetLength());
return false;