[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
+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