2011-03-17 01:47:30 -04:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "TimingData.h"
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "NoteTypes.h"
|
|
|
|
|
#include "Foreach.h"
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
TimingData::TimingData(float fOffset) : m_fBeat0OffsetInSeconds(fOffset)
|
2011-07-14 12:31:42 -04:00
|
|
|
{
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 19:29:52 -04:00
|
|
|
TimingData::~TimingData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-26 14:10:51 -04:00
|
|
|
bool TimingData::empty() const
|
|
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < NUM_TimingSegmentType; i++)
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
if (m_avpTimingSegments[i].size() > 0)
|
2011-07-26 14:10:51 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-26 14:13:10 -04:00
|
|
|
TimingData TimingData::CopyRange(int startRow, int endRow) const
|
2011-07-26 13:41:41 -04:00
|
|
|
{
|
2011-07-26 16:05:14 -04:00
|
|
|
TimingData ret;
|
2011-07-26 13:41:41 -04:00
|
|
|
|
2011-07-26 16:05:14 -04:00
|
|
|
FOREACH_ENUM(TimingSegmentType, tst)
|
2011-07-26 13:41:41 -04:00
|
|
|
{
|
2011-07-26 16:05:14 -04:00
|
|
|
unsigned cnt = 0;
|
2011-09-10 03:08:59 +00:00
|
|
|
for (unsigned j = 0; j < m_avpTimingSegments[tst].size(); j++)
|
2011-07-26 13:41:41 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
int row = m_avpTimingSegments[tst][j]->GetRow();
|
2011-07-26 13:41:41 -04:00
|
|
|
if (row >= startRow && row < endRow)
|
|
|
|
|
{
|
2011-07-26 16:05:14 -04:00
|
|
|
// TODO: This REALLY needs improving.
|
2011-09-10 03:08:59 +00:00
|
|
|
TimingSegment * org = m_avpTimingSegments[tst][j];
|
2011-07-26 16:05:14 -04:00
|
|
|
TimingSegment * cpy;
|
|
|
|
|
|
|
|
|
|
switch (tst)
|
|
|
|
|
{
|
|
|
|
|
case SEGMENT_BPM:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new BPMSegment(*(ToBPM(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2011-07-27 23:32:37 -04:00
|
|
|
case SEGMENT_STOP:
|
2011-07-26 16:05:14 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new StopSegment(*(ToStop(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2011-07-27 23:32:37 -04:00
|
|
|
case SEGMENT_DELAY:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new DelaySegment(*(ToDelay(org)));
|
2011-07-27 23:32:37 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2011-07-26 16:05:14 -04:00
|
|
|
case SEGMENT_TIME_SIG:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new TimeSignatureSegment(*(ToTimeSignature(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_WARP:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new WarpSegment(*(ToWarp(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_LABEL:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new LabelSegment(*(ToLabel(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_TICKCOUNT:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new TickcountSegment(*(ToTickcount(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_COMBO:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new ComboSegment(*(ToCombo(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_SPEED:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new SpeedSegment(*(ToSpeed(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_SCROLL:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new ScrollSegment(*(ToScroll(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEGMENT_FAKE:
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
cpy = new FakeSegment(*(ToFake(org)));
|
2011-07-26 16:05:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: FAIL_M(ssprintf("An unknown timing segment type %d can't be copied over!", tst));
|
|
|
|
|
}
|
|
|
|
|
// reset the rows as if startRow was beat 0.
|
|
|
|
|
cpy->SetRow(org->GetRow() - startRow);
|
|
|
|
|
ret.AddSegment(tst, cpy);
|
|
|
|
|
cnt++;
|
2011-07-26 13:41:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-26 16:05:14 -04:00
|
|
|
return ret;
|
2011-07-26 13:41:41 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-03 13:57:22 -04:00
|
|
|
void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut, float highest ) const
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
fMinBPMOut = FLT_MAX;
|
|
|
|
|
fMaxBPMOut = 0;
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 15:22:32 -04:00
|
|
|
for (unsigned i = 0; i < bpms.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
BPMSegment *seg = ToBPM( bpms[i] );
|
2011-03-17 01:47:30 -04:00
|
|
|
const float fBPM = seg->GetBPM();
|
2011-07-03 13:57:22 -04:00
|
|
|
fMaxBPMOut = clamp(max( fBPM, fMaxBPMOut ), 0, highest);
|
2011-03-17 01:47:30 -04:00
|
|
|
fMinBPMOut = min( fBPM, fMinBPMOut );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 13:03:21 +07:00
|
|
|
struct ts_less : binary_function <TimingSegment *, TimingSegment *, bool> {
|
|
|
|
|
bool operator() (const TimingSegment *x, const TimingSegment *y) const {
|
|
|
|
|
return (*x) < (*y);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2011-07-14 19:01:12 -04:00
|
|
|
void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg)
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &segs = m_avpTimingSegments[tst];
|
2011-07-14 19:01:12 -04:00
|
|
|
// Unsure if this uses the proper comparison.
|
2011-07-17 13:03:21 +07:00
|
|
|
segs.insert(upper_bound(segs.begin(), segs.end(), seg, ts_less()), seg);
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
float TimingData::GetNextSegmentBeatAtRow(TimingSegmentType tst, int row) const
|
2011-07-14 21:51:09 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> segs = m_avpTimingSegments[tst];
|
2011-07-14 23:54:06 -04:00
|
|
|
for (unsigned i = 0; i < segs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( segs[i]->GetRow() <= row )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-07-27 23:32:37 -04:00
|
|
|
return segs[i]->GetBeat();
|
2011-07-14 23:54:06 -04:00
|
|
|
}
|
|
|
|
|
return NoteRowToBeat(row);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
float TimingData::GetPreviousSegmentBeatAtRow(TimingSegmentType tst, int row) const
|
2011-07-14 23:54:06 -04:00
|
|
|
{
|
|
|
|
|
float backup = -1;
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> segs = m_avpTimingSegments[tst];
|
2011-07-14 23:54:06 -04:00
|
|
|
for (unsigned i = 0; i < segs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( segs[i]->GetRow() >= row )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-07-27 23:32:37 -04:00
|
|
|
backup = segs[i]->GetBeat();
|
2011-07-14 23:54:06 -04:00
|
|
|
}
|
|
|
|
|
return (backup > -1) ? backup : NoteRowToBeat(row);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
unsigned TimingData::GetSegmentIndexAtRow(TimingSegmentType tst, int iRow ) const
|
|
|
|
|
{
|
|
|
|
|
const vector<TimingSegment*> &vSegments = m_avpTimingSegments[tst];
|
|
|
|
|
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
|
|
// seek to the last segment that goes into effect before iRow.
|
|
|
|
|
// OPTIMIZATION OPPORTUNITY: use std::upper_bound instead?
|
|
|
|
|
for( ; i < vSegments.size() - 1; ++i )
|
|
|
|
|
if( iRow < vSegments[i+1]->GetRow() )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-14 19:52:37 -04:00
|
|
|
// TODO: Find a way to combine all of these SetAtRows to one.
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
/* Change an existing BPM segment, merge identical segments together or insert a new one. */
|
|
|
|
|
void TimingData::SetBPMAtRow( int iNoteRow, float fBPM )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 15:22:32 -04:00
|
|
|
for( i=0; i<bpms.size(); i++ )
|
|
|
|
|
if( bpms[i]->GetRow() >= iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if( i == bpms.size() || bpms[i]->GetRow() != iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
// There is no BPMSegment at the specified beat. If the BPM being set differs
|
|
|
|
|
// from the last BPMSegment's BPM, create a new BPMSegment.
|
2011-07-14 19:52:37 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
fabsf( ToBPM(bpms[i-1])->GetBPM() - fBPM) > 1e-5f )
|
2011-07-14 19:52:37 -04:00
|
|
|
AddSegment( SEGMENT_BPM, new BPMSegment(iNoteRow, fBPM) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else // BPMSegment being modified is m_BPMSegments[i]
|
|
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
fabsf(ToBPM(bpms[i-1])->GetBPM() - fBPM) < 1e-5f )
|
2011-07-14 19:52:37 -04:00
|
|
|
bpms.erase( bpms.begin()+i, bpms.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
2011-09-11 17:13:10 +00:00
|
|
|
ToBPM(bpms[i])->SetBPM(fBPM);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-27 23:32:37 -04:00
|
|
|
void TimingData::SetStopAtRow( int iRow, float fSeconds )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &stops = m_avpTimingSegments[SEGMENT_STOP];
|
2011-07-14 19:52:37 -04:00
|
|
|
for( i=0; i<stops.size(); i++ )
|
2011-07-27 23:32:37 -04:00
|
|
|
if (stops[i]->GetRow() == iRow)
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-27 23:32:37 -04:00
|
|
|
if( i == stops.size() ) // there is no StopSegment at the current beat
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
// create a new StopSegment
|
2011-04-05 14:28:08 -04:00
|
|
|
if( fSeconds > 0 )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-27 23:32:37 -04:00
|
|
|
AddSegment( SEGMENT_STOP, new StopSegment(iRow, fSeconds) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // StopSegment being modified is m_StopSegments[i]
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
StopSegment *ss = ToStop(stops[i]);
|
2011-04-05 14:28:08 -04:00
|
|
|
if( fSeconds > 0 )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
ss->SetPause(fSeconds);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else
|
2011-07-14 19:52:37 -04:00
|
|
|
stops.erase( stops.begin()+i, stops.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-27 23:32:37 -04:00
|
|
|
void TimingData::SetDelayAtRow( int iRow, float fSeconds )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &stops = m_avpTimingSegments[SEGMENT_DELAY];
|
2011-07-27 23:32:37 -04:00
|
|
|
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
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
DelaySegment *ss = ToDelay(stops[i]);
|
2011-07-27 23:32:37 -04:00
|
|
|
if( fSeconds > 0 )
|
|
|
|
|
{
|
|
|
|
|
ss->SetPause(fSeconds);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
stops.erase( stops.begin()+i, stops.begin()+i+1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
void TimingData::SetTimeSignatureAtRow( int iRow, int iNumerator, int iDenominator )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &tSigs = m_avpTimingSegments[SEGMENT_TIME_SIG];
|
2011-07-14 19:52:37 -04:00
|
|
|
for( i = 0; i < tSigs.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
if( tSigs[i]->GetRow() >= iRow)
|
2011-03-17 01:47:30 -04:00
|
|
|
break; // We found our segment.
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if ( i == tSigs.size() || tSigs[i]->GetRow() != iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
// No specific segment here: place one if it differs.
|
|
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
(ToTimeSignature(tSigs[i-1])->GetNum() != iNumerator ||
|
|
|
|
|
ToTimeSignature(tSigs[i-1])->GetDen() != iDenominator ) )
|
2011-07-14 19:52:37 -04:00
|
|
|
AddSegment( SEGMENT_TIME_SIG, new TimeSignatureSegment(iRow, iNumerator, iDenominator) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else // TimeSignatureSegment being modified is m_vTimeSignatureSegments[i]
|
|
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
ToTimeSignature(tSigs[i-1])->GetNum() == iNumerator &&
|
|
|
|
|
ToTimeSignature(tSigs[i-1])->GetDen() == iDenominator )
|
2011-07-14 19:52:37 -04:00
|
|
|
tSigs.erase( tSigs.begin()+i, tSigs.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToTimeSignature(tSigs[i])->SetNum(iNumerator);
|
|
|
|
|
ToTimeSignature(tSigs[i])->SetDen(iDenominator);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
void TimingData::SetTimeSignatureNumeratorAtRow( int iRow, int iNum )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
unsigned iDenom = GetTimeSignatureSegmentAtRow(iRow)->GetDen();
|
|
|
|
|
SetTimeSignatureAtRow(iRow, iNum, iDenom );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
void TimingData::SetTimeSignatureDenominatorAtRow( int iRow, int iDenom )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
unsigned iNum = GetTimeSignatureSegmentAtRow(iRow)->GetNum();
|
|
|
|
|
SetTimeSignatureAtRow( iRow, iNum, iDenom );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 00:54:33 -04:00
|
|
|
void TimingData::SetWarpAtRow( int iRow, float fNew )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 00:54:33 -04:00
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &warps = m_avpTimingSegments[SEGMENT_WARP];
|
2011-07-14 19:52:37 -04:00
|
|
|
for( i=0; i<warps.size(); i++ )
|
|
|
|
|
if( warps[i]->GetRow() == iRow )
|
2011-03-25 00:54:33 -04:00
|
|
|
break;
|
2011-05-16 10:24:59 -04:00
|
|
|
bool valid = iRow > 0 && fNew > 0;
|
2011-07-14 19:52:37 -04:00
|
|
|
if( i == warps.size() )
|
2011-03-25 00:54:33 -04:00
|
|
|
{
|
|
|
|
|
if( valid )
|
|
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
AddSegment( SEGMENT_WARP, new WarpSegment(iRow, fNew) );
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( valid )
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToWarp(warps[i])->SetLength(fNew);
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
else
|
2011-07-14 19:52:37 -04:00
|
|
|
warps.erase( warps.begin()+i, warps.begin()+i+1 );
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Change an existing Tickcount segment, merge identical segments together or insert a new one. */
|
|
|
|
|
void TimingData::SetTickcountAtRow( int iRow, int iTicks )
|
|
|
|
|
{
|
2011-07-19 23:42:32 -06:00
|
|
|
unsigned i = 0;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &ticks = m_avpTimingSegments[SEGMENT_TICKCOUNT];
|
2011-07-14 19:52:37 -04:00
|
|
|
for( i=0; i<ticks.size(); i++ )
|
|
|
|
|
if( ticks[i]->GetRow() >= iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if( i == ticks.size() || ticks[i]->GetRow() != iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
// No TickcountSegment here. Make a new segment if required.
|
2011-07-14 19:52:37 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToTickcount(ticks[i-1])->GetTicks() != iTicks )
|
2011-07-14 19:52:37 -04:00
|
|
|
AddSegment( SEGMENT_TICKCOUNT, new TickcountSegment(iRow, iTicks ) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else // TickcountSegment being modified is m_TickcountSegments[i]
|
|
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
ToTickcount(ticks[i-1])->GetTicks() == iTicks )
|
2011-07-14 19:52:37 -04:00
|
|
|
ticks.erase( ticks.begin()+i, ticks.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
2011-09-11 17:13:10 +00:00
|
|
|
ToTickcount(ticks[i])->SetTicks(iTicks);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-09 02:28:15 -04:00
|
|
|
void TimingData::SetComboAtRow( int iRow, int iCombo, int iMiss )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &combos = m_avpTimingSegments[SEGMENT_COMBO];
|
2011-07-14 21:25:17 -04:00
|
|
|
for( i=0; i<combos.size(); i++ )
|
|
|
|
|
if( combos[i]->GetRow() >= iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if( i == combos.size() || combos[i]->GetRow() != iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToCombo(combos[i-1])->GetCombo() != iCombo ||
|
|
|
|
|
ToCombo(combos[i-1])->GetMissCombo() != iMiss)
|
2011-07-14 21:25:17 -04:00
|
|
|
AddSegment( SEGMENT_COMBO, new ComboSegment(iRow, iCombo, iMiss ) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
ToCombo(combos[i-1])->GetCombo() == iCombo &&
|
|
|
|
|
ToCombo(combos[i-1])->GetMissCombo() == iMiss)
|
2011-07-14 21:25:17 -04:00
|
|
|
combos.erase( combos.begin()+i, combos.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
2011-07-09 02:28:15 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToCombo(combos[i])->SetCombo(iCombo);
|
|
|
|
|
ToCombo(combos[i])->SetMissCombo(iMiss);
|
2011-07-09 02:28:15 -04:00
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-09 02:28:15 -04:00
|
|
|
void TimingData::SetHitComboAtRow(int iRow, int iCombo)
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
SetComboAtRow(iRow,
|
2011-07-09 02:28:15 -04:00
|
|
|
iCombo,
|
2011-09-10 03:08:59 +00:00
|
|
|
GetComboSegmentAtRow(iRow)->GetMissCombo());
|
2011-07-09 02:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetMissComboAtRow(int iRow, int iMiss)
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
SetComboAtRow(iRow,
|
|
|
|
|
GetComboSegmentAtRow(iRow)->GetCombo(),
|
2011-07-09 02:28:15 -04:00
|
|
|
iMiss);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 23:03:10 -04:00
|
|
|
void TimingData::SetLabelAtRow( int iRow, const RString sLabel )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &labels = m_avpTimingSegments[SEGMENT_LABEL];
|
2011-07-14 21:25:17 -04:00
|
|
|
for( i=0; i<labels.size(); i++ )
|
|
|
|
|
if( labels[i]->GetRow() >= iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if( i == labels.size() || labels[i]->GetRow() != iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToLabel(labels[i-1])->GetLabel() != sLabel )
|
2011-07-14 21:25:17 -04:00
|
|
|
AddSegment( SEGMENT_LABEL, new LabelSegment(iRow, sLabel ) );
|
2011-04-04 23:03:10 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
( ToLabel(labels[i-1])->GetLabel() == sLabel ||
|
2011-07-14 21:25:17 -04:00
|
|
|
sLabel == "" ) )
|
|
|
|
|
labels.erase( labels.begin()+i, labels.begin()+i+1 );
|
2011-04-04 23:03:10 -04:00
|
|
|
else
|
2011-09-11 17:13:10 +00:00
|
|
|
ToLabel(labels[i])->SetLabel(sLabel);
|
2011-04-04 23:03:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
void TimingData::SetSpeedAtRow( int iRow, float fPercent, float fWait, SpeedSegment::BaseUnit unit )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &speeds = m_avpTimingSegments[SEGMENT_SPEED];
|
2011-07-14 21:25:17 -04:00
|
|
|
for( i = 0; i < speeds.size(); i++ )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if( speeds[i]->GetRow() >= iRow)
|
2011-05-15 13:48:10 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2011-09-11 17:13:10 +00:00
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if ( i == speeds.size() || speeds[i]->GetRow() != iRow )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
2011-05-16 09:44:07 -04:00
|
|
|
// the core mod itself matters the most for comparisons.
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToSpeed(speeds[i-1])->GetRatio() != fPercent )
|
|
|
|
|
AddSegment( SEGMENT_SPEED, new SpeedSegment(iRow, fPercent, fWait, unit) );
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-05-16 09:44:07 -04:00
|
|
|
// The others aren't compared: only the mod itself matters.
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
ToSpeed(speeds[i-1])->GetRatio() == fPercent )
|
2011-07-14 21:25:17 -04:00
|
|
|
speeds.erase( speeds.begin()+i, speeds.begin()+i+1 );
|
2011-05-15 13:48:10 -04:00
|
|
|
else
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToSpeed(speeds[i])->SetRatio(fPercent);
|
|
|
|
|
ToSpeed(speeds[i])->SetDelay(fWait);
|
|
|
|
|
ToSpeed(speeds[i])->SetUnit(unit);
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-25 22:44:41 +07:00
|
|
|
void TimingData::SetScrollAtRow( int iRow, float fPercent )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &scrolls = m_avpTimingSegments[SEGMENT_SCROLL];
|
2011-07-14 21:25:17 -04:00
|
|
|
for( i = 0; i < scrolls.size(); i++ )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if( scrolls[i]->GetRow() >= iRow)
|
2011-05-25 22:44:41 +07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 17:25:02 -04:00
|
|
|
if ( i == scrolls.size() || scrolls[i]->GetRow() != iRow )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
|
|
|
|
// the core mod itself matters the most for comparisons.
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToScroll(scrolls[i-1])->GetRatio() != fPercent )
|
2011-07-14 21:25:17 -04:00
|
|
|
AddSegment( SEGMENT_SCROLL, new ScrollSegment(iRow, fPercent) );
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// The others aren't compared: only the mod itself matters.
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i > 0 &&
|
2011-09-11 17:13:10 +00:00
|
|
|
ToScroll(scrolls[i-1])->GetRatio() == fPercent )
|
2011-07-14 21:25:17 -04:00
|
|
|
scrolls.erase( scrolls.begin()+i, scrolls.begin()+i+1 );
|
2011-05-25 22:44:41 +07:00
|
|
|
else
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToScroll(scrolls[i])->SetRatio(fPercent);
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-16 02:00:17 -04:00
|
|
|
void TimingData::SetFakeAtRow( int iRow, float fNew )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &fakes = m_avpTimingSegments[SEGMENT_FAKE];
|
2011-07-14 21:25:17 -04:00
|
|
|
for( i=0; i<fakes.size(); i++ )
|
|
|
|
|
if( fakes[i]->GetRow() == iRow )
|
2011-05-16 02:00:17 -04:00
|
|
|
break;
|
2011-05-16 16:17:34 -04:00
|
|
|
bool valid = iRow > 0 && fNew > 0;
|
2011-07-14 21:25:17 -04:00
|
|
|
if( i == fakes.size() )
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
|
|
|
|
if( valid )
|
|
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
AddSegment( SEGMENT_FAKE, new FakeSegment(iRow, fNew) );
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( valid )
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
ToFake(fakes[i])->SetLength(fNew);
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
else
|
2011-07-14 21:25:17 -04:00
|
|
|
fakes.erase( fakes.begin()+i, fakes.begin()+i+1 );
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-15 13:48:10 -04:00
|
|
|
void TimingData::SetSpeedPercentAtRow( int iRow, float fPercent )
|
|
|
|
|
{
|
2011-05-15 23:48:03 -04:00
|
|
|
SetSpeedAtRow( iRow,
|
|
|
|
|
fPercent,
|
2011-09-11 17:13:10 +00:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetDelay(),
|
2011-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetUnit());
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetSpeedWaitAtRow( int iRow, float fWait )
|
|
|
|
|
{
|
2011-05-15 23:48:03 -04:00
|
|
|
SetSpeedAtRow( iRow,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetRatio(),
|
2011-05-15 23:48:03 -04:00
|
|
|
fWait,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetUnit());
|
2011-05-15 23:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
void TimingData::SetSpeedModeAtRow( int iRow, SpeedSegment::BaseUnit unit )
|
2011-05-15 23:48:03 -04:00
|
|
|
{
|
|
|
|
|
SetSpeedAtRow( iRow,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetRatio(),
|
2011-09-11 17:13:10 +00:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetDelay(),
|
|
|
|
|
unit );
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-27 23:32:37 -04:00
|
|
|
float TimingData::GetStopAtRow( int iRow ) const
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &stops = m_avpTimingSegments[SEGMENT_STOP];
|
2011-07-14 22:19:32 -04:00
|
|
|
for( unsigned i=0; i<stops.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
const StopSegment *s = ToStop(stops[i]);
|
2011-07-27 23:32:37 -04:00
|
|
|
if( s->GetRow() == iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
return s->GetPause();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float TimingData::GetDelayAtRow( int iRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &stops = m_avpTimingSegments[SEGMENT_DELAY];
|
2011-07-27 23:32:37 -04:00
|
|
|
for( unsigned i=0; i<stops.size(); i++ )
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
const DelaySegment *s = ToDelay(stops[i]);
|
2011-07-27 23:32:37 -04:00
|
|
|
if( s->GetRow() == iRow )
|
|
|
|
|
{
|
|
|
|
|
return s->GetPause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetComboAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &c = m_avpTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
const int index = GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow);
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToCombo(c[index])->GetCombo();
|
2011-07-09 02:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetMissComboAtRow(int iNoteRow) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &c = m_avpTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
const int index = GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow);
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToCombo(c[index])->GetMissCombo();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-04 23:03:10 -04:00
|
|
|
RString TimingData::GetLabelAtRow( int iRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &l = m_avpTimingSegments[SEGMENT_LABEL];
|
|
|
|
|
const int index = GetSegmentIndexAtRow(SEGMENT_LABEL, iRow);
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToLabel(l[index])->GetLabel();
|
2011-04-04 23:03:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 00:54:33 -04:00
|
|
|
float TimingData::GetWarpAtRow( int iWarpRow ) const
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &warps = m_avpTimingSegments[SEGMENT_WARP];
|
2011-07-14 22:19:32 -04:00
|
|
|
for( unsigned i=0; i<warps.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
if( warps[i]->GetRow() == iWarpRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToWarp(warps[i])->GetLength();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-15 13:48:10 -04:00
|
|
|
float TimingData::GetSpeedPercentAtRow( int iRow )
|
|
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
return GetSpeedSegmentAtRow( iRow )->GetRatio();
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetSpeedWaitAtRow( int iRow )
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
return GetSpeedSegmentAtRow( iRow )->GetDelay();
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
SpeedSegment::BaseUnit TimingData::GetSpeedModeAtRow( int iRow )
|
2011-05-15 23:48:03 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
return GetSpeedSegmentAtRow( iRow )->GetUnit();
|
2011-05-15 23:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-25 22:44:41 +07:00
|
|
|
float TimingData::GetScrollAtRow( int iRow )
|
|
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
return GetScrollSegmentAtRow( iRow )->GetRatio();
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
|
|
|
|
|
2011-05-16 02:00:17 -04:00
|
|
|
float TimingData::GetFakeAtRow( int iFakeRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &fakes = m_avpTimingSegments[SEGMENT_FAKE];
|
2011-07-14 22:19:32 -04:00
|
|
|
for( unsigned i=0; i<fakes.size(); i++ )
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
if( fakes[i]->GetRow() == iFakeRow )
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToFake(fakes[i])->GetLength();
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
// Multiply the BPM in the range [fStartBeat,fEndBeat) by fFactor.
|
|
|
|
|
void TimingData::MultiplyBPMInBeatRange( int iStartIndex, int iEndIndex, float fFactor )
|
|
|
|
|
{
|
|
|
|
|
// Change all other BPM segments in this range.
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 22:19:32 -04:00
|
|
|
for( unsigned i=0; i<bpms.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
BPMSegment *bs = ToBPM(bpms[i]);
|
2011-07-14 22:19:32 -04:00
|
|
|
const int iStartIndexThisSegment = bs->GetRow();
|
|
|
|
|
const bool bIsLastBPMSegment = i == bpms.size()-1;
|
|
|
|
|
const int iStartIndexNextSegment = bIsLastBPMSegment ? INT_MAX : bpms[i+1]->GetRow();
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
if( iStartIndexThisSegment <= iStartIndex && iStartIndexNextSegment <= iStartIndex )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If this BPM segment crosses the beginning of the range,
|
|
|
|
|
* split it into two. */
|
|
|
|
|
if( iStartIndexThisSegment < iStartIndex && iStartIndexNextSegment > iStartIndex )
|
|
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
|
|
|
|
|
BPMSegment * b = new BPMSegment(iStartIndexNextSegment,
|
|
|
|
|
bs->GetBPS());
|
|
|
|
|
bpms.insert(bpms.begin()+i+1, b);
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
/* Don't apply the BPM change to the first half of the segment we
|
|
|
|
|
* just split, since it lies outside the range. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If this BPM segment crosses the end of the range, split it into two.
|
|
|
|
|
if( iStartIndexThisSegment < iEndIndex && iStartIndexNextSegment > iEndIndex )
|
|
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
BPMSegment * b = new BPMSegment(iEndIndex,
|
|
|
|
|
bs->GetBPS());
|
|
|
|
|
bpms.insert(bpms.begin()+i+1, b);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
else if( iStartIndexNextSegment > iEndIndex )
|
|
|
|
|
continue;
|
|
|
|
|
|
2011-07-14 22:19:32 -04:00
|
|
|
bs->SetBPM(bs->GetBPM() * fFactor);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetBPMAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 22:19:32 -04:00
|
|
|
for( i=0; i<bpms.size()-1; i++ )
|
|
|
|
|
if( bpms[i+1]->GetRow() > iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToBPM(bpms[i])->GetBPM();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 23:19:31 +07:00
|
|
|
bool TimingData::IsWarpAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &warps = m_avpTimingSegments[SEGMENT_WARP];
|
2011-07-14 22:19:32 -04:00
|
|
|
if( warps.empty() )
|
2011-03-25 23:40:03 +07:00
|
|
|
return false;
|
2011-09-10 03:08:59 +00:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_WARP, iNoteRow );
|
2011-09-11 17:13:10 +00:00
|
|
|
const WarpSegment *s = ToWarp(warps[i]);
|
2011-05-31 10:59:18 -04:00
|
|
|
float beatRow = NoteRowToBeat(iNoteRow);
|
2011-07-14 22:19:32 -04:00
|
|
|
if( s->GetBeat() <= beatRow && beatRow < (s->GetBeat() + s->GetLength() ) )
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
2011-05-24 13:07:59 +07:00
|
|
|
// Allow stops inside warps to allow things like stop, warp, stop, warp, stop, and so on.
|
2011-09-10 03:08:59 +00:00
|
|
|
if( m_avpTimingSegments[SEGMENT_STOP].empty() && m_avpTimingSegments[SEGMENT_DELAY].empty() )
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-03-27 15:56:40 +07:00
|
|
|
if( GetStopAtRow(iNoteRow) != 0.0f || GetDelayAtRow(iNoteRow) != 0.0f )
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2011-03-25 23:19:31 +07:00
|
|
|
}
|
|
|
|
|
|
2011-05-16 02:00:17 -04:00
|
|
|
bool TimingData::IsFakeAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &fakes = m_avpTimingSegments[SEGMENT_FAKE];
|
2011-07-14 22:19:32 -04:00
|
|
|
if( fakes.empty() )
|
2011-05-16 02:00:17 -04:00
|
|
|
return false;
|
2011-09-10 03:08:59 +00:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_FAKE, iNoteRow );
|
2011-09-11 17:13:10 +00:00
|
|
|
const FakeSegment *s = ToFake(fakes[i]);
|
2011-05-31 00:51:25 -04:00
|
|
|
float beatRow = NoteRowToBeat(iNoteRow);
|
2011-07-14 22:19:32 -04:00
|
|
|
if( s->GetBeat() <= beatRow && beatRow < ( s->GetBeat() + s->GetLength() ) )
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
// TODO: make this part of the TimingSegment struct
|
|
|
|
|
enum SegmentEffectArea
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
EffectArea_Row, // takes effect on a single row
|
|
|
|
|
EffectArea_Range, // takes effect until the next segment of its type
|
|
|
|
|
NUM_EffectArea,
|
|
|
|
|
EffectArea_Invalid,
|
|
|
|
|
};
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
TimingSegment* TimingData::GetSegmentAtRow( int iNoteRow, TimingSegmentType tst )
|
2011-03-25 00:54:33 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment*> vSegments = m_avpTimingSegments[tst];
|
2011-03-25 00:54:33 -04:00
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
if( vSegments.empty() )
|
|
|
|
|
FAIL_M( ssprintf("GetSegmentAtRow: %s is empty (blame vyhd)", TimingSegmentTypeToString(tst).c_str()) );
|
2011-05-15 13:48:10 -04:00
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
unsigned index = -1;
|
|
|
|
|
|
|
|
|
|
// seek to the last segment before this row
|
|
|
|
|
for( index = 0; index < vSegments.size() - 1; ++index )
|
|
|
|
|
if( iNoteRow < vSegments[index+1]->GetRow() )
|
2011-05-25 22:44:41 +07:00
|
|
|
break;
|
2011-09-10 03:08:59 +00:00
|
|
|
|
|
|
|
|
return vSegments[index];
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 00:54:33 -04:00
|
|
|
int TimingData::GetTimeSignatureNumeratorAtRow( int iRow )
|
|
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
return GetTimeSignatureSegmentAtRow( iRow )->GetNum();
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetTimeSignatureDenominatorAtRow( int iRow )
|
|
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
return GetTimeSignatureSegmentAtRow( iRow )->GetDen();
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
int TimingData::GetTickcountAtRow( int iRow ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &ticks = m_avpTimingSegments[SEGMENT_TICKCOUNT];
|
2011-07-14 23:15:48 -04:00
|
|
|
const int index = GetSegmentIndexAtRow( SEGMENT_TICKCOUNT, iRow );
|
2011-09-11 17:13:10 +00:00
|
|
|
return ToTickcount(ticks[index])->GetTicks();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-05 14:18:29 -04:00
|
|
|
bool TimingData::DoesLabelExist( RString sLabel ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &labels = m_avpTimingSegments[SEGMENT_LABEL];
|
2011-07-14 23:15:48 -04:00
|
|
|
for (unsigned i = 0; i < labels.size(); i++)
|
2011-04-05 14:18:29 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
if (ToLabel(labels[i])->GetLabel() == sLabel)
|
2011-04-05 14:18:29 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut, bool &bDelayOut, int &iWarpBeginOut, float &fWarpLengthOut ) const
|
|
|
|
|
{
|
|
|
|
|
fElapsedTime += PREFSMAN->m_fGlobalOffsetSeconds;
|
|
|
|
|
|
|
|
|
|
GetBeatAndBPSFromElapsedTimeNoOffset( fElapsedTime, fBeatOut, fBPSOut, bFreezeOut, bDelayOut, iWarpBeginOut, fWarpLengthOut );
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 23:19:31 +07:00
|
|
|
enum
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
FOUND_WARP,
|
|
|
|
|
FOUND_WARP_DESTINATION,
|
|
|
|
|
FOUND_BPM_CHANGE,
|
|
|
|
|
FOUND_STOP,
|
2011-07-27 23:43:52 -04:00
|
|
|
FOUND_DELAY,
|
2011-08-15 18:12:12 -04:00
|
|
|
FOUND_STOP_DELAY, // we have these two on the same row.
|
2011-03-25 23:19:31 +07:00
|
|
|
FOUND_MARKER,
|
|
|
|
|
NOT_FOUND
|
|
|
|
|
};
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-03-25 23:19:31 +07:00
|
|
|
void TimingData::GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut, bool &bDelayOut, int &iWarpBeginOut, float &fWarpDestinationOut ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> * segs = m_avpTimingSegments;
|
2011-07-15 00:54:11 -04:00
|
|
|
vector<TimingSegment *>::const_iterator itBPMS = segs[SEGMENT_BPM].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itWS = segs[SEGMENT_WARP].begin();
|
2011-07-27 23:43:52 -04:00
|
|
|
vector<TimingSegment *>::const_iterator itSS = segs[SEGMENT_STOP].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itDS = segs[SEGMENT_DELAY].begin();
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
bFreezeOut = false;
|
|
|
|
|
bDelayOut = false;
|
|
|
|
|
|
|
|
|
|
iWarpBeginOut = -1;
|
|
|
|
|
|
|
|
|
|
int iLastRow = 0;
|
|
|
|
|
float fLastTime = -m_fBeat0OffsetInSeconds;
|
2011-06-12 03:37:10 -04:00
|
|
|
float fBPS = GetBPMAtRow(0) / 60.0f;
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
float bIsWarping = false;
|
2011-06-12 03:37:10 -04:00
|
|
|
float fWarpDestination = 0;
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
for( ;; )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
int iEventRow = INT_MAX;
|
|
|
|
|
int iEventType = NOT_FOUND;
|
|
|
|
|
if( bIsWarping && BeatToNoteRow(fWarpDestination) < iEventRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventRow = BeatToNoteRow(fWarpDestination);
|
|
|
|
|
iEventType = FOUND_WARP_DESTINATION;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-07-15 00:54:11 -04:00
|
|
|
if (itBPMS != segs[SEGMENT_BPM].end() &&
|
|
|
|
|
(*itBPMS)->GetRow() < iEventRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itBPMS)->GetRow();
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventType = FOUND_BPM_CHANGE;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-07-27 23:43:52 -04:00
|
|
|
if (itDS != segs[SEGMENT_DELAY].end() &&
|
|
|
|
|
(*itDS)->GetRow() < iEventRow)
|
|
|
|
|
{
|
|
|
|
|
iEventRow = (*itDS)->GetRow();
|
|
|
|
|
iEventType = FOUND_DELAY;
|
|
|
|
|
}
|
|
|
|
|
if (itSS != segs[SEGMENT_STOP].end() &&
|
2011-08-15 17:54:06 -04:00
|
|
|
(*itSS)->GetRow() < iEventRow ) // && iEventType != FOUND_DELAY )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-08-15 18:12:12 -04:00
|
|
|
int tmpRow = iEventRow;
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itSS)->GetRow();
|
2011-08-15 18:12:12 -04:00
|
|
|
iEventType = (tmpRow == iEventRow) ? FOUND_STOP_DELAY : FOUND_STOP;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-07-15 00:54:11 -04:00
|
|
|
if (itWS != segs[SEGMENT_WARP].end() &&
|
|
|
|
|
(*itWS)->GetRow() < iEventRow )
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itWS)->GetRow();
|
2011-03-26 22:07:24 +07:00
|
|
|
iEventType = FOUND_WARP;
|
|
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
if( iEventType == NOT_FOUND )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
float fTimeToNextEvent = bIsWarping ? 0 : NoteRowToBeat( iEventRow - iLastRow ) / fBPS;
|
|
|
|
|
float fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
if ( fElapsedTime < fNextEventTime )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
switch( iEventType )
|
|
|
|
|
{
|
2011-07-27 23:43:52 -04:00
|
|
|
case FOUND_WARP_DESTINATION:
|
|
|
|
|
bIsWarping = false;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_BPM_CHANGE:
|
2011-09-11 17:13:10 +00:00
|
|
|
fBPS = ToBPM(*itBPMS)->GetBPS();
|
2011-07-27 23:43:52 -04:00
|
|
|
itBPMS ++;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_DELAY:
|
2011-08-15 19:23:43 -04:00
|
|
|
case FOUND_STOP_DELAY:
|
2011-07-27 23:43:52 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
const DelaySegment *ss = ToDelay(*itDS);
|
2011-07-27 23:43:52 -04:00
|
|
|
fTimeToNextEvent = ss->GetPause();
|
|
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
if ( fElapsedTime < fNextEventTime )
|
|
|
|
|
{
|
|
|
|
|
bFreezeOut = false;
|
|
|
|
|
bDelayOut = true;
|
|
|
|
|
fBeatOut = ss->GetBeat();
|
|
|
|
|
fBPSOut = fBPS;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
itDS ++;
|
2011-08-15 19:23:43 -04:00
|
|
|
if (iEventType == FOUND_DELAY)
|
|
|
|
|
break;
|
2011-07-27 23:43:52 -04:00
|
|
|
}
|
|
|
|
|
case FOUND_STOP:
|
2011-03-25 23:19:31 +07:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
const StopSegment *ss = ToStop(*itSS);
|
2011-07-15 00:54:11 -04:00
|
|
|
fTimeToNextEvent = ss->GetPause();
|
2011-03-26 11:59:48 -05:00
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
if ( fElapsedTime < fNextEventTime )
|
|
|
|
|
{
|
2011-07-27 23:43:52 -04:00
|
|
|
bFreezeOut = true;
|
|
|
|
|
bDelayOut = false;
|
2011-07-15 00:54:11 -04:00
|
|
|
fBeatOut = ss->GetBeat();
|
2011-03-26 11:59:48 -05:00
|
|
|
fBPSOut = fBPS;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
itSS ++;
|
2011-08-15 18:12:12 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2011-07-27 23:43:52 -04:00
|
|
|
case FOUND_WARP:
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
2011-05-16 10:24:59 -04:00
|
|
|
bIsWarping = true;
|
2011-09-11 17:13:10 +00:00
|
|
|
const WarpSegment *ws = ToWarp(*itWS);
|
2011-07-15 00:54:11 -04:00
|
|
|
float fWarpSum = ws->GetLength() + ws->GetBeat();
|
2011-05-16 10:24:59 -04:00
|
|
|
if( fWarpSum > fWarpDestination )
|
|
|
|
|
{
|
2011-05-16 22:05:23 +07:00
|
|
|
fWarpDestination = fWarpSum;
|
2011-05-16 10:24:59 -04:00
|
|
|
}
|
|
|
|
|
iWarpBeginOut = iEventRow;
|
|
|
|
|
fWarpDestinationOut = fWarpDestination;
|
|
|
|
|
itWS ++;
|
|
|
|
|
break;
|
2011-03-26 22:07:24 +07:00
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
iLastRow = iEventRow;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
fBeatOut = NoteRowToBeat( iLastRow ) + (fElapsedTime - fLastTime) * fBPS;
|
|
|
|
|
fBPSOut = fBPS;
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetElapsedTimeFromBeat( float fBeat ) const
|
|
|
|
|
{
|
|
|
|
|
return TimingData::GetElapsedTimeFromBeatNoOffset( fBeat ) - PREFSMAN->m_fGlobalOffsetSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> * segs = m_avpTimingSegments;
|
2011-07-15 00:54:11 -04:00
|
|
|
vector<TimingSegment *>::const_iterator itBPMS = segs[SEGMENT_BPM].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itWS = segs[SEGMENT_WARP].begin();
|
2011-07-27 23:43:52 -04:00
|
|
|
vector<TimingSegment *>::const_iterator itSS = segs[SEGMENT_STOP].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itDS = segs[SEGMENT_DELAY].begin();
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
int iLastRow = 0;
|
|
|
|
|
float fLastTime = -m_fBeat0OffsetInSeconds;
|
2011-06-12 03:37:10 -04:00
|
|
|
float fBPS = GetBPMAtRow(0) / 60.0f;
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
float bIsWarping = false;
|
2011-06-12 03:37:10 -04:00
|
|
|
float fWarpDestination = 0;
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
for( ;; )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
int iEventRow = INT_MAX;
|
|
|
|
|
int iEventType = NOT_FOUND;
|
|
|
|
|
if( bIsWarping && BeatToNoteRow(fWarpDestination) < iEventRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventRow = BeatToNoteRow(fWarpDestination);
|
|
|
|
|
iEventType = FOUND_WARP_DESTINATION;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-07-15 00:54:11 -04:00
|
|
|
if (itBPMS != segs[SEGMENT_BPM].end() &&
|
|
|
|
|
(*itBPMS)->GetRow() < iEventRow )
|
2011-03-25 23:19:31 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itBPMS)->GetRow();
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventType = FOUND_BPM_CHANGE;
|
|
|
|
|
}
|
2011-07-27 23:43:52 -04:00
|
|
|
if (itDS != segs[SEGMENT_DELAY].end() &&
|
|
|
|
|
(*itDS)->GetRow() < iEventRow ) // delays (come before marker)
|
2011-03-25 23:19:31 +07:00
|
|
|
{
|
2011-07-27 23:43:52 -04:00
|
|
|
iEventRow = (*itDS)->GetRow();
|
|
|
|
|
iEventType = FOUND_DELAY;
|
2011-03-25 23:19:31 +07:00
|
|
|
}
|
|
|
|
|
if( BeatToNoteRow(fBeat) < iEventRow )
|
|
|
|
|
{
|
|
|
|
|
iEventRow = BeatToNoteRow(fBeat);
|
|
|
|
|
iEventType = FOUND_MARKER;
|
|
|
|
|
}
|
2011-07-27 23:43:52 -04:00
|
|
|
if (itSS != segs[SEGMENT_STOP].end() &&
|
2011-07-15 00:54:11 -04:00
|
|
|
(*itSS)->GetRow() < iEventRow ) // stops (come after marker)
|
2011-03-25 23:19:31 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itSS)->GetRow();
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventType = FOUND_STOP;
|
|
|
|
|
}
|
2011-07-15 00:54:11 -04:00
|
|
|
if (itWS != segs[SEGMENT_WARP].end() &&
|
|
|
|
|
(*itWS)->GetRow() < iEventRow )
|
2011-03-26 22:07:24 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itWS)->GetRow();
|
2011-03-26 22:07:24 +07:00
|
|
|
iEventType = FOUND_WARP;
|
|
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
float fTimeToNextEvent = bIsWarping ? 0 : NoteRowToBeat( iEventRow - iLastRow ) / fBPS;
|
|
|
|
|
float fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
switch( iEventType )
|
|
|
|
|
{
|
|
|
|
|
case FOUND_WARP_DESTINATION:
|
|
|
|
|
bIsWarping = false;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_BPM_CHANGE:
|
2011-09-11 17:13:10 +00:00
|
|
|
fBPS = ToBPM(*itBPMS)->GetBPS();
|
2011-03-25 23:19:31 +07:00
|
|
|
itBPMS ++;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_STOP:
|
2011-09-11 17:13:10 +00:00
|
|
|
fTimeToNextEvent = ToStop(*itSS)->GetPause();
|
2011-03-25 23:19:31 +07:00
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
itSS ++;
|
|
|
|
|
break;
|
2011-07-27 23:43:52 -04:00
|
|
|
case FOUND_DELAY:
|
2011-09-11 17:13:10 +00:00
|
|
|
fTimeToNextEvent = ToDelay(*itDS)->GetPause();
|
2011-07-27 23:43:52 -04:00
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
itDS ++;
|
|
|
|
|
break;
|
2011-03-25 23:19:31 +07:00
|
|
|
case FOUND_MARKER:
|
|
|
|
|
return fLastTime;
|
2011-03-26 22:07:24 +07:00
|
|
|
case FOUND_WARP:
|
|
|
|
|
{
|
2011-05-16 10:24:59 -04:00
|
|
|
bIsWarping = true;
|
2011-09-11 17:13:10 +00:00
|
|
|
WarpSegment *ws = ToWarp(*itWS);
|
2011-07-15 00:54:11 -04:00
|
|
|
float fWarpSum = ws->GetLength() + ws->GetBeat();
|
2011-05-16 10:24:59 -04:00
|
|
|
if( fWarpSum > fWarpDestination )
|
|
|
|
|
{
|
2011-05-16 22:05:23 +07:00
|
|
|
fWarpDestination = fWarpSum;
|
2011-05-16 10:24:59 -04:00
|
|
|
}
|
|
|
|
|
itWS ++;
|
|
|
|
|
break;
|
2011-03-26 22:07:24 +07:00
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
}
|
|
|
|
|
iLastRow = iEventRow;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
2011-03-25 23:19:31 +07:00
|
|
|
|
|
|
|
|
// won't reach here, unless BeatToNoteRow(fBeat == INT_MAX) (impossible)
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-25 22:44:41 +07:00
|
|
|
float TimingData::GetDisplayedBeat( float fBeat ) const
|
|
|
|
|
{
|
2011-06-12 03:37:10 -04:00
|
|
|
float fOutBeat = 0;
|
2011-07-27 00:29:22 +07:00
|
|
|
unsigned i;
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &scrolls = m_avpTimingSegments[SEGMENT_SCROLL];
|
2011-07-27 00:29:22 +07:00
|
|
|
for( i=0; i<scrolls.size()-1; i++ )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
2011-07-27 00:29:22 +07:00
|
|
|
if( scrolls[i+1]->GetBeat() > fBeat )
|
2011-06-04 19:02:45 +07:00
|
|
|
break;
|
2011-09-11 17:13:10 +00:00
|
|
|
fOutBeat += (scrolls[i+1]->GetBeat() - scrolls[i]->GetBeat()) * ToScroll(scrolls[i])->GetRatio();
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
2011-09-11 17:13:10 +00:00
|
|
|
fOutBeat += (fBeat - scrolls[i]->GetBeat()) * ToScroll(scrolls[i])->GetRatio();
|
2011-05-25 22:44:41 +07:00
|
|
|
return fOutBeat;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 18:58:44 +07:00
|
|
|
void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool bAdjustBPM )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
ASSERT( fScale > 0 );
|
|
|
|
|
ASSERT( iStartIndex >= 0 );
|
|
|
|
|
ASSERT( iStartIndex < iEndIndex );
|
2011-03-19 18:58:44 +07:00
|
|
|
|
2011-06-26 13:43:30 +07:00
|
|
|
int length = iEndIndex - iStartIndex;
|
|
|
|
|
int newLength = lrintf( fScale * length );
|
|
|
|
|
|
2011-07-15 00:14:13 -04:00
|
|
|
for (unsigned i = 0; i < NUM_TimingSegmentType; i++)
|
2011-07-14 23:15:48 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
for (unsigned j = 0; j < m_avpTimingSegments[i].size(); j++)
|
2011-07-14 23:15:48 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
m_avpTimingSegments[i][j]->Scale(iStartIndex, length, newLength);
|
2011-07-14 23:15:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-26 17:38:31 -04:00
|
|
|
|
2011-03-19 18:58:44 +07:00
|
|
|
// adjust BPM changes to preserve timing
|
|
|
|
|
if( bAdjustBPM )
|
|
|
|
|
{
|
2011-06-26 13:43:30 +07:00
|
|
|
int iNewEndIndex = iStartIndex + newLength;
|
2011-03-19 18:58:44 +07:00
|
|
|
float fEndBPMBeforeScaling = GetBPMAtRow(iNewEndIndex);
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-03-19 18:58:44 +07:00
|
|
|
|
|
|
|
|
// adjust BPM changes "between" iStartIndex and iNewEndIndex
|
2011-07-15 00:54:11 -04:00
|
|
|
for ( unsigned i = 0; i < bpms.size(); i++ )
|
2011-03-19 18:58:44 +07:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
BPMSegment *bpm = ToBPM(bpms[i]);
|
2011-07-15 00:54:11 -04:00
|
|
|
const int iSegStart = bpm->GetRow();
|
2011-03-19 18:58:44 +07:00
|
|
|
if( iSegStart <= iStartIndex )
|
|
|
|
|
continue;
|
|
|
|
|
else if( iSegStart >= iNewEndIndex )
|
|
|
|
|
continue;
|
|
|
|
|
else
|
2011-07-15 00:54:11 -04:00
|
|
|
bpm->SetBPM( bpm->GetBPM() * fScale );
|
2011-03-19 18:58:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set BPM at iStartIndex and iNewEndIndex.
|
|
|
|
|
SetBPMAtRow( iStartIndex, GetBPMAtRow(iStartIndex) * fScale );
|
|
|
|
|
SetBPMAtRow( iNewEndIndex, fEndBPMBeforeScaling );
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::InsertRows( int iStartRow, int iRowsToAdd )
|
|
|
|
|
{
|
2011-07-15 00:14:13 -04:00
|
|
|
for (unsigned i = 0; i < NUM_TimingSegmentType; i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &segs = m_avpTimingSegments[i];
|
2011-07-14 15:22:32 -04:00
|
|
|
for (unsigned j = 0; j < segs.size(); j++)
|
|
|
|
|
{
|
|
|
|
|
TimingSegment *seg = segs[j];
|
|
|
|
|
if (seg->GetRow() < iStartRow)
|
|
|
|
|
continue;
|
|
|
|
|
seg->SetRow(seg->GetRow() + iRowsToAdd);
|
|
|
|
|
}
|
2011-05-26 17:38:31 -04:00
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
if( iStartRow == 0 )
|
|
|
|
|
{
|
|
|
|
|
/* If we're shifting up at the beginning, we just shifted up the first
|
|
|
|
|
* BPMSegment. That segment must always begin at 0. */
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &bpms = m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 15:22:32 -04:00
|
|
|
ASSERT_M( bpms.size() > 0, "There must be at least one BPM Segment in the chart!" );
|
|
|
|
|
bpms[0]->SetRow(0);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete BPMChanges and StopSegments in [iStartRow,iRowsToDelete), and shift down.
|
|
|
|
|
void TimingData::DeleteRows( int iStartRow, int iRowsToDelete )
|
|
|
|
|
{
|
|
|
|
|
/* Remember the BPM at the end of the region being deleted. */
|
2011-09-10 03:08:59 +00:00
|
|
|
float fNewBPM = GetBPMAtBeat( NoteRowToBeat(iStartRow+iRowsToDelete) );
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
/* We're moving rows up. Delete any BPM changes and stops in the region
|
|
|
|
|
* being deleted. */
|
2011-07-15 00:14:13 -04:00
|
|
|
for (unsigned i = 0; i < NUM_TimingSegmentType; i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &segs = m_avpTimingSegments[i];
|
2011-07-14 15:22:32 -04:00
|
|
|
for (unsigned j = 0; j < segs.size(); j++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 15:22:32 -04:00
|
|
|
TimingSegment *seg = segs[j];
|
|
|
|
|
// Before deleted region:
|
|
|
|
|
if (seg->GetRow() < iStartRow)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Inside deleted region:
|
|
|
|
|
if (seg->GetRow() < iStartRow + iRowsToDelete)
|
|
|
|
|
{
|
|
|
|
|
segs.erase(segs.begin()+j, segs.begin()+j+1);
|
|
|
|
|
--j;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// After deleted regions:
|
|
|
|
|
seg->SetRow(seg->GetRow() - iRowsToDelete);
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-26 17:38:31 -04:00
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
SetBPMAtRow( iStartRow, fNewBPM );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-24 12:29:55 +07:00
|
|
|
float TimingData::GetDisplayedSpeedPercent( float fSongBeat, float fMusicSeconds ) const
|
2011-05-24 11:43:08 +07:00
|
|
|
{
|
2011-06-01 14:32:59 -04:00
|
|
|
/* HACK: Somehow we get called into this function when there is no
|
|
|
|
|
* TimingData to work with. This seems to happen the most upon
|
|
|
|
|
* leaving the editor. Still, cover our butts in case this instance
|
|
|
|
|
* isn't existing. */
|
|
|
|
|
if (!this) return 1.0f;
|
2011-07-15 00:54:11 -04:00
|
|
|
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &speeds = m_avpTimingSegments[SEGMENT_SPEED];
|
2011-07-15 00:54:11 -04:00
|
|
|
if( speeds.size() == 0 )
|
2011-06-01 14:32:59 -04:00
|
|
|
return 1.0f;
|
2011-05-24 11:43:08 +07:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
const int index = GetSegmentIndexAtBeat( SEGMENT_SPEED, fSongBeat );
|
2011-05-24 11:43:08 +07:00
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
const SpeedSegment *seg = ToSpeed(speeds[index]);
|
2011-07-15 00:54:11 -04:00
|
|
|
float fStartBeat = seg->GetBeat();
|
2011-05-24 11:43:08 +07:00
|
|
|
float fStartTime = GetElapsedTimeFromBeat( fStartBeat ) - GetDelayAtBeat( fStartBeat );
|
|
|
|
|
float fEndTime;
|
|
|
|
|
float fCurTime = fMusicSeconds;
|
|
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
if( seg->GetUnit() == 1 ) // seconds
|
2011-05-24 11:43:08 +07:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
fEndTime = fStartTime + seg->GetDelay();
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
fEndTime = GetElapsedTimeFromBeat( fStartBeat + seg->GetDelay() )
|
|
|
|
|
- GetDelayAtBeat( fStartBeat + seg->GetDelay() );
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
|
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
SpeedSegment *first = ToSpeed(speeds[0]);
|
2011-07-15 00:54:11 -04:00
|
|
|
|
2011-09-11 17:13:10 +00:00
|
|
|
if( ( index == 0 && first->GetDelay() > 0.0 ) && fCurTime < fStartTime )
|
2011-05-24 11:43:08 +07:00
|
|
|
{
|
2011-06-12 03:37:10 -04:00
|
|
|
return 1.0f;
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
2011-09-11 17:13:10 +00:00
|
|
|
else if( fEndTime >= fCurTime && ( index > 0 || first->GetDelay() > 0.0 ) )
|
2011-05-24 11:43:08 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
const float fPriorSpeed = (index == 0 ?
|
|
|
|
|
1 :
|
2011-09-11 17:13:10 +00:00
|
|
|
ToSpeed(speeds[index - 1])->GetRatio() );
|
2011-05-24 11:43:08 +07:00
|
|
|
float fTimeUsed = fCurTime - fStartTime;
|
|
|
|
|
float fDuration = fEndTime - fStartTime;
|
|
|
|
|
float fRatioUsed = fDuration == 0.0 ? 1 : fTimeUsed / fDuration;
|
|
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
float fDistance = fPriorSpeed - seg->GetRatio();
|
2011-05-24 11:43:08 +07:00
|
|
|
float fRatioNeed = fRatioUsed * -fDistance;
|
|
|
|
|
return (fPriorSpeed + fRatioNeed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
return seg->GetRatio();
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-10 16:00:47 +07:00
|
|
|
void TimingData::TidyUpData()
|
|
|
|
|
{
|
|
|
|
|
// If there are no BPM segments, provide a default.
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> *segs = m_avpTimingSegments;
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_BPM].empty() )
|
2011-05-10 16:00:47 +07:00
|
|
|
{
|
|
|
|
|
LOG->UserLog( "Song file", m_sFile, "has no BPM segments, default provided." );
|
|
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
AddSegment( SEGMENT_BPM, new BPMSegment(0, 60) );
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the first BPM segment starts at beat 0.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_BPM][0]->GetRow() != 0 )
|
|
|
|
|
segs[SEGMENT_BPM][0]->SetRow(0);
|
2011-05-10 16:00:47 +07:00
|
|
|
|
|
|
|
|
// If no time signature specified, assume 4/4 time for the whole song.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_TIME_SIG].empty() )
|
2011-05-10 16:00:47 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_TIME_SIG].push_back( new TimeSignatureSegment(0, 4, 4) );
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
// Likewise, if no tickcount signature is specified, assume 4 ticks
|
|
|
|
|
//per beat for the entire song. The default of 4 is chosen more
|
|
|
|
|
//for compatibility with the main Pump series than anything else.
|
|
|
|
|
if( segs[SEGMENT_TICKCOUNT].empty() )
|
2011-05-10 16:00:47 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_TICKCOUNT].push_back( new TickcountSegment(0, 4) );
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Have a default combo segment of one just in case.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_COMBO].empty() )
|
2011-05-10 16:00:47 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_COMBO].push_back( new ComboSegment(0, 1, 1) );
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Have a default label segment just in case.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_LABEL].empty() )
|
2011-05-10 16:00:47 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_LABEL].push_back( new LabelSegment(0, "Song Start") );
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
2011-05-15 13:48:10 -04:00
|
|
|
|
|
|
|
|
// Always be sure there is a starting speed.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_SPEED].empty() )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_SPEED].push_back( new SpeedSegment(0, 1, 0) );
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
2011-05-25 22:44:41 +07:00
|
|
|
|
|
|
|
|
// Always be sure there is a starting scrolling factor.
|
2011-07-15 00:54:11 -04:00
|
|
|
if( segs[SEGMENT_SCROLL].empty() )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
segs[SEGMENT_SCROLL].push_back( new ScrollSegment(0, 1) );
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
2011-05-10 16:00:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
bool TimingData::HasBpmChanges() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
return m_avpTimingSegments[SEGMENT_BPM].size()>1;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasStops() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
return m_avpTimingSegments[SEGMENT_STOP].size()>0;
|
2011-08-07 13:48:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasDelays() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
return m_avpTimingSegments[SEGMENT_DELAY].size()>0;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasWarps() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
return m_avpTimingSegments[SEGMENT_WARP].size()>0;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-16 02:00:17 -04:00
|
|
|
bool TimingData::HasFakes() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
return m_avpTimingSegments[SEGMENT_FAKE].size()>0;
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-15 13:48:10 -04:00
|
|
|
bool TimingData::HasSpeedChanges() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &speeds = m_avpTimingSegments[SEGMENT_SPEED];
|
2011-07-14 23:15:48 -04:00
|
|
|
return (speeds.size()>1 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToSpeed(speeds[0])->GetRatio() != 1);
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-25 22:44:41 +07:00
|
|
|
bool TimingData::HasScrollChanges() const
|
|
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &scrolls = m_avpTimingSegments[SEGMENT_SCROLL];
|
2011-07-14 23:15:48 -04:00
|
|
|
return (scrolls.size()>1 ||
|
2011-09-11 17:13:10 +00:00
|
|
|
ToScroll(scrolls[0])->GetRatio() != 1);
|
2011-05-25 22:44:41 +07:00
|
|
|
}
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
void TimingData::NoteRowToMeasureAndBeat( int iNoteRow, int &iMeasureIndexOut, int &iBeatIndexOut, int &iRowsRemainder ) const
|
|
|
|
|
{
|
|
|
|
|
iMeasureIndexOut = 0;
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> &tSigs = m_avpTimingSegments[SEGMENT_TIME_SIG];
|
2011-07-15 00:54:11 -04:00
|
|
|
for (unsigned i = 0; i < tSigs.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
TimeSignatureSegment *curSig = ToTimeSignature(tSigs[i]);
|
2011-07-15 00:54:11 -04:00
|
|
|
int iSegmentEndRow = (i + 1 == tSigs.size()) ? INT_MAX : curSig->GetRow();
|
|
|
|
|
|
|
|
|
|
int iRowsPerMeasureThisSegment = curSig->GetNoteRowsPerMeasure();
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
if( iNoteRow >= curSig->GetRow() )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
// iNoteRow lands in this segment
|
2011-07-15 00:54:11 -04:00
|
|
|
int iNumRowsThisSegment = iNoteRow - curSig->GetRow();
|
2011-03-17 01:47:30 -04:00
|
|
|
int iNumMeasuresThisSegment = (iNumRowsThisSegment) / iRowsPerMeasureThisSegment; // don't round up
|
|
|
|
|
iMeasureIndexOut += iNumMeasuresThisSegment;
|
|
|
|
|
iBeatIndexOut = iNumRowsThisSegment / iRowsPerMeasureThisSegment;
|
|
|
|
|
iRowsRemainder = iNumRowsThisSegment % iRowsPerMeasureThisSegment;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// iNoteRow lands after this segment
|
2011-07-15 00:54:11 -04:00
|
|
|
int iNumRowsThisSegment = iSegmentEndRow - curSig->GetRow();
|
|
|
|
|
int iNumMeasuresThisSegment = (iNumRowsThisSegment + iRowsPerMeasureThisSegment - 1)
|
|
|
|
|
/ iRowsPerMeasureThisSegment; // round up
|
2011-03-17 01:47:30 -04:00
|
|
|
iMeasureIndexOut += iNumMeasuresThisSegment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-27 22:33:50 -04:00
|
|
|
vector<RString> TimingData::ToVectorString(TimingSegmentType tst, int dec) const
|
2011-07-17 16:06:40 -04:00
|
|
|
{
|
2011-09-10 03:08:59 +00:00
|
|
|
const vector<TimingSegment *> segs = m_avpTimingSegments[tst];
|
2011-07-17 16:06:40 -04:00
|
|
|
vector<RString> ret;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < segs.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
ret.push_back(segs[i]->ToString(dec));
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
|
|
|
|
/** @brief Allow Lua to have access to the TimingData. */
|
|
|
|
|
class LunaTimingData: public Luna<TimingData>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static int HasStops( T* p, lua_State *L ) { lua_pushboolean(L, p->HasStops()); return 1; }
|
2011-08-07 13:48:42 -05:00
|
|
|
static int HasDelays( T* p, lua_State *L ) { lua_pushboolean(L, p->HasDelays()); return 1; }
|
2011-03-17 01:47:30 -04:00
|
|
|
static int HasBPMChanges( T* p, lua_State *L ) { lua_pushboolean(L, p->HasBpmChanges()); return 1; }
|
2011-03-24 20:21:43 -04:00
|
|
|
static int HasWarps( T* p, lua_State *L ) { lua_pushboolean(L, p->HasWarps()); return 1; }
|
2011-05-16 02:00:17 -04:00
|
|
|
static int HasFakes( T* p, lua_State *L ) { lua_pushboolean(L, p->HasFakes()); return 1; }
|
2011-05-15 13:48:10 -04:00
|
|
|
static int HasSpeedChanges( T* p, lua_State *L ) { lua_pushboolean(L, p->HasSpeedChanges()); return 1; }
|
2011-06-01 10:12:10 -04:00
|
|
|
static int HasScrollChanges( T* p, lua_State *L ) { lua_pushboolean(L, p->HasScrollChanges()); return 1; }
|
2011-06-15 16:56:01 -04:00
|
|
|
static int GetWarps( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_WARP), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetFakes( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_FAKE), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetScrolls( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_SCROLL), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetSpeeds( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_SPEED), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetTimeSignatures( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_TIME_SIG), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetCombos( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_COMBO), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetTickcounts( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_TICKCOUNT), L);
|
2011-06-15 16:56:01 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
static int GetStops( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-27 22:33:50 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_STOP), L);
|
2011-03-17 01:47:30 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetDelays( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-27 22:33:50 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_DELAY), L);
|
2011-03-17 01:47:30 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetBPMs( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
vector<float> vBPMs;
|
2011-09-10 03:08:59 +00:00
|
|
|
vector<TimingSegment *> &bpms = p->m_avpTimingSegments[SEGMENT_BPM];
|
2011-07-14 15:22:32 -04:00
|
|
|
for (unsigned i = 0; i < bpms.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-09-11 17:13:10 +00:00
|
|
|
BPMSegment *seg = ToBPM(bpms[i]);
|
2011-03-17 01:47:30 -04:00
|
|
|
const float fBPM = seg->GetBPM();
|
|
|
|
|
vBPMs.push_back( fBPM );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LuaHelpers::CreateTableFromArray(vBPMs, L);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-04-04 23:03:10 -04:00
|
|
|
static int GetLabels( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_LABEL), L);
|
2011-04-04 23:03:10 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
2011-03-17 01:47:30 -04:00
|
|
|
static int GetBPMsAndTimes( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_BPM), L);
|
2011-03-17 01:47:30 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetActualBPM( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
// certainly there's a better way to do it than this? -aj
|
|
|
|
|
float fMinBPM, fMaxBPM;
|
|
|
|
|
p->GetActualBPM( fMinBPM, fMaxBPM );
|
|
|
|
|
vector<float> fBPMs;
|
|
|
|
|
fBPMs.push_back( fMinBPM );
|
|
|
|
|
fBPMs.push_back( fMaxBPM );
|
|
|
|
|
LuaHelpers::CreateTableFromArray(fBPMs, L);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-06-09 18:16:23 -04:00
|
|
|
static int HasNegativeBPMs( T* p, lua_State *L ) { lua_pushboolean(L, p->HasWarps()); return 1; }
|
2011-03-17 01:47:30 -04:00
|
|
|
// formerly in Song.cpp in sm-ssc private beta 1.x:
|
|
|
|
|
static int GetBPMAtBeat( T* p, lua_State *L ) { lua_pushnumber(L, p->GetBPMAtBeat(FArg(1))); return 1; }
|
|
|
|
|
static int GetBeatFromElapsedTime( T* p, lua_State *L ) { lua_pushnumber(L, p->GetBeatFromElapsedTime(FArg(1))); return 1; }
|
|
|
|
|
static int GetElapsedTimeFromBeat( T* p, lua_State *L ) { lua_pushnumber(L, p->GetElapsedTimeFromBeat(FArg(1))); return 1; }
|
|
|
|
|
|
|
|
|
|
LunaTimingData()
|
|
|
|
|
{
|
|
|
|
|
ADD_METHOD( HasStops );
|
2011-08-07 13:48:42 -05:00
|
|
|
ADD_METHOD( HasDelays );
|
2011-03-17 01:47:30 -04:00
|
|
|
ADD_METHOD( HasBPMChanges );
|
2011-03-24 20:21:43 -04:00
|
|
|
ADD_METHOD( HasWarps );
|
2011-05-16 02:00:17 -04:00
|
|
|
ADD_METHOD( HasFakes );
|
2011-05-15 13:48:10 -04:00
|
|
|
ADD_METHOD( HasSpeedChanges );
|
2011-06-01 10:12:10 -04:00
|
|
|
ADD_METHOD( HasScrollChanges );
|
2011-03-17 01:47:30 -04:00
|
|
|
ADD_METHOD( GetStops );
|
|
|
|
|
ADD_METHOD( GetDelays );
|
|
|
|
|
ADD_METHOD( GetBPMs );
|
2011-06-15 16:56:01 -04:00
|
|
|
ADD_METHOD( GetWarps );
|
|
|
|
|
ADD_METHOD( GetFakes );
|
|
|
|
|
ADD_METHOD( GetTimeSignatures );
|
|
|
|
|
ADD_METHOD( GetTickcounts );
|
|
|
|
|
ADD_METHOD( GetSpeeds );
|
|
|
|
|
ADD_METHOD( GetScrolls );
|
|
|
|
|
ADD_METHOD( GetCombos );
|
2011-04-04 23:03:10 -04:00
|
|
|
ADD_METHOD( GetLabels );
|
2011-03-17 01:47:30 -04:00
|
|
|
ADD_METHOD( GetBPMsAndTimes );
|
|
|
|
|
ADD_METHOD( GetActualBPM );
|
|
|
|
|
ADD_METHOD( HasNegativeBPMs );
|
|
|
|
|
// formerly in Song.cpp in sm-ssc private beta 1.x:
|
|
|
|
|
ADD_METHOD( GetBPMAtBeat );
|
|
|
|
|
ADD_METHOD( GetBeatFromElapsedTime );
|
|
|
|
|
ADD_METHOD( GetElapsedTimeFromBeat );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( TimingData )
|
|
|
|
|
// lua end
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|