let SpeedSegment scale itself.

also fixes the bug where the segments outside of the scaling region are scaled too.
This commit is contained in:
Thai Pangsakulyanont
2011-07-01 22:40:57 +07:00
parent 25ffddeb70
commit 9a1a824f22
3 changed files with 17 additions and 6 deletions
+1 -6
View File
@@ -1332,12 +1332,7 @@ void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool
m_LabelSegments[i].Scale( iStartIndex, length, newLength ); m_LabelSegments[i].Scale( iStartIndex, length, newLength );
for ( unsigned i = 0; i < m_SpeedSegments.size(); i++ ) for ( unsigned i = 0; i < m_SpeedSegments.size(); i++ )
{ m_SpeedSegments[i].Scale( iStartIndex, length, newLength );
SpeedSegment &s = m_SpeedSegments[i];
s.Scale( iStartIndex, length, newLength );
if (s.GetUnit() == 0) // beats
s.SetLength(s.GetLength() * fScale);
}
for( unsigned i = 0; i < m_FakeSegments.size(); i++ ) for( unsigned i = 0; i < m_FakeSegments.size(); i++ )
m_FakeSegments[i].Scale( iStartIndex, length, newLength ); m_FakeSegments[i].Scale( iStartIndex, length, newLength );
+14
View File
@@ -250,6 +250,20 @@ void SpeedSegment::SetUnit(const int i)
this->unit = static_cast<unsigned short>(i); this->unit = static_cast<unsigned short>(i);
} }
void SpeedSegment::Scale( int start, int length, int newLength )
{
if( GetUnit() == 0 )
{
// 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<SpeedSegment>::Scale( start, length, newLength );
}
bool SpeedSegment::operator<( const SpeedSegment &other ) const bool SpeedSegment::operator<( const SpeedSegment &other ) const
{ {
LTCOMPARE(GetRow()); LTCOMPARE(GetRow());
+2
View File
@@ -681,6 +681,8 @@ struct SpeedSegment : public TimingSegment<SpeedSegment>
* @param i the unit. */ * @param i the unit. */
void SetUnit(const int i); void SetUnit(const int i);
void Scale( int start, int length, int newLength );
/** /**
* @brief Compares two SpeedSegments to see if one is less than the other. * @brief Compares two SpeedSegments to see if one is less than the other.
* @param other the other SpeedSegment to compare to. * @param other the other SpeedSegment to compare to.