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-05-09 23:16:56 -04:00
|
|
|
TimingData::TimingData(float fOffset) :
|
2011-07-14 11:09:49 -04:00
|
|
|
m_fBeat0OffsetInSeconds(fOffset)
|
2011-07-14 12:31:42 -04:00
|
|
|
{
|
|
|
|
|
// allTimingSegments[SEGMENT_BPM] = new vector<BPMSegment>();
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 19:29:52 -04:00
|
|
|
TimingData::~TimingData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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-07-14 15:22:32 -04:00
|
|
|
const vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
for (unsigned i = 0; i < bpms.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 15:22:32 -04:00
|
|
|
BPMSegment *seg = static_cast<BPMSegment *>(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-07-14 19:01:12 -04:00
|
|
|
vector<TimingSegment *> &segs = this->allTimingSegments[tst];
|
|
|
|
|
// 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-07-14 21:51:09 -04:00
|
|
|
int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst,
|
|
|
|
|
int row, bool isDelay) const
|
|
|
|
|
{
|
|
|
|
|
const vector<TimingSegment *> &segs = this->allTimingSegments[tst];
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
for (; i < segs.size() - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
TimingSegment *seg = segs[i+1];
|
|
|
|
|
if (seg->GetRow() > row)
|
|
|
|
|
{
|
|
|
|
|
// put conditions here for individual segments.
|
|
|
|
|
if (tst == SEGMENT_STOP_DELAY &&
|
|
|
|
|
static_cast<StopSegment *>(seg)->GetDelay() != isDelay)
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return static_cast<int>(i);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:54:06 -04:00
|
|
|
float TimingData::GetNextSegmentBeatAtRow(TimingSegmentType tst,
|
|
|
|
|
int row, bool isDelay) const
|
|
|
|
|
{
|
|
|
|
|
const vector<TimingSegment *> segs = this->allTimingSegments[tst];
|
|
|
|
|
for (unsigned i = 0; i < segs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( segs[i]->GetRow() <= row )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (tst != SEGMENT_STOP_DELAY ||
|
|
|
|
|
static_cast<StopSegment *>(segs[i])->GetDelay() == isDelay)
|
|
|
|
|
return segs[i]->GetBeat();
|
|
|
|
|
}
|
|
|
|
|
return NoteRowToBeat(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetPreviousSegmentBeatAtRow(TimingSegmentType tst,
|
|
|
|
|
int row, bool isDelay) const
|
|
|
|
|
{
|
|
|
|
|
float backup = -1;
|
|
|
|
|
const vector<TimingSegment *> segs = this->allTimingSegments[tst];
|
|
|
|
|
for (unsigned i = 0; i < segs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( segs[i]->GetRow() >= row )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (tst != SEGMENT_STOP_DELAY ||
|
|
|
|
|
static_cast<StopSegment *>(segs[i])->GetDelay() == isDelay)
|
|
|
|
|
backup = segs[i]->GetBeat();
|
|
|
|
|
}
|
|
|
|
|
return (backup > -1) ? backup : NoteRowToBeat(row);
|
|
|
|
|
}
|
|
|
|
|
|
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-07-14 15:22:32 -04:00
|
|
|
vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
for( i=0; i<bpms.size(); i++ )
|
|
|
|
|
if( bpms[i]->GetRow() >= iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-14 15:22:32 -04:00
|
|
|
BPMSegment *bs = static_cast<BPMSegment *>(bpms[i]);
|
|
|
|
|
if( i == bpms.size() || bs->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 ||
|
|
|
|
|
fabsf(static_cast<BPMSegment *>(bpms[i-1])->GetBPM() - fBPM) > 1e-5f )
|
|
|
|
|
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 &&
|
|
|
|
|
fabsf(static_cast<BPMSegment *>(bpms[i-1])->GetBPM() - fBPM) < 1e-5f )
|
|
|
|
|
bpms.erase( bpms.begin()+i, bpms.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
2011-07-14 19:52:37 -04:00
|
|
|
bs->SetBPM(fBPM);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetStopAtRow( int iRow, float fSeconds, bool bDelay )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 19:52:37 -04:00
|
|
|
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
|
|
|
|
|
for( i=0; i<stops.size(); i++ )
|
|
|
|
|
if (stops[i]->GetRow() == iRow &&
|
|
|
|
|
static_cast<StopSegment *>(stops[i])->GetDelay() == bDelay )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-14 19:52:37 -04:00
|
|
|
StopSegment *ss = static_cast<StopSegment *>(stops[i]);
|
|
|
|
|
if( i == stops.size() ) // there is no Stop/Delay Segment 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-14 19:52:37 -04:00
|
|
|
AddSegment( SEGMENT_STOP_DELAY, new StopSegment(iRow, fSeconds, bDelay) );
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // StopSegment being modified is m_StopSegments[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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetTimeSignatureAtRow( int iRow, int iNumerator, int iDenominator )
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 19:52:37 -04:00
|
|
|
vector<TimingSegment *> &tSigs = this->allTimingSegments[SEGMENT_TIME_SIG];
|
|
|
|
|
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-14 19:52:37 -04:00
|
|
|
TimeSignatureSegment *ts = static_cast<TimeSignatureSegment *>(tSigs[i]);
|
|
|
|
|
if ( i == tSigs.size() || ts->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 ||
|
|
|
|
|
(static_cast<TimeSignatureSegment *>(tSigs[i-1])->GetNum() != iNumerator ||
|
|
|
|
|
static_cast<TimeSignatureSegment *>(tSigs[i-1])->GetDen() != iDenominator ) )
|
|
|
|
|
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 &&
|
|
|
|
|
static_cast<TimeSignatureSegment *>(tSigs[i-1])->GetNum() == iNumerator &&
|
|
|
|
|
static_cast<TimeSignatureSegment *>(tSigs[i-1])->GetDen() == iDenominator )
|
|
|
|
|
tSigs.erase( tSigs.begin()+i, tSigs.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
|
|
|
|
{
|
2011-07-14 19:52:37 -04:00
|
|
|
ts->SetNum(iNumerator);
|
|
|
|
|
ts->SetDen(iDenominator);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetTimeSignatureNumeratorAtRow( int iRow, int iNumerator )
|
|
|
|
|
{
|
2011-07-09 02:28:15 -04:00
|
|
|
this->SetTimeSignatureAtRow(iRow,
|
|
|
|
|
iNumerator,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetTimeSignatureSegmentAtRow(iRow)->GetDen());
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetTimeSignatureDenominatorAtRow( int iRow, int iDenominator )
|
|
|
|
|
{
|
2011-07-09 02:28:15 -04:00
|
|
|
this->SetTimeSignatureAtRow(iRow,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetTimeSignatureSegmentAtRow(iRow)->GetNum(),
|
2011-07-09 02:28:15 -04:00
|
|
|
iDenominator);
|
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-07-14 19:52:37 -04:00
|
|
|
vector<TimingSegment *> &warps = this->allTimingSegments[SEGMENT_WARP];
|
|
|
|
|
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-07-14 19:52:37 -04:00
|
|
|
static_cast<WarpSegment *>(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 18:35:29 -06:00
|
|
|
LOG->Trace( "TimingData::SetTickcountAtRow( '%i' , '%i' )", iRow, iTicks );
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
unsigned i;
|
2011-07-14 19:52:37 -04:00
|
|
|
vector<TimingSegment *> &ticks = this->allTimingSegments[SEGMENT_TICKCOUNT];
|
|
|
|
|
for( i=0; i<ticks.size(); i++ )
|
|
|
|
|
if( ticks[i]->GetRow() >= iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-14 19:52:37 -04:00
|
|
|
TickcountSegment *ts = static_cast<TickcountSegment *>(ticks[i]);
|
|
|
|
|
if( i == ticks.size() || ts->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 ||
|
|
|
|
|
static_cast<TickcountSegment *>(ticks[i-1])->GetTicks() != iTicks )
|
|
|
|
|
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 &&
|
|
|
|
|
static_cast<TickcountSegment *>(ticks[i-1])->GetTicks() == iTicks )
|
|
|
|
|
ticks.erase( ticks.begin()+i, ticks.begin()+i+1 );
|
2011-03-17 01:47:30 -04:00
|
|
|
else
|
2011-07-14 19:52:37 -04:00
|
|
|
ts->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-07-14 21:25:17 -04:00
|
|
|
vector<TimingSegment *> &combos = this->allTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
for( i=0; i<combos.size(); i++ )
|
|
|
|
|
if( combos[i]->GetRow() >= iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-14 21:25:17 -04:00
|
|
|
ComboSegment *cs = static_cast<ComboSegment *>(combos[i]);
|
|
|
|
|
|
|
|
|
|
if( i == combos.size() || cs->GetRow() != iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
|
|
|
|
static_cast<ComboSegment *>(combos[i-1])->GetCombo() != iCombo ||
|
|
|
|
|
static_cast<ComboSegment *>(combos[i-1])->GetMissCombo() != iMiss)
|
|
|
|
|
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 &&
|
|
|
|
|
static_cast<ComboSegment *>(combos[i-1])->GetCombo() == iCombo &&
|
|
|
|
|
static_cast<ComboSegment *>(combos[i-1])->GetMissCombo() == iMiss)
|
|
|
|
|
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-07-14 21:25:17 -04:00
|
|
|
cs->SetCombo(iCombo);
|
|
|
|
|
cs->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)
|
|
|
|
|
{
|
|
|
|
|
this->SetComboAtRow(iRow,
|
|
|
|
|
iCombo,
|
2011-07-14 23:15:48 -04:00
|
|
|
this->GetComboSegmentAtRow(iRow)->GetMissCombo());
|
2011-07-09 02:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetMissComboAtRow(int iRow, int iMiss)
|
|
|
|
|
{
|
|
|
|
|
this->SetComboAtRow(iRow,
|
2011-07-14 23:15:48 -04:00
|
|
|
this->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-07-14 21:25:17 -04:00
|
|
|
vector<TimingSegment *> &labels = this->allTimingSegments[SEGMENT_LABEL];
|
|
|
|
|
for( i=0; i<labels.size(); i++ )
|
|
|
|
|
if( labels[i]->GetRow() >= iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-07-14 21:25:17 -04:00
|
|
|
LabelSegment *ls = static_cast<LabelSegment *>(labels[i]);
|
|
|
|
|
|
|
|
|
|
if( i == labels.size() || ls->GetRow() != iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
if (i == 0 ||
|
|
|
|
|
static_cast<LabelSegment *>(labels[i-1])->GetLabel() != sLabel )
|
|
|
|
|
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 &&
|
|
|
|
|
( static_cast<LabelSegment *>(labels[i-1])->GetLabel() == sLabel ||
|
|
|
|
|
sLabel == "" ) )
|
|
|
|
|
labels.erase( labels.begin()+i, labels.begin()+i+1 );
|
2011-04-04 23:03:10 -04:00
|
|
|
else
|
2011-07-14 21:25:17 -04:00
|
|
|
ls->SetLabel(sLabel);
|
2011-04-04 23:03:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-15 23:48:03 -04:00
|
|
|
void TimingData::SetSpeedAtRow( int iRow, float fPercent, float fWait, unsigned short usMode )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 21:25:17 -04:00
|
|
|
vector<TimingSegment *> &speeds = this->allTimingSegments[SEGMENT_SPEED];
|
|
|
|
|
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-07-14 21:25:17 -04:00
|
|
|
SpeedSegment *ss = static_cast<SpeedSegment *>(speeds[i]);
|
|
|
|
|
|
|
|
|
|
if ( i == speeds.size() || ss->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 ||
|
|
|
|
|
static_cast<SpeedSegment *>(speeds[i-1])->GetRatio() != fPercent )
|
|
|
|
|
AddSegment( SEGMENT_SPEED, new SpeedSegment(iRow, fPercent, fWait, usMode) );
|
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 &&
|
|
|
|
|
static_cast<SpeedSegment *>(speeds[i-1])->GetRatio() == fPercent )
|
|
|
|
|
speeds.erase( speeds.begin()+i, speeds.begin()+i+1 );
|
2011-05-15 13:48:10 -04:00
|
|
|
else
|
|
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
ss->SetRatio(fPercent);
|
|
|
|
|
ss->SetLength(fWait);
|
|
|
|
|
ss->SetUnit(usMode);
|
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-07-14 21:25:17 -04:00
|
|
|
vector<TimingSegment *> &scrolls = this->allTimingSegments[SEGMENT_SCROLL];
|
|
|
|
|
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-14 21:25:17 -04:00
|
|
|
ScrollSegment *ss = static_cast<ScrollSegment *>(scrolls[i]);
|
|
|
|
|
if ( i == scrolls.size() || ss->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 ||
|
|
|
|
|
static_cast<ScrollSegment *>(scrolls[i-1])->GetRatio() != fPercent )
|
|
|
|
|
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 &&
|
|
|
|
|
static_cast<ScrollSegment *>(scrolls[i-1])->GetRatio() == fPercent )
|
|
|
|
|
scrolls.erase( scrolls.begin()+i, scrolls.begin()+i+1 );
|
2011-05-25 22:44:41 +07:00
|
|
|
else
|
|
|
|
|
{
|
2011-07-14 21:25:17 -04:00
|
|
|
ss->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-07-14 21:25:17 -04:00
|
|
|
vector<TimingSegment *> &fakes = this->allTimingSegments[SEGMENT_FAKE];
|
|
|
|
|
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-07-14 21:25:17 -04:00
|
|
|
static_cast<FakeSegment *>(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-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetLength(),
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::SetSpeedModeAtRow( int iRow, unsigned short usMode )
|
|
|
|
|
{
|
|
|
|
|
SetSpeedAtRow( iRow,
|
2011-07-14 23:15:48 -04:00
|
|
|
GetSpeedSegmentAtRow( iRow )->GetRatio(),
|
|
|
|
|
GetSpeedSegmentAtRow( iRow )->GetLength(),
|
2011-05-15 23:48:03 -04:00
|
|
|
usMode );
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-03-17 01:47:30 -04:00
|
|
|
float TimingData::GetStopAtRow( int iNoteRow, bool bDelay ) const
|
|
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
|
|
|
|
|
for( unsigned i=0; i<stops.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
const StopSegment *s = static_cast<StopSegment *>(stops[i]);
|
|
|
|
|
if( s->GetDelay() == bDelay && s->GetRow() == iNoteRow )
|
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::GetStopAtRow( int iRow ) const
|
|
|
|
|
{
|
|
|
|
|
return GetStopAtRow( iRow, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float TimingData::GetDelayAtRow( int iRow ) const
|
|
|
|
|
{
|
|
|
|
|
return GetStopAtRow( iRow, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetComboAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &c = this->allTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
const int index = this->GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow);
|
|
|
|
|
return static_cast<ComboSegment *>(c[index])->GetCombo();
|
2011-07-09 02:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetMissComboAtRow(int iNoteRow) const
|
|
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &c = this->allTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
const int index = this->GetSegmentIndexAtRow(SEGMENT_COMBO, iNoteRow);
|
|
|
|
|
return static_cast<ComboSegment *>(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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &l = this->allTimingSegments[SEGMENT_LABEL];
|
|
|
|
|
const int index = this->GetSegmentIndexAtRow(SEGMENT_LABEL, iRow);
|
|
|
|
|
return static_cast<LabelSegment *>(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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &warps = this->allTimingSegments[SEGMENT_WARP];
|
|
|
|
|
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-07-14 22:19:32 -04:00
|
|
|
return static_cast<WarpSegment *>(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-07-14 23:15:48 -04:00
|
|
|
return GetSpeedSegmentAtRow( iRow )->GetLength();
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-05-15 23:48:03 -04:00
|
|
|
unsigned short TimingData::GetSpeedModeAtRow( int iRow )
|
|
|
|
|
{
|
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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &fakes = this->allTimingSegments[SEGMENT_FAKE];
|
|
|
|
|
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-07-14 22:19:32 -04:00
|
|
|
return static_cast<FakeSegment *>(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-07-14 22:19:32 -04:00
|
|
|
vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
for( unsigned i=0; i<bpms.size(); i++ )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 22:19:32 -04:00
|
|
|
BPMSegment *bs = static_cast<BPMSegment *>(bpms[i]);
|
|
|
|
|
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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
for( i=0; i<bpms.size()-1; i++ )
|
|
|
|
|
if( bpms[i+1]->GetRow() > iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
2011-07-14 22:19:32 -04:00
|
|
|
return static_cast<BPMSegment *>(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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &warps = this->allTimingSegments[SEGMENT_WARP];
|
|
|
|
|
if( warps.empty() )
|
2011-03-25 23:40:03 +07:00
|
|
|
return false;
|
|
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_WARP, iNoteRow );
|
2011-07-14 22:19:32 -04:00
|
|
|
const WarpSegment *s = static_cast<WarpSegment *>(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-07-14 22:19:32 -04:00
|
|
|
if( this->allTimingSegments[SEGMENT_STOP_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-07-14 22:19:32 -04:00
|
|
|
const vector<TimingSegment *> &fakes = this->allTimingSegments[SEGMENT_FAKE];
|
|
|
|
|
if( fakes.empty() )
|
2011-05-16 02:00:17 -04:00
|
|
|
return false;
|
|
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_FAKE, iNoteRow );
|
2011-07-14 22:19:32 -04:00
|
|
|
const FakeSegment *s = static_cast<FakeSegment *>(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-07-14 23:15:48 -04:00
|
|
|
BPMSegment* TimingData::GetBPMSegmentAtRow( int iNoteRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
2011-03-17 01:47:30 -04:00
|
|
|
static BPMSegment empty;
|
2011-07-14 23:15:48 -04:00
|
|
|
if( bpms.empty() )
|
|
|
|
|
return new BPMSegment();
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_BPM, iNoteRow );
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<BPMSegment *>(bpms[i]);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
TimeSignatureSegment* TimingData::GetTimeSignatureSegmentAtRow( int iRow )
|
2011-03-25 00:54:33 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &tSigs = this->allTimingSegments[SEGMENT_TIME_SIG];
|
|
|
|
|
for( i=0; i<tSigs.size()-1; i++ )
|
|
|
|
|
if( tSigs[i+1]->GetRow() > iRow )
|
2011-03-25 00:54:33 -04:00
|
|
|
break;
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<TimeSignatureSegment *>(tSigs[i]);
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
SpeedSegment* TimingData::GetSpeedSegmentAtRow( int iRow )
|
2011-05-15 13:48:10 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &speeds = this->allTimingSegments[SEGMENT_SPEED];
|
|
|
|
|
for( i=0; i<speeds.size()-1; i++ )
|
|
|
|
|
if( speeds[i+1]->GetRow() > iRow )
|
2011-05-15 13:48:10 -04:00
|
|
|
break;
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<SpeedSegment *>(speeds[i]);
|
2011-05-15 13:48:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
ScrollSegment* TimingData::GetScrollSegmentAtRow( int iRow )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &scrolls = this->allTimingSegments[SEGMENT_SCROLL];
|
|
|
|
|
for( i=0; i<scrolls.size()-1; i++ )
|
|
|
|
|
if( scrolls[i+1]->GetRow() > iRow )
|
2011-05-25 22:44:41 +07:00
|
|
|
break;
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<ScrollSegment *>(scrolls[i]);
|
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-07-14 23:15:48 -04:00
|
|
|
ComboSegment* TimingData::GetComboSegmentAtRow( int iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &combos = this->allTimingSegments[SEGMENT_COMBO];
|
|
|
|
|
for( i=0; i<combos.size()-1; i++ )
|
|
|
|
|
if( combos[i+1]->GetRow() > iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
break;
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<ComboSegment *>(combos[i]);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
LabelSegment* TimingData::GetLabelSegmentAtRow( int iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &labels = this->allTimingSegments[SEGMENT_LABEL];
|
|
|
|
|
for( i=0; i<labels.size()-1; i++ )
|
|
|
|
|
if( labels[i+1]->GetRow() > iRow )
|
2011-04-04 23:03:10 -04:00
|
|
|
break;
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<LabelSegment *>(labels[i]);
|
2011-04-04 23:03:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
StopSegment* TimingData::GetStopSegmentAtRow( int iNoteRow, bool bDelay )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &stops = this->allTimingSegments[SEGMENT_STOP_DELAY];
|
|
|
|
|
if( stops.empty() )
|
|
|
|
|
return new StopSegment();
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_STOP_DELAY, iNoteRow, bDelay );
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<StopSegment *>(stops[i]);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
WarpSegment* TimingData::GetWarpSegmentAtRow( int iRow )
|
2011-03-25 00:54:33 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &warps = this->allTimingSegments[SEGMENT_WARP];
|
|
|
|
|
if( warps.empty() )
|
|
|
|
|
return new WarpSegment();
|
2011-03-25 00:54:33 -04:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_WARP, iRow );
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<WarpSegment *>(warps[i]);
|
2011-03-25 00:54:33 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
FakeSegment* TimingData::GetFakeSegmentAtRow( int iRow )
|
2011-05-16 02:00:17 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &fakes = this->allTimingSegments[SEGMENT_FAKE];
|
|
|
|
|
if( fakes.empty() )
|
|
|
|
|
return new FakeSegment();
|
2011-05-16 02:00:17 -04:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_FAKE, iRow );
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<FakeSegment *>(fakes[i]);
|
2011-05-16 02:00:17 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 23:15:48 -04:00
|
|
|
TickcountSegment* TimingData::GetTickcountSegmentAtRow( int iRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
vector<TimingSegment *> &ticks = this->allTimingSegments[SEGMENT_TICKCOUNT];
|
|
|
|
|
if( ticks.empty() )
|
|
|
|
|
return new TickcountSegment();
|
2011-03-17 01:47:30 -04:00
|
|
|
|
2011-07-14 21:51:09 -04:00
|
|
|
int i = GetSegmentIndexAtRow( SEGMENT_TICKCOUNT, iRow );
|
2011-07-14 23:15:48 -04:00
|
|
|
return static_cast<TickcountSegment *>(ticks[i]);
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TimingData::GetTickcountAtRow( int iRow ) const
|
|
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
const vector<TimingSegment *> &ticks = this->allTimingSegments[SEGMENT_TICKCOUNT];
|
|
|
|
|
const int index = GetSegmentIndexAtRow( SEGMENT_TICKCOUNT, iRow );
|
|
|
|
|
return static_cast<TickcountSegment *>(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-07-14 23:15:48 -04:00
|
|
|
const vector<TimingSegment *> &labels = this->allTimingSegments[SEGMENT_LABEL];
|
|
|
|
|
for (unsigned i = 0; i < labels.size(); i++)
|
2011-04-05 14:18:29 -04:00
|
|
|
{
|
2011-07-14 23:15:48 -04:00
|
|
|
if (static_cast<LabelSegment *>(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,
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
const vector<TimingSegment *> * segs = this->allTimingSegments;
|
|
|
|
|
vector<TimingSegment *>::const_iterator itBPMS = segs[SEGMENT_BPM].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itWS = segs[SEGMENT_WARP].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itSS = segs[SEGMENT_STOP_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-15 00:54:11 -04:00
|
|
|
if (itSS != segs[SEGMENT_STOP_DELAY].end() &&
|
|
|
|
|
(*itSS)->GetRow() < iEventRow )
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
iEventRow = (*itSS)->GetRow();
|
2011-03-25 23:19:31 +07:00
|
|
|
iEventType = 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 )
|
|
|
|
|
{
|
|
|
|
|
case FOUND_WARP_DESTINATION:
|
|
|
|
|
bIsWarping = false;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_BPM_CHANGE:
|
2011-07-15 00:54:11 -04:00
|
|
|
fBPS = static_cast<BPMSegment *>(*itBPMS)->GetBPS();
|
2011-03-25 23:19:31 +07:00
|
|
|
itBPMS ++;
|
|
|
|
|
break;
|
2011-03-30 21:57:54 -04:00
|
|
|
case FOUND_STOP:
|
2011-03-25 23:19:31 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
const StopSegment *ss = static_cast<StopSegment *>(*itSS);
|
|
|
|
|
fTimeToNextEvent = ss->GetPause();
|
2011-03-26 11:59:48 -05:00
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
2011-07-15 00:54:11 -04:00
|
|
|
const bool bIsDelay = ss->GetDelay();
|
2011-03-26 11:59:48 -05:00
|
|
|
if ( fElapsedTime < fNextEventTime )
|
|
|
|
|
{
|
|
|
|
|
bFreezeOut = !bIsDelay;
|
|
|
|
|
bDelayOut = bIsDelay;
|
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-03-25 23:19:31 +07:00
|
|
|
}
|
|
|
|
|
break;
|
2011-03-26 22:07:24 +07:00
|
|
|
case FOUND_WARP:
|
|
|
|
|
{
|
2011-05-16 10:24:59 -04:00
|
|
|
bIsWarping = true;
|
2011-07-15 00:54:11 -04:00
|
|
|
const WarpSegment *ws = static_cast<WarpSegment *>(*itWS);
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
const vector<TimingSegment *> * segs = this->allTimingSegments;
|
|
|
|
|
vector<TimingSegment *>::const_iterator itBPMS = segs[SEGMENT_BPM].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itWS = segs[SEGMENT_WARP].begin();
|
|
|
|
|
vector<TimingSegment *>::const_iterator itSS = segs[SEGMENT_STOP_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-15 00:54:11 -04:00
|
|
|
if (itSS != segs[SEGMENT_STOP_DELAY].end() &&
|
|
|
|
|
static_cast<StopSegment *>(*itSS)->GetDelay() &&
|
|
|
|
|
(*itSS)->GetRow() < iEventRow ) // delays (come before 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;
|
|
|
|
|
}
|
|
|
|
|
if( BeatToNoteRow(fBeat) < iEventRow )
|
|
|
|
|
{
|
|
|
|
|
iEventRow = BeatToNoteRow(fBeat);
|
|
|
|
|
iEventType = FOUND_MARKER;
|
|
|
|
|
}
|
2011-07-15 00:54:11 -04:00
|
|
|
if (itSS != segs[SEGMENT_STOP_DELAY].end() &&
|
|
|
|
|
!static_cast<StopSegment *>(*itSS)->GetDelay() &&
|
|
|
|
|
(*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-07-15 00:54:11 -04:00
|
|
|
fBPS = static_cast<BPMSegment *>(*itBPMS)->GetBPS();
|
2011-03-25 23:19:31 +07:00
|
|
|
itBPMS ++;
|
|
|
|
|
break;
|
|
|
|
|
case FOUND_STOP:
|
2011-07-15 00:54:11 -04:00
|
|
|
fTimeToNextEvent = static_cast<StopSegment *>(*itSS)->GetPause();
|
2011-03-25 23:19:31 +07:00
|
|
|
fNextEventTime = fLastTime + fTimeToNextEvent;
|
|
|
|
|
fLastTime = fNextEventTime;
|
|
|
|
|
itSS ++;
|
|
|
|
|
break;
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
WarpSegment *ws = static_cast<WarpSegment *>(*itWS);
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
const vector<TimingSegment *> &scrolls = this->allTimingSegments[SEGMENT_SCROLL];
|
|
|
|
|
vector<TimingSegment *>::const_iterator it = scrolls.begin(), end = scrolls.end();
|
2011-06-12 03:37:10 -04:00
|
|
|
float fOutBeat = 0;
|
2011-07-17 13:03:21 +07:00
|
|
|
for( it = it + 1; it != end; it++ )
|
|
|
|
|
{
|
|
|
|
|
ASSERT((*(it-1))->GetBeat() <= (*it)->GetBeat());
|
|
|
|
|
}
|
|
|
|
|
it = scrolls.begin();
|
2011-06-04 19:02:45 +07:00
|
|
|
for( ; it != end; it++ )
|
2011-05-25 22:44:41 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
if( it+1 == end || fBeat <= (*(it+1))->GetBeat() )
|
2011-06-04 19:02:45 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
fOutBeat += ( fBeat - (*it)->GetBeat() ) *
|
|
|
|
|
static_cast<ScrollSegment *>(*it)->GetRatio();
|
2011-06-04 19:02:45 +07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
fOutBeat += ( (*(it+1))->GetBeat() - (*it)->GetBeat() ) *
|
|
|
|
|
static_cast<ScrollSegment *>(*it)->GetRatio();
|
2011-06-04 19:02:45 +07:00
|
|
|
}
|
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-14 23:15:48 -04:00
|
|
|
// TODO: Confirm this works as intended.
|
2011-07-15 00:14:13 -04:00
|
|
|
for (unsigned i = 0; i < NUM_TimingSegmentType; i++)
|
2011-07-14 23:15:48 -04:00
|
|
|
{
|
|
|
|
|
vector<TimingSegment *> &segs = this->allTimingSegments[i];
|
|
|
|
|
for (unsigned j = 0; j < segs.size(); j++)
|
|
|
|
|
{
|
|
|
|
|
segs[i][j].Scale(iStartIndex, length, newLength);
|
|
|
|
|
}
|
|
|
|
|
}
|
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-07-15 00:54:11 -04:00
|
|
|
vector<TimingSegment *> &bpms = this->allTimingSegments[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-07-15 00:54:11 -04:00
|
|
|
BPMSegment *bpm = static_cast<BPMSegment *>(bpms[i]);
|
|
|
|
|
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-07-14 15:22:32 -04:00
|
|
|
vector<TimingSegment *> &segs = this->allTimingSegments[i];
|
|
|
|
|
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-07-14 15:22:32 -04:00
|
|
|
vector<TimingSegment *> &bpms = this->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
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. */
|
|
|
|
|
float fNewBPM = this->GetBPMAtBeat( NoteRowToBeat(iStartRow+iRowsToDelete) );
|
|
|
|
|
|
|
|
|
|
/* 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-07-14 15:22:32 -04:00
|
|
|
vector<TimingSegment *> &segs = this->allTimingSegments[i];
|
|
|
|
|
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-03-17 01:47:30 -04:00
|
|
|
this->SetBPMAtRow( iStartRow, fNewBPM );
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const vector<TimingSegment *> &speeds = this->allTimingSegments[SEGMENT_SPEED];
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
const SpeedSegment *seg = static_cast<SpeedSegment *>(speeds[index]);
|
|
|
|
|
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-07-15 00:54:11 -04:00
|
|
|
fEndTime = fStartTime + seg->GetLength();
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
fEndTime = GetElapsedTimeFromBeat( fStartBeat + seg->GetLength() )
|
|
|
|
|
- GetDelayAtBeat( fStartBeat + seg->GetLength() );
|
2011-05-24 11:43:08 +07:00
|
|
|
}
|
|
|
|
|
|
2011-07-15 00:54:11 -04:00
|
|
|
SpeedSegment *first = static_cast<SpeedSegment *>(speeds[0]);
|
|
|
|
|
|
|
|
|
|
if( ( index == 0 && first->GetLength() > 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-07-15 00:54:11 -04:00
|
|
|
else if( fEndTime >= fCurTime && ( index > 0 || first->GetLength() > 0.0 ) )
|
2011-05-24 11:43:08 +07:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
const float fPriorSpeed = (index == 0 ?
|
|
|
|
|
1 :
|
|
|
|
|
static_cast<SpeedSegment *>(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-07-15 00:54:11 -04:00
|
|
|
vector<TimingSegment *> *segs = this->allTimingSegments;
|
|
|
|
|
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-07-14 15:22:32 -04:00
|
|
|
return this->allTimingSegments[SEGMENT_BPM].size()>1;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasStops() const
|
|
|
|
|
{
|
2011-07-14 15:22:32 -04:00
|
|
|
return this->allTimingSegments[SEGMENT_STOP_DELAY].size()>0;
|
2011-03-17 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasWarps() const
|
|
|
|
|
{
|
2011-07-14 15:22:32 -04:00
|
|
|
return this->allTimingSegments[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-07-14 15:22:32 -04:00
|
|
|
return this->allTimingSegments[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-07-14 23:15:48 -04:00
|
|
|
const vector<TimingSegment *> &speeds = this->allTimingSegments[SEGMENT_SPEED];
|
|
|
|
|
return (speeds.size()>1 ||
|
|
|
|
|
static_cast<SpeedSegment *>(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-07-14 23:15:48 -04:00
|
|
|
const vector<TimingSegment *> &scrolls = this->allTimingSegments[SEGMENT_SCROLL];
|
|
|
|
|
return (scrolls.size()>1 ||
|
|
|
|
|
static_cast<ScrollSegment *>(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-07-15 00:54:11 -04:00
|
|
|
const vector<TimingSegment *> &tSigs = this->allTimingSegments[SEGMENT_TIME_SIG];
|
|
|
|
|
for (unsigned i = 0; i < tSigs.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-15 00:54:11 -04:00
|
|
|
TimeSignatureSegment *curSig = static_cast<TimeSignatureSegment *>(tSigs[i]);
|
|
|
|
|
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-17 16:06:40 -04:00
|
|
|
vector<RString> TimingData::ToVectorString(TimingSegmentType tst,
|
|
|
|
|
bool isDelay, int dec) const
|
|
|
|
|
{
|
|
|
|
|
const vector<TimingSegment *> segs = this->allTimingSegments[tst];
|
|
|
|
|
vector<RString> ret;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < segs.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (tst == SEGMENT_STOP_DELAY)
|
|
|
|
|
{
|
|
|
|
|
StopSegment *seg = static_cast<StopSegment *>(segs[i]);
|
2011-07-17 23:58:22 -04:00
|
|
|
if (seg->GetDelay() != isDelay)
|
2011-07-17 16:06:40 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
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-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_STOP_DELAY, false), L);
|
2011-03-17 01:47:30 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetDelays( T* p, lua_State *L )
|
|
|
|
|
{
|
2011-07-17 16:06:40 -04:00
|
|
|
LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_STOP_DELAY, true), L);
|
2011-03-17 01:47:30 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
static int GetBPMs( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
vector<float> vBPMs;
|
2011-07-14 15:22:32 -04:00
|
|
|
vector<TimingSegment *> &bpms = p->allTimingSegments[SEGMENT_BPM];
|
|
|
|
|
for (unsigned i = 0; i < bpms.size(); i++)
|
2011-03-17 01:47:30 -04:00
|
|
|
{
|
2011-07-14 15:22:32 -04:00
|
|
|
BPMSegment *seg = static_cast<BPMSegment *>(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 );
|
|
|
|
|
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.
|
|
|
|
|
*/
|