/* Holds data for translating beats<->seconds. */ #include "global.h" #include "TimingData.h" #include "PrefsManager.h" #include "RageUtil.h" TimingData::TimingData() { m_fBeat0OffsetInSeconds = 0; } static int CompareBPMSegments(const BPMSegment &seg1, const BPMSegment &seg2) { return seg1.m_fStartBeat < seg2.m_fStartBeat; } void SortBPMSegmentsArray( vector &arrayBPMSegments ) { sort( arrayBPMSegments.begin(), arrayBPMSegments.end(), CompareBPMSegments ); } static int CompareStopSegments(const StopSegment &seg1, const StopSegment &seg2) { return seg1.m_fStartBeat < seg2.m_fStartBeat; } void SortStopSegmentsArray( vector &arrayStopSegments ) { sort( arrayStopSegments.begin(), arrayStopSegments.end(), CompareStopSegments ); } void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut ) const { fMaxBPMOut = 0; fMinBPMOut = 100000; // inf for( unsigned i=0; i 0 && fabsf(m_BPMSegments[i-1].m_fBPM - fBPM) < 0.009f ) m_BPMSegments.erase( m_BPMSegments.begin()+i, m_BPMSegments.begin()+i+1); else m_BPMSegments[i].m_fBPM = fBPM; } } float TimingData::GetBPMAtBeat( float fBeat ) const { unsigned i; for( i=0; i fBeat ) break; return m_BPMSegments[i].m_fBPM; } BPMSegment& TimingData::GetBPMSegmentAtBeat( float fBeat ) { unsigned i; for( i=0; i fBeat ) break; return m_BPMSegments[i]; } void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const { // LOG->Trace( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime ); fElapsedTime += PREFSMAN->m_fGlobalOffsetSeconds; fElapsedTime += m_fBeat0OffsetInSeconds; for( unsigned i=0; i= m_StopSegments[j].m_fStartBeat ) continue; if( !bIsLastBPMSegment && m_StopSegments[j].m_fStartBeat > fStartBeatNextSegment ) continue; // this freeze lies within this BPMSegment const float fBeatsSinceStartOfSegment = m_StopSegments[j].m_fStartBeat - fStartBeatThisSegment; const float fFreezeStartSecond = fBeatsSinceStartOfSegment / fBPS; if( fFreezeStartSecond >= fElapsedTime ) break; // the freeze segment is <= current time fElapsedTime -= m_StopSegments[j].m_fStopSeconds; if( fFreezeStartSecond >= fElapsedTime ) { /* The time lies within the stop. */ fBeatOut = m_StopSegments[j].m_fStartBeat; fBPSOut = fBPS; bFreezeOut = true; return; } } 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; } } float TimingData::GetElapsedTimeFromBeat( float fBeat ) const { float fElapsedTime = 0; fElapsedTime -= PREFSMAN->m_fGlobalOffsetSeconds; fElapsedTime -= m_fBeat0OffsetInSeconds; for( unsigned j=0; j=, not >. */ if( m_StopSegments[j].m_fStartBeat >= fBeat ) break; fElapsedTime += m_StopSegments[j].m_fStopSeconds; } for( unsigned i=0; i 0 ); ASSERT( fStartBeat >= 0 ); ASSERT( fStartBeat < fEndBeat ); unsigned ix = 0; for ( ix = 0; ix < m_BPMSegments.size(); ix++ ) { const float fSegStart = m_BPMSegments[ix].m_fStartBeat; if( fSegStart < fStartBeat ) continue; else if( fSegStart > fEndBeat ) m_BPMSegments[ix].m_fStartBeat += (fEndBeat - fStartBeat) * (fScale - 1); else m_BPMSegments[ix].m_fStartBeat = (fSegStart - fStartBeat) * fScale + fStartBeat; } for( ix = 0; ix < m_StopSegments.size(); ix++ ) { const float fSegStart = m_StopSegments[ix].m_fStartBeat; if( fSegStart < fStartBeat ) continue; else if( fSegStart > fEndBeat ) m_StopSegments[ix].m_fStartBeat += (fEndBeat - fStartBeat) * (fScale - 1); else m_StopSegments[ix].m_fStartBeat = (fSegStart - fStartBeat) * fScale + fStartBeat; } } void TimingData::ShiftRows( float fStartBeat, float fBeatsToShift ) { unsigned ix = 0; for( ix = 0; ix < m_BPMSegments.size(); ix++ ) { float &fSegStart = m_BPMSegments[ix].m_fStartBeat; if( fSegStart < fStartBeat ) continue; fSegStart += fBeatsToShift; fSegStart = max( fSegStart, fStartBeat ); } for( ix = 0; ix < m_StopSegments.size(); ix++ ) { float &fSegStart = m_StopSegments[ix].m_fStartBeat; if( fSegStart < fStartBeat ) continue; fSegStart += fBeatsToShift; fSegStart = max( fSegStart, fStartBeat ); } } bool TimingData::HasBpmChangesOrStops() const { return m_BPMSegments.size()>1 || m_StopSegments.size()>0; } /* * Copyright (c) 2001-2004 by the person(s) listed below. All rights reserved. * Chris Danford * Glenn Maynard */