[timing] More abstractions of common functions.

This commit is contained in:
Jason Felds
2011-07-14 21:51:09 -04:00
parent 48a8113336
commit 6255a84be4
2 changed files with 41 additions and 265 deletions
+32 -117
View File
@@ -44,6 +44,26 @@ void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg)
segs.insert(upper_bound(segs.begin(), segs.end(), seg), seg);
}
int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst,
int row, bool isDelay) const
{
const vector<TimingSegment *> &segs = this->allTimingSegments[tst];
unsigned i = 0;
for (; i < segs.size() - 1; i++)
{
TimingSegment *seg = segs[i+1];
if (seg->GetRow() > row)
{
// put conditions here for individual segments.
if (tst == SEGMENT_STOP_DELAY &&
static_cast<StopSegment *>(seg)->GetDelay() != isDelay)
continue;
break;
}
}
return static_cast<int>(i);
}
// TODO: Find a way to combine all of these SetAtRows to one.
/* Change an existing BPM segment, merge identical segments together or insert a new one. */
@@ -417,17 +437,17 @@ float TimingData::GetDelayAtRow( int iRow ) const
int TimingData::GetComboAtRow( int iNoteRow ) const
{
return m_ComboSegments[this->GetComboSegmentIndexAtRow(iNoteRow)].GetCombo();
return m_ComboSegments[this->GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow)].GetCombo();
}
int TimingData::GetMissComboAtRow(int iNoteRow) const
{
return m_ComboSegments[this->GetComboSegmentIndexAtRow(iNoteRow)].GetMissCombo();
return m_ComboSegments[this->GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow)].GetMissCombo();
}
RString TimingData::GetLabelAtRow( int iRow ) const
{
return m_LabelSegments[GetLabelSegmentIndexAtRow( iRow )].GetLabel();
return m_LabelSegments[GetSegmentIndexAtRow(SEGMENT_LABEL, iRow)].GetLabel();
}
float TimingData::GetWarpAtRow( int iWarpRow ) const
@@ -523,57 +543,12 @@ float TimingData::GetBPMAtRow( int iNoteRow ) const
return m_BPMSegments[i].GetBPM();
}
int TimingData::GetBPMSegmentIndexAtRow( int iNoteRow ) const
{
unsigned i;
for( i=0; i<m_BPMSegments.size()-1; i++ )
if( m_BPMSegments[i+1].GetRow() > iNoteRow )
break;
return static_cast<int>(i);
}
int TimingData::GetStopSegmentIndexAtRow( int iNoteRow, bool bDelay ) const
{
unsigned i;
for( i=0; i<m_StopSegments.size()-1; i++ )
{
const StopSegment& s = m_StopSegments[i+1];
if( s.GetRow() > iNoteRow && s.GetDelay() == bDelay )
break;
}
return static_cast<int>(i);
}
int TimingData::GetWarpSegmentIndexAtRow( int iNoteRow ) const
{
unsigned i;
for( i=0; i<m_WarpSegments.size()-1; i++ )
{
const WarpSegment& s = m_WarpSegments[i+1];
if( s.GetRow() > iNoteRow )
break;
}
return static_cast<int>(i);
}
int TimingData::GetFakeSegmentIndexAtRow( int iNoteRow ) const
{
unsigned i;
for( i=0; i<m_FakeSegments.size()-1; i++ )
{
const FakeSegment& s = m_FakeSegments[i+1];
if( s.GetRow() > iNoteRow )
break;
}
return static_cast<int>(i);
}
bool TimingData::IsWarpAtRow( int iNoteRow ) const
{
if( m_WarpSegments.empty() )
return false;
int i = GetWarpSegmentIndexAtRow( iNoteRow );
int i = GetSegmentIndexAtRow( SEGMENT_WARP, iNoteRow );
const WarpSegment& s = m_WarpSegments[i];
float beatRow = NoteRowToBeat(iNoteRow);
if( s.GetBeat() <= beatRow && beatRow < (s.GetBeat() + s.GetLength() ) )
@@ -597,7 +572,7 @@ bool TimingData::IsFakeAtRow( int iNoteRow ) const
if( m_FakeSegments.empty() )
return false;
int i = GetFakeSegmentIndexAtRow( iNoteRow );
int i = GetSegmentIndexAtRow( SEGMENT_FAKE, iNoteRow );
const FakeSegment& s = m_FakeSegments[i];
float beatRow = NoteRowToBeat(iNoteRow);
if( s.GetBeat() <= beatRow && beatRow < ( s.GetBeat() + s.GetLength() ) )
@@ -607,64 +582,13 @@ bool TimingData::IsFakeAtRow( int iNoteRow ) const
return false;
}
int TimingData::GetTimeSignatureSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for (i=0; i < m_vTimeSignatureSegments.size() - 1; i++ )
if( m_vTimeSignatureSegments[i+1].GetRow() > iRow )
break;
return static_cast<int>(i);
}
int TimingData::GetComboSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for( i=0; i<m_ComboSegments.size()-1; i++ )
{
const ComboSegment& s = m_ComboSegments[i+1];
if( s.GetRow() > iRow )
break;
}
return static_cast<int>(i);
}
int TimingData::GetLabelSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for( i=0; i<m_LabelSegments.size()-1; i++ )
{
const LabelSegment& s = m_LabelSegments[i+1];
if( s.GetRow() > iRow )
break;
}
return static_cast<int>(i);
}
int TimingData::GetSpeedSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for (i=0; i < m_SpeedSegments.size() - 1; i++ )
if( m_SpeedSegments[i+1].GetRow() > iRow )
break;
return static_cast<int>(i);
}
int TimingData::GetScrollSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for (i=0; i < m_ScrollSegments.size() - 1; i++ )
if( m_ScrollSegments[i+1].GetRow() > iRow )
break;
return static_cast<int>(i);
}
BPMSegment& TimingData::GetBPMSegmentAtRow( int iNoteRow )
{
static BPMSegment empty;
if( m_BPMSegments.empty() )
return empty;
int i = GetBPMSegmentIndexAtRow( iNoteRow );
int i = GetSegmentIndexAtRow( SEGMENT_BPM, iNoteRow );
return m_BPMSegments[i];
}
@@ -729,7 +653,7 @@ StopSegment& TimingData::GetStopSegmentAtRow( int iNoteRow, bool bDelay )
if( m_StopSegments.empty() )
return empty;
int i = GetStopSegmentIndexAtRow( iNoteRow, bDelay );
int i = GetSegmentIndexAtRow( SEGMENT_STOP_DELAY, iNoteRow, bDelay );
return m_StopSegments[i];
}
@@ -739,7 +663,7 @@ WarpSegment& TimingData::GetWarpSegmentAtRow( int iRow )
if( m_WarpSegments.empty() )
return empty;
int i = GetWarpSegmentIndexAtRow( iRow );
int i = GetSegmentIndexAtRow( SEGMENT_WARP, iRow );
return m_WarpSegments[i];
}
@@ -749,32 +673,23 @@ FakeSegment& TimingData::GetFakeSegmentAtRow( int iRow )
if( m_FakeSegments.empty() )
return empty;
int i = GetFakeSegmentIndexAtRow( iRow );
int i = GetSegmentIndexAtRow( SEGMENT_FAKE, iRow );
return m_FakeSegments[i];
}
int TimingData::GetTickcountSegmentIndexAtRow( int iRow ) const
{
unsigned i;
for (i=0; i < m_TickcountSegments.size() - 1; i++ )
if( m_TickcountSegments[i+1].GetRow() > iRow )
break;
return static_cast<int>(i);
}
TickcountSegment& TimingData::GetTickcountSegmentAtRow( int iRow )
{
static TickcountSegment empty;
if( m_TickcountSegments.empty() )
return empty;
int i = GetTickcountSegmentIndexAtBeat( iRow );
int i = GetSegmentIndexAtRow( SEGMENT_TICKCOUNT, iRow );
return m_TickcountSegments[i];
}
int TimingData::GetTickcountAtRow( int iRow ) const
{
return m_TickcountSegments[GetTickcountSegmentIndexAtRow( iRow )].GetTicks();
return m_TickcountSegments[GetSegmentIndexAtRow( SEGMENT_TICKCOUNT, iRow )].GetTicks();
}
float TimingData::GetPreviousBPMSegmentBeatAtRow( int iRow ) const
@@ -1457,7 +1372,7 @@ float TimingData::GetDisplayedSpeedPercent( float fSongBeat, float fMusicSeconds
if( m_SpeedSegments.size() == 0 )
return 1.0f;
const int index = GetSpeedSegmentIndexAtBeat( fSongBeat );
const int index = GetSegmentIndexAtBeat( SEGMENT_SPEED, fSongBeat );
const SpeedSegment &seg = m_SpeedSegments[index];
float fStartBeat = seg.GetBeat();
+9 -148
View File
@@ -18,6 +18,15 @@ class TimingData
public:
void AddSegment(TimingSegmentType tst, TimingSegment * seg);
int GetSegmentIndexAtRow(TimingSegmentType tst,
int row, bool isDelay = false) const;
int GetSegmentIndexAtBeat(TimingSegmentType tst,
float beat, bool isDelay = false) const
{
return this->GetSegmentIndexAtRow(tst, BeatToNoteRow(beat), isDelay);
}
/**
* @brief Sets up initial timing data with a defined offset.
* @param fOffset the offset from the 0th beat. */
@@ -70,18 +79,6 @@ public:
* @return the BPMSegment in question.
*/
BPMSegment& GetBPMSegmentAtBeat( float fBeat ) { return GetBPMSegmentAtRow( (int)BeatToNoteRow(fBeat)); }
/**
* @brief Retrieve the index of the BPMSegments at the specified row.
* @param iNoteRow the row that has a BPMSegment.
* @return the BPMSegment's index in question.
*/
int GetBPMSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the BPMSegments at the specified beat.
* @param fBeat the beat that has a BPMSegment.
* @return the BPMSegment's index in question.
*/
int GetBPMSegmentIndexAtBeat( float fBeat ) const { return GetBPMSegmentIndexAtRow( BeatToNoteRow(fBeat)); }
/**
* @brief Retrieve the next beat that contains a BPMSegment.
@@ -242,45 +239,6 @@ public:
* @param iNoteRow the row that has a StopSegment.
* @return the StopSegment's index in question.
*/
int GetStopSegmentIndexAtRow( int iNoteRow ) const { return GetStopSegmentIndexAtRow( iNoteRow, false ); }
/**
* @brief Retrieve the index of the StopSegments at the specified beat.
* @param fBeat the beat that has a StopSegment.
* @return the StopSegment's index in question.
*/
int GetStopSegmentIndexAtBeat( float fBeat ) const { return GetStopSegmentIndexAtRow( BeatToNoteRow(fBeat), false ); }
/**
* @brief Retrieve the index of the StopSegments at the specified row.
* @param iNoteRow the row that has a StopSegment.
* @param bDelay If true, it's a Delay Segment. Otherwise, it's a StopSegment.
* @return the StopSegment's index in question.
*/
int GetStopSegmentIndexAtRow( int iNoteRow, bool bDelay ) const;
/**
* @brief Retrieve the index of the StopSegments at the specified beat.
* @param fBeat the beat that has a StopSegment.
* @param bDelay If true, it's a Delay Segment. Otherwise, it's a StopSegment.
* @return the StopSegment's index in question.
*/
int GetStopSegmentIndexAtBeat( float fBeat, bool bDelay ) const { return GetStopSegmentIndexAtRow( BeatToNoteRow(fBeat), bDelay ); }
/**
* @brief Retrieve the index of the Delay Segments at the specified row.
* @param iNoteRow the row that has a Delay Segment.
* @return the StopSegment's index in question.
*/
int GetDelaySegmentIndexAtRow( int iNoteRow ) const { return GetStopSegmentIndexAtRow( iNoteRow, true ); }
/**
* @brief Retrieve the index of the Delay Segments at the specified beat.
* @param fBeat the beat that has a Delay Segment.
* @return the StopSegment's index in question.
*/
int GetDelaySegmentIndexAtBeat( float fBeat ) const { return GetStopSegmentIndexAtRow( BeatToNoteRow(fBeat), true ); }
/**
* @brief Retrieve the next beat that contains a StopSegment.
* @param iRow the present row.
* @return the next beat with a StopSegment, or fBeat if there is none ahead.
*/
float GetNextStopSegmentBeatAtRow( int iRow ) const;
/**
* @brief Retrieve the previous beat that contains a StopSegment.
@@ -412,18 +370,6 @@ public:
* @return the TimeSignatureSegment in question.
*/
TimeSignatureSegment& GetTimeSignatureSegmentAtBeat( float fBeat ) { return GetTimeSignatureSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the TimeSignatureSegments at the specified row.
* @param iNoteRow the row that has a TimeSignatureSegment.
* @return the TimeSignatureSegment's index in question.
*/
int GetTimeSignatureSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the TimeSignatureSegments at the specified beat.
* @param fBeat the beat that has a TimeSignatureSegment.
* @return the TimeSignatureSegment's index in question.
*/
int GetTimeSignatureSegmentIndexAtBeat( float fBeat ) const { return GetTimeSignatureSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
/**
@@ -493,18 +439,6 @@ public:
* @return the WarpSegment in question.
*/
WarpSegment& GetWarpSegmentAtBeat( float fBeat ) { return GetWarpSegmentAtRow( BeatToNoteRow( fBeat ) ); }
/**
* @brief Retrieve the index of the WarpSegment at the specified row.
* @param iRow the row to focus on.
* @return the index in question.
*/
int GetWarpSegmentIndexAtRow( int iRow ) const;
/**
* @brief Retrieve the index of the WarpSegment at the specified beat.
* @param fBeat the beat to focus on.
* @return the index in question.
*/
int GetWarpSegmentIndexAtBeat( float fBeat ) const { return GetWarpSegmentIndexAtRow( BeatToNoteRow( fBeat ) ); }
/**
* @brief Checks if the row is inside a warp.
* @param iRow the row to focus on.
@@ -586,18 +520,6 @@ public:
* @return the TickcountSegment in question.
*/
TickcountSegment& GetTickcountSegmentAtBeat( float fBeat ) { return GetTickcountSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the TickcountSegments at the specified row.
* @param iNoteRow the row that has a TickcountSegment.
* @return the TickcountSegment's index in question.
*/
int GetTickcountSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the TickcountSegments at the specified beat.
* @param fBeat the beat that has a TickcountSegment.
* @return the TickcountSegment's index in question.
*/
int GetTickcountSegmentIndexAtBeat( float fBeat ) const { return GetTickcountSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the next beat that contains a TickcountSegment.
@@ -717,18 +639,6 @@ public:
* @return the ComboSegment in question.
*/
ComboSegment& GetComboSegmentAtBeat( float fBeat ) { return GetComboSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the ComboSegments at the specified row.
* @param iNoteRow the row that has a ComboSegment.
* @return the ComboSegment's index in question.
*/
int GetComboSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the ComboSegments at the specified beat.
* @param fBeat the beat that has a ComboSegment.
* @return the ComboSegment's index in question.
*/
int GetComboSegmentIndexAtBeat( float fBeat ) const { return GetComboSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the next beat that contains a ComboSegment.
@@ -798,18 +708,6 @@ public:
* @return the LabelSegment in question.
*/
LabelSegment& GetLabelSegmentAtBeat( float fBeat ) { return GetLabelSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the LabelSegments at the specified row.
* @param iNoteRow the row that has a LabelSegment.
* @return the LabelSegment's index in question.
*/
int GetLabelSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the LabelSegments at the specified beat.
* @param fBeat the beat that has a LabelSegment.
* @return the LabelSegment's index in question.
*/
int GetLabelSegmentIndexAtBeat( float fBeat ) const { return GetLabelSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the previous beat that contains a LabelSegment.
@@ -950,18 +848,6 @@ public:
* @return the SpeedSegment in question.
*/
SpeedSegment& GetSpeedSegmentAtBeat( float fBeat ) { return GetSpeedSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the SpeedSegments at the specified row.
* @param iNoteRow the row that has a SpeedSegment.
* @return the SpeedSegment's index in question.
*/
int GetSpeedSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the SpeedSegments at the specified beat.
* @param fBeat the beat that has a SpeedSegment.
* @return the SpeedSegment's index in question.
*/
int GetSpeedSegmentIndexAtBeat( float fBeat ) const { return GetSpeedSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
float GetDisplayedSpeedPercent( float fBeat, float fMusicSeconds ) const;
@@ -1036,19 +922,6 @@ public:
*/
ScrollSegment& GetScrollSegmentAtBeat( float fBeat ) { return GetScrollSegmentAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the index of the ScrollSegment at the specified row.
* @param iNoteRow the row that has a ScrollSegment.
* @return the ScrollSegment's index in question.
*/
int GetScrollSegmentIndexAtRow( int iNoteRow ) const;
/**
* @brief Retrieve the index of the ScrollSegment at the specified beat.
* @param fBeat the beat that has a ScrollSegment.
* @return the ScrollSegment's index in question.
*/
int GetScrollSegmentIndexAtBeat( float fBeat ) const { return GetScrollSegmentIndexAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Retrieve the next beat that contains a ScrollSegment.
* @param iRow the present row.
@@ -1117,18 +990,6 @@ public:
* @return the FakeSegment in question.
*/
FakeSegment& GetFakeSegmentAtBeat( float fBeat ) { return GetFakeSegmentAtRow( BeatToNoteRow( fBeat ) ); }
/**
* @brief Retrieve the index of the FakeSegment at the specified row.
* @param iRow the row to focus on.
* @return the index in question.
*/
int GetFakeSegmentIndexAtRow( int iRow ) const;
/**
* @brief Retrieve the index of the FakeSegment at the specified beat.
* @param fBeat the beat to focus on.
* @return the index in question.
*/
int GetFakeSegmentIndexAtBeat( float fBeat ) const { return GetFakeSegmentIndexAtRow( BeatToNoteRow( fBeat ) ); }
/**
* @brief Checks if the row is inside a fake.
* @param iRow the row to focus on.