2003-12-18 04:42:54 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "TimingData.h"
|
2006-03-29 11:12:20 +00:00
|
|
|
#include "PrefsManager.h"
|
2004-01-28 21:28:43 +00:00
|
|
|
#include "RageUtil.h"
|
2004-10-26 19:18:03 +00:00
|
|
|
#include "RageLog.h"
|
2005-01-23 21:55:01 +00:00
|
|
|
#include "NoteTypes.h"
|
2006-07-20 01:56:17 +00:00
|
|
|
#include "Foreach.h"
|
2005-03-25 20:01:51 +00:00
|
|
|
#include <float.h>
|
2005-01-23 21:55:01 +00:00
|
|
|
|
2007-04-30 05:12:48 +00:00
|
|
|
|
2003-12-18 04:42:54 +00:00
|
|
|
TimingData::TimingData()
|
|
|
|
|
{
|
|
|
|
|
m_fBeat0OffsetInSeconds = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut ) const
|
|
|
|
|
{
|
2005-03-25 20:01:51 +00:00
|
|
|
fMinBPMOut = FLT_MAX;
|
2005-01-23 23:17:12 +00:00
|
|
|
fMaxBPMOut = 0;
|
2006-07-20 01:56:17 +00:00
|
|
|
FOREACH_CONST( BPMSegment, m_BPMSegments, seg )
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2006-07-20 01:56:17 +00:00
|
|
|
const float fBPM = seg->GetBPM();
|
|
|
|
|
fMaxBPMOut = max( fBPM, fMaxBPMOut );
|
|
|
|
|
fMinBPMOut = min( fBPM, fMinBPMOut );
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TimingData::AddBPMSegment( const BPMSegment &seg )
|
|
|
|
|
{
|
2006-07-20 01:56:17 +00:00
|
|
|
m_BPMSegments.insert( upper_bound(m_BPMSegments.begin(), m_BPMSegments.end(), seg), seg );
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::AddStopSegment( const StopSegment &seg )
|
|
|
|
|
{
|
2006-07-20 01:56:17 +00:00
|
|
|
m_StopSegments.insert( upper_bound(m_StopSegments.begin(), m_StopSegments.end(), seg), seg );
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-30 05:12:48 +00:00
|
|
|
void TimingData::AddTimeSignatureSegment( const TimeSignatureSegment &seg )
|
|
|
|
|
{
|
|
|
|
|
m_vTimeSignatureSegments.insert( upper_bound(m_vTimeSignatureSegments.begin(), m_vTimeSignatureSegments.end(), seg), seg );
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-08 13:57:48 +00:00
|
|
|
/* Change an existing BPM segment, merge identical segments together or insert a new one. */
|
2005-12-18 07:29:31 +00:00
|
|
|
void TimingData::SetBPMAtRow( int iNoteRow, float fBPM )
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2005-01-23 23:17:12 +00:00
|
|
|
float fBPS = fBPM / 60.0f;
|
2003-12-18 04:42:54 +00:00
|
|
|
unsigned i;
|
|
|
|
|
for( i=0; i<m_BPMSegments.size(); i++ )
|
2007-04-25 22:42:40 +00:00
|
|
|
if( m_BPMSegments[i].m_iStartRow >= iNoteRow )
|
2003-12-18 04:42:54 +00:00
|
|
|
break;
|
|
|
|
|
|
2007-04-25 22:42:40 +00:00
|
|
|
if( i == m_BPMSegments.size() || m_BPMSegments[i].m_iStartRow != iNoteRow )
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2005-01-08 13:57:48 +00: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.
|
2005-02-10 04:59:03 +00:00
|
|
|
if( i == 0 || fabsf(m_BPMSegments[i-1].m_fBPS - fBPS) > 1e-5f )
|
|
|
|
|
AddBPMSegment( BPMSegment(iNoteRow, fBPM) );
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
else // BPMSegment being modified is m_BPMSegments[i]
|
|
|
|
|
{
|
2005-02-10 04:59:03 +00:00
|
|
|
if( i > 0 && fabsf(m_BPMSegments[i-1].m_fBPS - fBPS) < 1e-5f )
|
2006-06-28 18:45:06 +00:00
|
|
|
m_BPMSegments.erase( m_BPMSegments.begin()+i, m_BPMSegments.begin()+i+1 );
|
2003-12-18 04:42:54 +00:00
|
|
|
else
|
2005-01-23 23:17:12 +00:00
|
|
|
m_BPMSegments[i].m_fBPS = fBPS;
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:29:31 +00:00
|
|
|
void TimingData::SetStopAtRow( int iRow, float fSeconds )
|
2005-01-08 13:58:34 +00:00
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
for( i=0; i<m_StopSegments.size(); i++ )
|
2005-01-23 21:55:01 +00:00
|
|
|
if( m_StopSegments[i].m_iStartRow == iRow )
|
2005-01-08 13:58:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if( i == m_StopSegments.size() ) // there is no BPMSegment at the current beat
|
|
|
|
|
{
|
|
|
|
|
// create a new StopSegment
|
|
|
|
|
if( fSeconds > 0 )
|
2005-01-23 21:55:01 +00:00
|
|
|
AddStopSegment( StopSegment(iRow, fSeconds) );
|
2005-01-08 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
else // StopSegment being modified is m_StopSegments[i]
|
|
|
|
|
{
|
|
|
|
|
if( fSeconds > 0 )
|
|
|
|
|
m_StopSegments[i].m_fStopSeconds = fSeconds;
|
|
|
|
|
else
|
|
|
|
|
m_StopSegments.erase( m_StopSegments.begin()+i, m_StopSegments.begin()+i+1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-19 00:07:34 +00:00
|
|
|
float TimingData::GetStopAtRow( int iNoteRow ) const
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<m_StopSegments.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( m_StopSegments[i].m_iStartRow == iNoteRow )
|
|
|
|
|
return m_StopSegments[i].m_fStopSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-08 22:24:18 +00:00
|
|
|
/* Multiply the BPM in the range [fStartBeat,fEndBeat) by fFactor. */
|
2005-01-23 21:55:01 +00:00
|
|
|
void TimingData::MultiplyBPMInBeatRange( int iStartIndex, int iEndIndex, float fFactor )
|
2004-11-08 22:24:18 +00:00
|
|
|
{
|
|
|
|
|
/* Change all other BPM segments in this range. */
|
|
|
|
|
for( unsigned i=0; i<m_BPMSegments.size(); i++ )
|
2005-01-23 21:55:01 +00:00
|
|
|
{
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iStartIndexThisSegment = m_BPMSegments[i].m_iStartRow;
|
2005-01-23 21:55:01 +00:00
|
|
|
const bool bIsLastBPMSegment = i==m_BPMSegments.size()-1;
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iStartIndexNextSegment = bIsLastBPMSegment ? INT_MAX : m_BPMSegments[i+1].m_iStartRow;
|
2005-01-23 21:55:01 +00: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 )
|
|
|
|
|
{
|
|
|
|
|
BPMSegment b = m_BPMSegments[i];
|
2007-04-25 22:42:40 +00:00
|
|
|
b.m_iStartRow = iStartIndexNextSegment;
|
2005-01-23 21:55:01 +00:00
|
|
|
m_BPMSegments.insert( m_BPMSegments.begin()+i+1, b );
|
|
|
|
|
|
|
|
|
|
/* Don't apply the BPM change to the first half of the segment we just split,
|
|
|
|
|
* since it lies outside the range. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-11-08 22:24:18 +00:00
|
|
|
|
2005-01-23 21:55:01 +00:00
|
|
|
/* If this BPM segment crosses the end of the range, split it into two. */
|
|
|
|
|
if( iStartIndexThisSegment < iEndIndex && iStartIndexNextSegment > iEndIndex )
|
|
|
|
|
{
|
|
|
|
|
BPMSegment b = m_BPMSegments[i];
|
2007-04-25 22:42:40 +00:00
|
|
|
b.m_iStartRow = iEndIndex;
|
2005-01-23 21:55:01 +00:00
|
|
|
m_BPMSegments.insert( m_BPMSegments.begin()+i+1, b );
|
|
|
|
|
}
|
|
|
|
|
else if( iStartIndexNextSegment > iEndIndex )
|
|
|
|
|
continue;
|
|
|
|
|
|
2005-01-23 23:17:12 +00:00
|
|
|
m_BPMSegments[i].m_fBPS = m_BPMSegments[i].m_fBPS * fFactor;
|
2005-01-23 21:55:01 +00:00
|
|
|
}
|
2004-11-08 22:24:18 +00:00
|
|
|
}
|
2003-12-18 04:42:54 +00:00
|
|
|
|
|
|
|
|
float TimingData::GetBPMAtBeat( float fBeat ) const
|
|
|
|
|
{
|
2005-01-23 21:55:01 +00:00
|
|
|
int iIndex = BeatToNoteRow( fBeat );
|
2003-12-18 04:42:54 +00:00
|
|
|
unsigned i;
|
|
|
|
|
for( i=0; i<m_BPMSegments.size()-1; i++ )
|
2007-04-25 22:42:40 +00:00
|
|
|
if( m_BPMSegments[i+1].m_iStartRow > iIndex )
|
2003-12-18 04:42:54 +00:00
|
|
|
break;
|
2005-01-23 21:55:01 +00:00
|
|
|
return m_BPMSegments[i].GetBPM();
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-19 23:29:39 +00:00
|
|
|
int TimingData::GetBPMSegmentIndexAtBeat( float fBeat )
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2005-01-23 21:55:01 +00:00
|
|
|
int iIndex = BeatToNoteRow( fBeat );
|
2005-05-19 23:29:39 +00:00
|
|
|
int i;
|
|
|
|
|
for( i=0; i<(int)(m_BPMSegments.size())-1; i++ )
|
2007-04-25 22:42:40 +00:00
|
|
|
if( m_BPMSegments[i+1].m_iStartRow > iIndex )
|
2003-12-18 04:42:54 +00:00
|
|
|
break;
|
2005-05-19 23:29:39 +00:00
|
|
|
return i;
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-23 02:29:22 +00:00
|
|
|
const TimeSignatureSegment& TimingData::GetTimeSignatureSegmentAtBeat( float fBeat ) const
|
|
|
|
|
{
|
|
|
|
|
int iIndex = BeatToNoteRow( fBeat );
|
|
|
|
|
unsigned i;
|
|
|
|
|
for( i=0; i<m_vTimeSignatureSegments.size()-1; i++ )
|
|
|
|
|
if( m_vTimeSignatureSegments[i+1].m_iStartRow > iIndex )
|
|
|
|
|
break;
|
|
|
|
|
return m_vTimeSignatureSegments[i];
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-19 23:29:39 +00:00
|
|
|
BPMSegment& TimingData::GetBPMSegmentAtBeat( float fBeat )
|
|
|
|
|
{
|
|
|
|
|
static BPMSegment empty;
|
|
|
|
|
if( m_BPMSegments.empty() )
|
|
|
|
|
return empty;
|
|
|
|
|
|
|
|
|
|
int i = GetBPMSegmentIndexAtBeat( fBeat );
|
|
|
|
|
return m_BPMSegments[i];
|
|
|
|
|
}
|
2003-12-18 04:42:54 +00:00
|
|
|
|
|
|
|
|
void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const
|
2006-03-29 11:12:20 +00:00
|
|
|
{
|
|
|
|
|
fElapsedTime += PREFSMAN->m_fGlobalOffsetSeconds;
|
|
|
|
|
|
|
|
|
|
GetBeatAndBPSFromElapsedTimeNoOffset( fElapsedTime, fBeatOut, fBPSOut, bFreezeOut );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingData::GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
|
|
|
|
// LOG->Trace( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime );
|
2008-07-28 07:35:56 +00:00
|
|
|
const float fTime = fElapsedTime;
|
2003-12-18 04:42:54 +00:00
|
|
|
fElapsedTime += m_fBeat0OffsetInSeconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<m_BPMSegments.size(); i++ ) // foreach BPMSegment
|
|
|
|
|
{
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iStartRowThisSegment = m_BPMSegments[i].m_iStartRow;
|
2005-01-23 21:55:01 +00:00
|
|
|
const float fStartBeatThisSegment = NoteRowToBeat( iStartRowThisSegment );
|
2004-02-24 23:40:28 +00:00
|
|
|
const bool bIsFirstBPMSegment = i==0;
|
2004-01-28 21:28:43 +00:00
|
|
|
const bool bIsLastBPMSegment = i==m_BPMSegments.size()-1;
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iStartRowNextSegment = bIsLastBPMSegment ? MAX_NOTE_ROW : m_BPMSegments[i+1].m_iStartRow;
|
2005-01-23 21:55:01 +00:00
|
|
|
const float fStartBeatNextSegment = NoteRowToBeat( iStartRowNextSegment );
|
2005-01-23 23:17:12 +00:00
|
|
|
const float fBPS = m_BPMSegments[i].m_fBPS;
|
2003-12-18 04:42:54 +00:00
|
|
|
|
2004-01-28 21:28:43 +00:00
|
|
|
for( unsigned j=0; j<m_StopSegments.size(); j++ ) // foreach freeze
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2005-01-23 21:55:01 +00:00
|
|
|
if( !bIsFirstBPMSegment && iStartRowThisSegment >= m_StopSegments[j].m_iStartRow )
|
2004-01-28 21:28:43 +00:00
|
|
|
continue;
|
2005-01-23 21:55:01 +00:00
|
|
|
if( !bIsLastBPMSegment && m_StopSegments[j].m_iStartRow > iStartRowNextSegment )
|
2003-12-18 04:42:54 +00:00
|
|
|
continue;
|
|
|
|
|
|
2005-01-23 23:17:12 +00:00
|
|
|
// this freeze lies within this BPMSegment
|
2005-01-23 21:55:01 +00:00
|
|
|
const int iRowsBeatsSinceStartOfSegment = m_StopSegments[j].m_iStartRow - iStartRowThisSegment;
|
|
|
|
|
const float fBeatsSinceStartOfSegment = NoteRowToBeat(iRowsBeatsSinceStartOfSegment);
|
2004-01-28 21:28:43 +00:00
|
|
|
const float fFreezeStartSecond = fBeatsSinceStartOfSegment / fBPS;
|
|
|
|
|
|
|
|
|
|
if( fFreezeStartSecond >= fElapsedTime )
|
2003-12-18 04:42:54 +00:00
|
|
|
break;
|
|
|
|
|
|
2004-01-28 21:28:43 +00:00
|
|
|
// the freeze segment is <= current time
|
2003-12-18 04:42:54 +00:00
|
|
|
fElapsedTime -= m_StopSegments[j].m_fStopSeconds;
|
2004-01-28 21:28:43 +00:00
|
|
|
|
|
|
|
|
if( fFreezeStartSecond >= fElapsedTime )
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
2004-01-28 21:28:43 +00:00
|
|
|
/* The time lies within the stop. */
|
2005-01-23 21:55:01 +00:00
|
|
|
fBeatOut = NoteRowToBeat(m_StopSegments[j].m_iStartRow);
|
2003-12-18 04:42:54 +00:00
|
|
|
fBPSOut = fBPS;
|
|
|
|
|
bFreezeOut = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-28 21:28:43 +00:00
|
|
|
const float fBeatsInThisSegment = fStartBeatNextSegment - fStartBeatThisSegment;
|
|
|
|
|
const float fSecondsInThisSegment = fBeatsInThisSegment / fBPS;
|
|
|
|
|
if( bIsLastBPMSegment || fElapsedTime <= fSecondsInThisSegment )
|
|
|
|
|
{
|
|
|
|
|
// this BPMSegment IS the current segment
|
|
|
|
|
fBeatOut = fStartBeatThisSegment + fElapsedTime*fBPS;
|
|
|
|
|
fBPSOut = fBPS;
|
|
|
|
|
bFreezeOut = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this BPMSegment is NOT the current segment
|
|
|
|
|
fElapsedTime -= fSecondsInThisSegment;
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
2008-07-28 07:35:56 +00:00
|
|
|
// If we get here, something has gone wrong. Is everything sorted?
|
|
|
|
|
vector<BPMSegment> vBPMS = m_BPMSegments;
|
|
|
|
|
vector<StopSegment> vSS = m_StopSegments;
|
|
|
|
|
sort( vBPMS.begin(), vBPMS.end() );
|
|
|
|
|
sort( vSS.begin(), vSS.end() );
|
|
|
|
|
ASSERT_M( vBPMS == m_BPMSegments, "The BPM segments were not sorted!" );
|
|
|
|
|
ASSERT_M( vSS == m_StopSegments, "The Stop segments were not sorted!" );
|
|
|
|
|
FAIL_M( ssprintf("Failed to find the appropriate segment for elapsed time %f.", fTime) );
|
2003-12-18 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float TimingData::GetElapsedTimeFromBeat( float fBeat ) const
|
2006-03-29 11:12:20 +00:00
|
|
|
{
|
|
|
|
|
return TimingData::GetElapsedTimeFromBeatNoOffset( fBeat ) - PREFSMAN->m_fGlobalOffsetSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const
|
2003-12-18 04:42:54 +00:00
|
|
|
{
|
|
|
|
|
float fElapsedTime = 0;
|
|
|
|
|
fElapsedTime -= m_fBeat0OffsetInSeconds;
|
|
|
|
|
|
2005-01-23 21:55:01 +00:00
|
|
|
int iRow = BeatToNoteRow(fBeat);
|
2003-12-18 04:42:54 +00:00
|
|
|
for( unsigned j=0; j<m_StopSegments.size(); j++ ) // foreach freeze
|
|
|
|
|
{
|
2004-01-28 21:28:43 +00:00
|
|
|
/* The exact beat of a stop comes before the stop, not after, so use >=, not >. */
|
2005-01-23 21:55:01 +00:00
|
|
|
if( m_StopSegments[j].m_iStartRow >= iRow )
|
2003-12-18 04:42:54 +00:00
|
|
|
break;
|
|
|
|
|
fElapsedTime += m_StopSegments[j].m_fStopSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<m_BPMSegments.size(); i++ ) // foreach BPMSegment
|
|
|
|
|
{
|
|
|
|
|
const bool bIsLastBPMSegment = i==m_BPMSegments.size()-1;
|
2005-01-23 23:17:12 +00:00
|
|
|
const float fBPS = m_BPMSegments[i].m_fBPS;
|
2003-12-18 04:42:54 +00:00
|
|
|
|
2004-01-28 21:28:43 +00:00
|
|
|
if( bIsLastBPMSegment )
|
|
|
|
|
{
|
2005-01-23 23:17:12 +00:00
|
|
|
fElapsedTime += NoteRowToBeat( iRow ) / fBPS;
|
2004-01-28 21:28:43 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iStartIndexThisSegment = m_BPMSegments[i].m_iStartRow;
|
|
|
|
|
const int iStartIndexNextSegment = m_BPMSegments[i+1].m_iStartRow;
|
2005-01-23 23:17:12 +00:00
|
|
|
const int iRowsInThisSegment = min( iStartIndexNextSegment - iStartIndexThisSegment, iRow );
|
|
|
|
|
fElapsedTime += NoteRowToBeat( iRowsInThisSegment ) / fBPS;
|
|
|
|
|
iRow -= iRowsInThisSegment;
|
2004-01-28 21:28:43 +00:00
|
|
|
}
|
2003-12-18 04:42:54 +00:00
|
|
|
|
2005-01-23 23:17:12 +00:00
|
|
|
if( iRow <= 0 )
|
2003-12-18 04:42:54 +00:00
|
|
|
return fElapsedTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fElapsedTime;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-23 21:55:01 +00:00
|
|
|
void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2004-02-26 05:38:46 +00:00
|
|
|
ASSERT( fScale > 0 );
|
2005-01-23 21:55:01 +00:00
|
|
|
ASSERT( iStartIndex >= 0 );
|
|
|
|
|
ASSERT( iStartIndex < iEndIndex );
|
2004-02-26 05:38:46 +00:00
|
|
|
|
2005-12-18 07:28:48 +00:00
|
|
|
for ( unsigned i = 0; i < m_BPMSegments.size(); i++ )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2007-04-25 22:42:40 +00:00
|
|
|
const int iSegStart = m_BPMSegments[i].m_iStartRow;
|
2005-01-23 21:55:01 +00:00
|
|
|
if( iSegStart < iStartIndex )
|
2004-02-26 05:38:46 +00:00
|
|
|
continue;
|
2005-01-23 21:55:01 +00:00
|
|
|
else if( iSegStart > iEndIndex )
|
2007-04-25 22:42:40 +00:00
|
|
|
m_BPMSegments[i].m_iStartRow += lrintf( (iEndIndex - iStartIndex) * (fScale - 1) );
|
2004-02-26 05:38:46 +00:00
|
|
|
else
|
2007-04-25 22:42:40 +00:00
|
|
|
m_BPMSegments[i].m_iStartRow = lrintf( (iSegStart - iStartIndex) * fScale ) + iStartIndex;
|
2004-02-26 05:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:28:48 +00:00
|
|
|
for( unsigned i = 0; i < m_StopSegments.size(); i++ )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2005-12-18 07:28:48 +00:00
|
|
|
const int iSegStartRow = m_StopSegments[i].m_iStartRow;
|
2005-01-23 21:55:01 +00:00
|
|
|
if( iSegStartRow < iStartIndex )
|
2004-02-26 05:38:46 +00:00
|
|
|
continue;
|
2005-01-23 21:55:01 +00:00
|
|
|
else if( iSegStartRow > iEndIndex )
|
2005-12-18 07:28:48 +00:00
|
|
|
m_StopSegments[i].m_iStartRow += lrintf((iEndIndex - iStartIndex) * (fScale - 1));
|
2004-02-26 05:38:46 +00:00
|
|
|
else
|
2005-12-18 07:28:48 +00:00
|
|
|
m_StopSegments[i].m_iStartRow = lrintf((iSegStartRow - iStartIndex) * fScale) + iStartIndex;
|
2004-02-26 05:38:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:55:01 +00:00
|
|
|
void TimingData::InsertRows( int iStartRow, int iRowsToAdd )
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i = 0; i < m_BPMSegments.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
BPMSegment &bpm = m_BPMSegments[i];
|
2007-04-25 22:42:40 +00:00
|
|
|
if( bpm.m_iStartRow < iStartRow )
|
2005-12-18 07:55:01 +00:00
|
|
|
continue;
|
2007-04-25 22:42:40 +00:00
|
|
|
bpm.m_iStartRow += iRowsToAdd;
|
2005-12-18 07:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_StopSegments.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
StopSegment &stop = m_StopSegments[i];
|
|
|
|
|
if( stop.m_iStartRow < iStartRow )
|
|
|
|
|
continue;
|
|
|
|
|
stop.m_iStartRow += iRowsToAdd;
|
|
|
|
|
}
|
2005-12-18 08:09:27 +00: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. */
|
|
|
|
|
ASSERT( m_BPMSegments.size() > 0 );
|
2007-04-25 22:42:40 +00:00
|
|
|
m_BPMSegments[0].m_iStartRow = 0;
|
2005-12-18 08:09:27 +00:00
|
|
|
}
|
2005-12-18 07:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete BPMChanges and StopSegments in [iStartRow,iRowsToDelete), and shift down. */
|
|
|
|
|
void TimingData::DeleteRows( int iStartRow, int iRowsToDelete )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2005-12-18 07:55:01 +00:00
|
|
|
/* 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. */
|
2005-12-18 07:28:48 +00:00
|
|
|
for( unsigned i = 0; i < m_BPMSegments.size(); i++ )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2005-12-18 07:55:01 +00:00
|
|
|
BPMSegment &bpm = m_BPMSegments[i];
|
2005-12-18 07:58:53 +00:00
|
|
|
|
|
|
|
|
/* Before deleted region: */
|
2007-04-25 22:42:40 +00:00
|
|
|
if( bpm.m_iStartRow < iStartRow )
|
2004-02-26 05:38:46 +00:00
|
|
|
continue;
|
2004-02-26 06:00:52 +00:00
|
|
|
|
2005-12-18 07:58:53 +00:00
|
|
|
/* Inside deleted region: */
|
2007-04-25 22:42:40 +00:00
|
|
|
if( bpm.m_iStartRow < iStartRow+iRowsToDelete )
|
2005-12-18 07:55:01 +00:00
|
|
|
{
|
|
|
|
|
m_BPMSegments.erase( m_BPMSegments.begin()+i, m_BPMSegments.begin()+i+1 );
|
|
|
|
|
--i;
|
2005-12-18 07:58:53 +00:00
|
|
|
continue;
|
2005-12-18 07:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:58:53 +00:00
|
|
|
/* After deleted region: */
|
2007-04-25 22:42:40 +00:00
|
|
|
bpm.m_iStartRow -= iRowsToDelete;
|
2004-02-26 05:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:28:48 +00:00
|
|
|
for( unsigned i = 0; i < m_StopSegments.size(); i++ )
|
2004-02-26 06:00:52 +00:00
|
|
|
{
|
2005-12-18 07:55:01 +00:00
|
|
|
StopSegment &stop = m_StopSegments[i];
|
2005-12-18 07:58:53 +00:00
|
|
|
|
|
|
|
|
/* Before deleted region: */
|
2005-12-18 07:55:01 +00:00
|
|
|
if( stop.m_iStartRow < iStartRow )
|
2004-02-26 05:38:46 +00:00
|
|
|
continue;
|
2005-12-18 07:58:53 +00:00
|
|
|
|
|
|
|
|
/* Inside deleted region: */
|
2005-12-18 07:55:01 +00:00
|
|
|
if( stop.m_iStartRow < iStartRow+iRowsToDelete )
|
|
|
|
|
{
|
|
|
|
|
m_StopSegments.erase( m_StopSegments.begin()+i, m_StopSegments.begin()+i+1 );
|
|
|
|
|
--i;
|
2005-12-18 07:58:53 +00:00
|
|
|
continue;
|
2005-12-18 07:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-18 07:58:53 +00:00
|
|
|
/* After deleted region: */
|
2005-12-18 07:55:01 +00:00
|
|
|
stop.m_iStartRow -= iRowsToDelete;
|
2004-02-26 05:38:46 +00:00
|
|
|
}
|
2005-12-18 07:55:01 +00:00
|
|
|
|
|
|
|
|
this->SetBPMAtRow( iStartRow, fNewBPM );
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-10 20:29:42 +00:00
|
|
|
bool TimingData::HasBpmChanges() const
|
2004-03-08 07:49:01 +00:00
|
|
|
{
|
2005-06-10 20:29:42 +00:00
|
|
|
return m_BPMSegments.size()>1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimingData::HasStops() const
|
|
|
|
|
{
|
|
|
|
|
return m_StopSegments.size()>0;
|
2004-03-08 07:49:01 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-25 05:18:49 +00:00
|
|
|
bool TimingData::HasTimeSignatures() const
|
|
|
|
|
{
|
|
|
|
|
return m_vTimeSignatureSegments.size()>0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 05:12:48 +00:00
|
|
|
void TimingData::NoteRowToMeasureAndBeat( int iNoteRow, int &iMeasureIndexOut, int &iBeatIndexOut, int &iRowsRemainder ) const
|
|
|
|
|
{
|
|
|
|
|
iMeasureIndexOut = 0;
|
|
|
|
|
|
|
|
|
|
FOREACH_CONST( TimeSignatureSegment, m_vTimeSignatureSegments, iter )
|
|
|
|
|
{
|
|
|
|
|
vector<TimeSignatureSegment>::const_iterator next = iter;
|
|
|
|
|
next++;
|
|
|
|
|
int iSegmentEndRow = (next == m_vTimeSignatureSegments.end()) ? INT_MAX : next->m_iStartRow;
|
|
|
|
|
|
|
|
|
|
int iRowsPerMeasureThisSegment = iter->GetNoteRowsPerMeasure();
|
|
|
|
|
|
|
|
|
|
if( iNoteRow >= iter->m_iStartRow )
|
|
|
|
|
{
|
|
|
|
|
// iNoteRow lands in this segment
|
|
|
|
|
int iNumRowsThisSegment = iNoteRow - iter->m_iStartRow;
|
|
|
|
|
int iNumMeasuresThisSegment = (iNumRowsThisSegment) / iRowsPerMeasureThisSegment; // don't round up
|
|
|
|
|
iMeasureIndexOut += iNumMeasuresThisSegment;
|
|
|
|
|
iBeatIndexOut = iNumRowsThisSegment / iRowsPerMeasureThisSegment;
|
|
|
|
|
iRowsRemainder = iNumRowsThisSegment % iRowsPerMeasureThisSegment;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// iNoteRow lands after this segment
|
|
|
|
|
int iNumRowsThisSegment = iSegmentEndRow - iter->m_iStartRow;
|
|
|
|
|
int iNumMeasuresThisSegment = (iNumRowsThisSegment + iRowsPerMeasureThisSegment - 1) / iRowsPerMeasureThisSegment; // round up
|
|
|
|
|
iMeasureIndexOut += iNumMeasuresThisSegment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-15 09:21:53 +00:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
|
|
|
|
class LunaTimingData: public Luna<TimingData>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static int HasStops( T* p, lua_State *L ) { lua_pushboolean(L, p->HasStops()); return 1; }
|
|
|
|
|
|
|
|
|
|
LunaTimingData()
|
|
|
|
|
{
|
|
|
|
|
ADD_METHOD( HasStops );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( TimingData )
|
|
|
|
|
// lua end
|
|
|
|
|
|
2003-12-18 04:42:54 +00:00
|
|
|
/*
|
2004-05-31 21:35:31 +00:00
|
|
|
* (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.
|
2003-12-18 04:42:54 +00:00
|
|
|
*/
|