[timing] All but the Beat <-> Time functions.

Alright Thai...let's see if I can modify your work properly.
This commit is contained in:
Jason Felds
2011-07-27 23:32:37 -04:00
parent 5391b4c11d
commit 18ff542910
4 changed files with 119 additions and 121 deletions
+2 -2
View File
@@ -355,14 +355,14 @@ static bool LoadFromKSFFile( const RString &sPath, Steps &out, Song &song, bool
// DelayBeat
float fCurDelay = 60 / stepsTiming.GetBPMAtBeat(fCurBeat) * numTemp / iTickCount;
fCurDelay += stepsTiming.GetDelayAtRow(BeatToNoteRow(fCurBeat) );
stepsTiming.SetStopAtBeat( fCurBeat, fCurDelay, true );
stepsTiming.SetDelayAtBeat( fCurBeat, fCurDelay );
}
else if (BeginsWith(sRowString, "|D"))
{
// Delays
float fCurDelay = stepsTiming.GetStopAtRow(BeatToNoteRow(fCurBeat) );
fCurDelay += numTemp / 1000;
stepsTiming.SetStopAtBeat( fCurBeat, fCurDelay, true );
stepsTiming.SetDelayAtBeat( fCurBeat, fCurDelay );
}
else if (BeginsWith(sRowString, "|M") || BeginsWith(sRowString, "|C"))
{
+1 -1
View File
@@ -2978,7 +2978,7 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM )
{
float fDelay = StringToFloat( ScreenTextEntry::s_sLastAnswer );
if( fDelay >= 0 )
GetAppropriateTiming().SetStopAtBeat( GetBeat(), fDelay, true );
GetAppropriateTiming().SetDelayAtBeat( GetBeat(), fDelay );
SetDirty( true );
}
else if( SM == SM_BackFromTimeSignatureChange && !ScreenTextEntry::s_bCancelledLast )
+75 -35
View File
@@ -50,11 +50,16 @@ TimingData TimingData::CopyRange(int startRow, int endRow) const
cpy = new BPMSegment(*(static_cast<BPMSegment *>(org)));
break;
}
case SEGMENT_STOP_DELAY:
case SEGMENT_STOP:
{
cpy = new StopSegment(*(static_cast<StopSegment *>(org)));
break;
}
case SEGMENT_DELAY:
{
cpy = new DelaySegment(*(static_cast<DelaySegment *>(org)));
break;
}
case SEGMENT_TIME_SIG:
{
cpy = new TimeSignatureSegment(*(static_cast<TimeSignatureSegment *>(org)));
@@ -136,7 +141,7 @@ void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg)
}
int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst,
int row, bool isDelay) const
int row) const
{
const vector<TimingSegment *> &segs = this->allTimingSegments[tst];
unsigned i = 0;
@@ -145,10 +150,6 @@ int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst,
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;
}
}
@@ -156,7 +157,7 @@ int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst,
}
float TimingData::GetNextSegmentBeatAtRow(TimingSegmentType tst,
int row, bool isDelay) const
int row) const
{
const vector<TimingSegment *> segs = this->allTimingSegments[tst];
for (unsigned i = 0; i < segs.size(); i++ )
@@ -165,15 +166,13 @@ float TimingData::GetNextSegmentBeatAtRow(TimingSegmentType tst,
{
continue;
}
if (tst != SEGMENT_STOP_DELAY ||
static_cast<StopSegment *>(segs[i])->GetDelay() == isDelay)
return segs[i]->GetBeat();
return segs[i]->GetBeat();
}
return NoteRowToBeat(row);
}
float TimingData::GetPreviousSegmentBeatAtRow(TimingSegmentType tst,
int row, bool isDelay) const
int row) const
{
float backup = -1;
const vector<TimingSegment *> segs = this->allTimingSegments[tst];
@@ -183,9 +182,7 @@ float TimingData::GetPreviousSegmentBeatAtRow(TimingSegmentType tst,
{
break;
}
if (tst != SEGMENT_STOP_DELAY ||
static_cast<StopSegment *>(segs[i])->GetDelay() == isDelay)
backup = segs[i]->GetBeat();
backup = segs[i]->GetBeat();
}
return (backup > -1) ? backup : NoteRowToBeat(row);
}
@@ -219,21 +216,20 @@ void TimingData::SetBPMAtRow( int iNoteRow, float fBPM )
}
}
void TimingData::SetStopAtRow( int iRow, float fSeconds, bool bDelay )
void TimingData::SetStopAtRow( int iRow, float fSeconds )
{
unsigned i;
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP];
for( i=0; i<stops.size(); i++ )
if (stops[i]->GetRow() == iRow &&
static_cast<StopSegment *>(stops[i])->GetDelay() == bDelay )
if (stops[i]->GetRow() == iRow)
break;
if( i == stops.size() ) // there is no Stop/Delay Segment at the current beat
if( i == stops.size() ) // there is no StopSegment at the current beat
{
// create a new StopSegment
if( fSeconds > 0 )
{
AddSegment( SEGMENT_STOP_DELAY, new StopSegment(iRow, fSeconds, bDelay) );
AddSegment( SEGMENT_STOP, new StopSegment(iRow, fSeconds) );
}
}
else // StopSegment being modified is m_StopSegments[i]
@@ -248,6 +244,34 @@ void TimingData::SetStopAtRow( int iRow, float fSeconds, bool bDelay )
}
}
void TimingData::SetDelayAtRow( int iRow, float fSeconds )
{
unsigned i;
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_DELAY];
for( i=0; i<stops.size(); i++ )
if (stops[i]->GetRow() == iRow)
break;
if( i == stops.size() ) // there is no DelaySegment at the current beat
{
// create a new DelaySegment
if( fSeconds > 0 )
{
AddSegment( SEGMENT_DELAY, new DelaySegment(iRow, fSeconds) );
}
}
else // DelaySegment being modified is present one
{
DelaySegment *ss = static_cast<DelaySegment *>(stops[i]);
if( fSeconds > 0 )
{
ss->SetPause(fSeconds);
}
else
stops.erase( stops.begin()+i, stops.begin()+i+1 );
}
}
void TimingData::SetTimeSignatureAtRow( int iRow, int iNumerator, int iDenominator )
{
unsigned i;
@@ -526,14 +550,13 @@ void TimingData::SetSpeedModeAtRow( int iRow, unsigned short usMode )
usMode );
}
float TimingData::GetStopAtRow( int iNoteRow, bool bDelay ) const
float TimingData::GetStopAtRow( int iRow ) const
{
const vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
const vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP];
for( unsigned i=0; i<stops.size(); i++ )
{
const StopSegment *s = static_cast<StopSegment *>(stops[i]);
if( s->GetDelay() == bDelay && s->GetRow() == iNoteRow )
if( s->GetRow() == iRow )
{
return s->GetPause();
}
@@ -541,15 +564,19 @@ float TimingData::GetStopAtRow( int iNoteRow, bool bDelay ) const
return 0;
}
float TimingData::GetStopAtRow( int iRow ) const
{
return GetStopAtRow( iRow, false );
}
float TimingData::GetDelayAtRow( int iRow ) const
{
return GetStopAtRow( iRow, true );
const vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_DELAY];
for( unsigned i=0; i<stops.size(); i++ )
{
const DelaySegment *s = static_cast<DelaySegment *>(stops[i]);
if( s->GetRow() == iRow )
{
return s->GetPause();
}
}
return 0;
}
int TimingData::GetComboAtRow( int iNoteRow ) const
@@ -684,7 +711,7 @@ bool TimingData::IsWarpAtRow( int iNoteRow ) const
if( s->GetBeat() <= beatRow && beatRow < (s->GetBeat() + s->GetLength() ) )
{
// Allow stops inside warps to allow things like stop, warp, stop, warp, stop, and so on.
if( this->allTimingSegments[SEGMENT_STOP_DELAY].empty() )
if( this->allTimingSegments[SEGMENT_STOP].empty() && this->allTimingSegments[SEGMENT_DELAY].empty() )
{
return true;
}
@@ -783,16 +810,26 @@ LabelSegment* TimingData::GetLabelSegmentAtRow( int iRow )
return static_cast<LabelSegment *>(labels[i]);
}
StopSegment* TimingData::GetStopSegmentAtRow( int iNoteRow, bool bDelay )
StopSegment* TimingData::GetStopSegmentAtRow( int iNoteRow )
{
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP];
if( stops.empty() )
return new StopSegment();
int i = GetSegmentIndexAtRow( SEGMENT_STOP_DELAY, iNoteRow, bDelay );
int i = GetSegmentIndexAtRow( SEGMENT_STOP, iNoteRow );
return static_cast<StopSegment *>(stops[i]);
}
DelaySegment* TimingData::GetDelaySegmentAtRow( int iNoteRow )
{
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_DELAY];
if( stops.empty() )
return new DelaySegment();
int i = GetSegmentIndexAtRow( SEGMENT_DELAY, iNoteRow );
return static_cast<DelaySegment *>(stops[i]);
}
WarpSegment* TimingData::GetWarpSegmentAtRow( int iRow )
{
vector<TimingSegment *> &warps = this->allTimingSegments[SEGMENT_WARP];
@@ -1300,9 +1337,12 @@ bool TimingData::HasBpmChanges() const
return this->allTimingSegments[SEGMENT_BPM].size()>1;
}
// TODO: Think about splitting this up into HasStops and HasDelays.
bool TimingData::HasStops() const
{
return this->allTimingSegments[SEGMENT_STOP_DELAY].size()>0;
return
this->allTimingSegments[SEGMENT_STOP].size()>0 ||
this->allTimingSegments[SEGMENT_DELAY].size()>0;
}
bool TimingData::HasWarps() const
+41 -83
View File
@@ -19,30 +19,30 @@ public:
void AddSegment(TimingSegmentType tst, TimingSegment * seg);
int GetSegmentIndexAtRow(TimingSegmentType tst,
int row, bool isDelay = false) const;
int row) const;
int GetSegmentIndexAtBeat(TimingSegmentType tst,
float beat, bool isDelay = false) const
float beat) const
{
return this->GetSegmentIndexAtRow(tst, BeatToNoteRow(beat), isDelay);
return this->GetSegmentIndexAtRow(tst, BeatToNoteRow(beat));
}
float GetNextSegmentBeatAtRow(TimingSegmentType tst,
int row, bool isDelay = false) const;
int row) const;
float GetNextSegmentBeatAtBeat(TimingSegmentType tst,
float beat, bool isDelay = false) const
float beat) const
{
return this->GetNextSegmentBeatAtRow(tst, BeatToNoteRow(beat), isDelay);
return this->GetNextSegmentBeatAtRow(tst, BeatToNoteRow(beat));
}
float GetPreviousSegmentBeatAtRow(TimingSegmentType tst,
int row, bool isDelay = false) const;
int row) const;
float GetPreviousSegmentBeatAtBeat(TimingSegmentType tst,
float beat, bool isDelay = false) const
float beat) const
{
return this->GetPreviousSegmentBeatAtRow(tst, BeatToNoteRow(beat), isDelay);
return this->GetPreviousSegmentBeatAtRow(tst, BeatToNoteRow(beat));
}
bool empty() const;
@@ -102,20 +102,6 @@ public:
*/
BPMSegment* GetBPMSegmentAtBeat( float fBeat ) { return GetBPMSegmentAtRow( (int)BeatToNoteRow(fBeat)); }
/**
* @brief Retrieve the Stop/Delay at the given row.
* @param iNoteRow the row in question.
* @param bDelayOut A flag to determine if we are getting a delay or not.
* @return the time we stop at this row.
*/
float GetStopAtRow( int iNoteRow, bool bDelayOut ) const;
/**
* @brief Retrieve the Stop/Delay at the given row.
* @param fBeat the beat in question.
* @param bDelayOut A flag to determine if we are getting a delay or not.
* @return the time we stop at this beat.
*/
float GetStopAtBeat( float fBeat, bool bDelayOut ) const { return GetStopAtRow( BeatToNoteRow(fBeat), bDelayOut ); }
/**
* @brief Retrieve the stop time at the given row.
* @param iNoteRow the row in question.
@@ -128,6 +114,33 @@ public:
* @return the stop time.
*/
float GetStopAtBeat( float fBeat ) const { return GetStopAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Set the row to have the new stop time.
* @param iNoteRow the row to have the new stop time.
* @param fSeconds the new stop time.
*/
void SetStopAtRow( int iNoteRow, float fSeconds );
/**
* @brief Set the beat to have the new stop time.
* @param fBeat to have the new stop time.
* @param fSeconds the new stop time.
*/
void SetStopAtBeat( float fBeat, float fSeconds ) { SetStopAtRow( BeatToNoteRow(fBeat), fSeconds); }
/**
* @brief Retrieve the StopSegment at the specified row.
* @param iNoteRow the row that has a StopSegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtRow( int iNoteRow );
/**
* @brief Retrieve the StopSegment at the specified beat.
* @param fBeat the beat that has a StopSegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtBeat( float fBeat ) { return GetStopSegmentAtRow( BeatToNoteRow(fBeat)); }
/**
* @brief Retrieve the delay time at the given row.
* @param iNoteRow the row in question.
@@ -140,21 +153,7 @@ public:
* @return the delay time.
*/
float GetDelayAtBeat( float fBeat ) const { return GetDelayAtRow( BeatToNoteRow(fBeat) ); }
/**
* @brief Set the row to have the new stop time.
* @param iNoteRow the row to have the new stop time.
* @param fSeconds the new stop time.
*/
void SetStopAtRow( int iNoteRow, float fSeconds ) { SetStopAtRow( iNoteRow, fSeconds, false ); }
/**
* @brief Set the row to have the new pause time.
*
* This function was added specifically for sm-ssc.
* @param iNoteRow the row to have the new pause time.
* @param fSeconds the new pause time.
* @param bDelay If true, this is a Delay Segment. Otherwise, it is a StopSegment.
*/
void SetStopAtRow( int iNoteRow, float fSeconds, bool bDelay );
/**
* @brief Set the row to have the new delay time.
*
@@ -162,22 +161,7 @@ public:
* @param iNoteRow the row to have the new delay time.
* @param fSeconds the new delay time.
*/
void SetDelayAtRow( int iNoteRow, float fSeconds ) { SetStopAtRow( iNoteRow, fSeconds, true ); }
/**
* @brief Set the beat to have the new stop time.
* @param fBeat to have the new stop time.
* @param fSeconds the new stop time.
*/
void SetStopAtBeat( float fBeat, float fSeconds ) { SetStopAtRow( BeatToNoteRow(fBeat), fSeconds, false ); }
/**
* @brief Set the beat to have the new pause time.
*
* This function was added specifically for sm-ssc.
* @param fBeat the beat to have the new pause time.
* @param fSeconds the new pause time.
* @param bDelay If true, this is a Delay Segment. Otherwise, it is a StopSegment.
*/
void SetStopAtBeat( float fBeat, float fSeconds, bool bDelay ) { SetStopAtRow( BeatToNoteRow(fBeat), fSeconds, bDelay ); }
void SetDelayAtRow( int iNoteRow, float fSeconds );
/**
* @brief Set the beat to have the new delay time.
*
@@ -185,45 +169,19 @@ public:
* @param fBeat the beat to have the new delay time.
* @param fSeconds the new delay time.
*/
void SetDelayAtBeat( float fBeat, float fSeconds ) { SetStopAtRow( BeatToNoteRow(fBeat), fSeconds, true ); }
/**
* @brief Retrieve the StopSegment at the specified row.
* @param iNoteRow the row that has a StopSegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtRow( int iNoteRow ) { return GetStopSegmentAtRow( iNoteRow, false ); }
/**
* @brief Retrieve the StopSegment at the specified beat.
* @param fBeat the beat that has a StopSegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtBeat( float fBeat ) { return GetStopSegmentAtRow( BeatToNoteRow(fBeat), false); }
/**
* @brief Retrieve the StopSegment at the specified row.
* @param iNoteRow the row that has a StopSegment.
* @param bDelay If true, this is actually a DelaySegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtRow( int iNoteRow, bool bDelay );
/**
* @brief Retrieve the StopSegment at the specified beat.
* @param fBeat the beat that has a StopSegment.
* @param bDelay If true, this is actually a DelaySegment.
* @return the StopSegment in question.
*/
StopSegment* GetStopSegmentAtBeat( float fBeat, bool bDelay ) { return GetStopSegmentAtRow( BeatToNoteRow(fBeat), bDelay ); }
void SetDelayAtBeat( float fBeat, float fSeconds ) { SetDelayAtRow( BeatToNoteRow(fBeat), fSeconds); }
/**
* @brief Retrieve the DelaySegment at the specified row.
* @param iNoteRow the row that has a DelaySegment.
* @return the DelaySegment in question.
*/
StopSegment* GetDelaySegmentAtRow( int iNoteRow ) { return GetStopSegmentAtRow( iNoteRow, true ); }
DelaySegment* GetDelaySegmentAtRow( int iNoteRow );
/**
* @brief Retrieve the DelaySegment at the specified beat.
* @param fBeat the beat that has a DelaySegment.
* @return the DelaySegment in question.
*/
StopSegment* GetDelaySegmentAtBeat( float fBeat ) { return GetStopSegmentAtRow( BeatToNoteRow(fBeat), true); }
DelaySegment* GetDelaySegmentAtBeat( float fBeat ) { return GetDelaySegmentAtRow( BeatToNoteRow(fBeat)); }
/**
* @brief Retrieve the Time Signature's numerator at the given row.