diff --git a/src/Background.cpp b/src/Background.cpp index 8c5a64c5fa..d8cef11d4e 100644 --- a/src/Background.cpp +++ b/src/Background.cpp @@ -450,7 +450,7 @@ void BackgroundImpl::LoadFromRandom( float fFirstBeat, float fEndBeat, const Bac bool bAtBeginningOfMeasure = false; FOREACH_CONST( TimeSignatureSegment, timing.m_vTimeSignatureSegments, iter ) { - if( (bpmseg.m_iStartRow - iter->m_iStartRow) % iter->GetNoteRowsPerMeasure() == 0 ) + if( (bpmseg.GetRow() - iter->m_iStartRow) % iter->GetNoteRowsPerMeasure() == 0 ) { bAtBeginningOfMeasure = true; break; @@ -461,7 +461,7 @@ void BackgroundImpl::LoadFromRandom( float fFirstBeat, float fEndBeat, const Bac continue; // skip // start so that we don't create a BGChange right on top of fEndBeat - bool bInRange = bpmseg.m_iStartRow >= iStartRow && bpmseg.m_iStartRow < iEndRow; + bool bInRange = bpmseg.GetRow() >= iStartRow && bpmseg.GetRow() < iEndRow; if( !bInRange ) continue; // skip @@ -471,7 +471,7 @@ void BackgroundImpl::LoadFromRandom( float fFirstBeat, float fEndBeat, const Bac BackgroundChange c = change; c.m_def.m_sFile1 = bd.m_sFile1; c.m_def.m_sFile2 = bd.m_sFile2; - c.m_fStartBeat = NoteRowToBeat(bpmseg.m_iStartRow); + c.m_fStartBeat = bpmseg.GetBeat(); m_Layer[0].m_aBGChanges.push_back( c ); } } diff --git a/src/NoteField.cpp b/src/NoteField.cpp index 0385dee466..3abb6bf177 100644 --- a/src/NoteField.cpp +++ b/src/NoteField.cpp @@ -899,9 +899,9 @@ void NoteField::DrawPrimitives() // BPM text FOREACH_CONST( BPMSegment, timing.m_BPMSegments, seg ) { - if( seg->m_iStartRow >= iFirstRowToDraw && seg->m_iStartRow <= iLastRowToDraw ) + if( seg->GetRow() >= iFirstRowToDraw && seg->GetRow() <= iLastRowToDraw ) { - float fBeat = NoteRowToBeat(seg->m_iStartRow); + float fBeat = seg->GetBeat(); if( IS_ON_SCREEN(fBeat) ) DrawBPMText( fBeat, seg->GetBPM() ); } diff --git a/src/NotesLoaderJson.cpp b/src/NotesLoaderJson.cpp index e460a0eaba..4478423e6b 100644 --- a/src/NotesLoaderJson.cpp +++ b/src/NotesLoaderJson.cpp @@ -17,8 +17,8 @@ void NotesLoaderJson::GetApplicableFiles( const RString &sPath, vector void Deserialize(BPMSegment &seg, const Json::Value &root) { - seg.m_iStartRow = BeatToNoteRow((float)root["Beat"].asDouble()); - seg.m_fBPS = (float)(root["BPM"].asDouble() / 60); + seg.SetBeat((float)(root["Beat"].asDouble())); + seg.SetBPM((float)(root["BPM"].asDouble())); } static void Deserialize(StopSegment &seg, const Json::Value &root) diff --git a/src/NotesLoaderMidi.cpp b/src/NotesLoaderMidi.cpp index 9673cdb14d..0d2a49b5e6 100644 --- a/src/NotesLoaderMidi.cpp +++ b/src/NotesLoaderMidi.cpp @@ -678,9 +678,9 @@ static bool LoadFromMidi( const RString &sPath, Song &songOut ) FOREACH_CONST( MidiFileIn::TempoChange, midi.tempoEvents_, iter ) { BPMSegment bpmSeg; - bpmSeg.m_iStartRow = MidiCountToNoteRow( iter->count ); + bpmSeg.SetRow( MidiCountToNoteRow( iter->count ) ); double fSecondsPerBeat = (iter->tickSeconds * GUITAR_MIDI_COUNTS_PER_BEAT); - bpmSeg.m_fBPS = float( 1. / fSecondsPerBeat ); + bpmSeg.SetBPS( float( 1. / fSecondsPerBeat ) ); songOut.m_SongTiming.AddBPMSegment( bpmSeg ); } diff --git a/src/NotesLoaderPMS.cpp b/src/NotesLoaderPMS.cpp index f9ef5bf1cc..749710abde 100644 --- a/src/NotesLoaderPMS.cpp +++ b/src/NotesLoaderPMS.cpp @@ -751,7 +751,7 @@ static void ReadGlobalTags( const NameToData_t &mapNameToData, Song &out, Measur { BPMSegment newSeg( iStepIndex, fBPM ); out.m_SongTiming.AddBPMSegment( newSeg ); - LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", NoteRowToBeat(newSeg.m_iStartRow), newSeg.GetBPM() ); + LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", newSeg.GetBeat(), newSeg.GetBPM() ); } else diff --git a/src/NotesWriterDWI.cpp b/src/NotesWriterDWI.cpp index 260728a70d..4694c1f6db 100644 --- a/src/NotesWriterDWI.cpp +++ b/src/NotesWriterDWI.cpp @@ -350,7 +350,7 @@ bool NotesWriterDWI::Write( RString sPath, const Song &out ) /* Write transliterations, if we have them, since DWI doesn't support UTF-8. */ f.PutLine( ssprintf("#TITLE:%s;", DwiEscape(out.GetTranslitFullTitle()).c_str()) ); f.PutLine( ssprintf("#ARTIST:%s;", DwiEscape(out.GetTranslitArtist()).c_str()) ); - ASSERT( out.m_SongTiming.m_BPMSegments[0].m_iStartRow == 0 ); + ASSERT( out.m_SongTiming.m_BPMSegments[0].GetRow() == 0 ); f.PutLine( ssprintf("#FILE:%s;", DwiEscape(out.m_sMusicFile).c_str()) ); f.PutLine( ssprintf("#BPM:%.3f;", out.m_SongTiming.m_BPMSegments[0].GetBPM()) ); f.PutLine( ssprintf("#GAP:%ld;", -lrintf( out.m_SongTiming.m_fBeat0OffsetInSeconds*1000 )) ); @@ -395,7 +395,7 @@ bool NotesWriterDWI::Write( RString sPath, const Song &out ) for( unsigned i=1; i &lines, TimingData timing, bool bIsSo w.Init( "BPMS" ); FOREACH_CONST( BPMSegment, timing.m_BPMSegments, bs ) - w.Write( bs->m_iStartRow, bs->GetBPM() ); + w.Write( bs->GetRow(), bs->GetBPM() ); w.Finish(); w.Init( "STOPS" ); diff --git a/src/ScreenSyncOverlay.cpp b/src/ScreenSyncOverlay.cpp index 5f5d8e37f4..3596c91e70 100644 --- a/src/ScreenSyncOverlay.cpp +++ b/src/ScreenSyncOverlay.cpp @@ -222,7 +222,7 @@ bool ScreenSyncOverlay::OverlayInput( const InputEventPlus &input ) if( GAMESTATE->m_pCurSong != NULL ) { BPMSegment& seg = GAMESTATE->m_pCurSong->m_SongTiming.GetBPMSegmentAtBeat( GAMESTATE->m_Position.m_fSongBeat ); - seg.m_fBPS += fDelta; + seg.SetBPS( seg.GetBPS() + fDelta ); } } break; diff --git a/src/TimingData.cpp b/src/TimingData.cpp index a7ae78db9b..19ae6a591f 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -86,25 +86,24 @@ void TimingData::AddFakeSegment( const FakeSegment &seg ) /* Change an existing BPM segment, merge identical segments together or insert a new one. */ void TimingData::SetBPMAtRow( int iNoteRow, float fBPM ) { - float fBPS = fBPM / 60.0f; unsigned i; for( i=0; i= iNoteRow ) + if( m_BPMSegments[i].GetRow() >= iNoteRow ) break; - if( i == m_BPMSegments.size() || m_BPMSegments[i].m_iStartRow != iNoteRow ) + if( i == m_BPMSegments.size() || m_BPMSegments[i].GetRow() != iNoteRow ) { // There is no BPMSegment at the specified beat. If the BPM being set differs // from the last BPMSegment's BPM, create a new BPMSegment. - if( i == 0 || fabsf(m_BPMSegments[i-1].m_fBPS - fBPS) > 1e-5f ) + if( i == 0 || fabsf(m_BPMSegments[i-1].GetBPM() - fBPM) > 1e-5f ) AddBPMSegment( BPMSegment(iNoteRow, fBPM) ); } else // BPMSegment being modified is m_BPMSegments[i] { - if( i > 0 && fabsf(m_BPMSegments[i-1].m_fBPS - fBPS) < 1e-5f ) + if( i > 0 && fabsf(m_BPMSegments[i-1].GetBPM() - fBPM) < 1e-5f ) m_BPMSegments.erase( m_BPMSegments.begin()+i, m_BPMSegments.begin()+i+1 ); else - m_BPMSegments[i].m_fBPS = fBPS; + m_BPMSegments[i].SetBPM(fBPM); } } @@ -456,9 +455,9 @@ void TimingData::MultiplyBPMInBeatRange( int iStartIndex, int iEndIndex, float f // Change all other BPM segments in this range. for( unsigned i=0; i iStartIndex ) { BPMSegment b = m_BPMSegments[i]; - b.m_iStartRow = iStartIndexNextSegment; + b.SetRow(iStartIndexNextSegment); m_BPMSegments.insert( m_BPMSegments.begin()+i+1, b ); /* Don't apply the BPM change to the first half of the segment we @@ -480,13 +479,13 @@ void TimingData::MultiplyBPMInBeatRange( int iStartIndex, int iEndIndex, float f if( iStartIndexThisSegment < iEndIndex && iStartIndexNextSegment > iEndIndex ) { BPMSegment b = m_BPMSegments[i]; - b.m_iStartRow = iEndIndex; + b.SetRow(iEndIndex); m_BPMSegments.insert( m_BPMSegments.begin()+i+1, b ); } else if( iStartIndexNextSegment > iEndIndex ) continue; - m_BPMSegments[i].m_fBPS = m_BPMSegments[i].m_fBPS * fFactor; + m_BPMSegments[i].SetBPM(m_BPMSegments[i].GetBPM() * fFactor); } } @@ -494,7 +493,7 @@ float TimingData::GetBPMAtRow( int iNoteRow ) const { unsigned i; for( i=0; i iNoteRow ) + if( m_BPMSegments[i+1].GetRow() > iNoteRow ) break; return m_BPMSegments[i].GetBPM(); } @@ -503,7 +502,7 @@ int TimingData::GetBPMSegmentIndexAtRow( int iNoteRow ) const { unsigned i; for( i=0; i iNoteRow ) + if( m_BPMSegments[i+1].GetRow() > iNoteRow ) break; return static_cast(i); } @@ -835,9 +834,9 @@ void TimingData::GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float iEventRow = BeatToNoteRow(fWarpDestination); iEventType = FOUND_WARP_DESTINATION; } - if( itBPMS != m_BPMSegments.end() && itBPMS->m_iStartRow < iEventRow ) + if( itBPMS != m_BPMSegments.end() && itBPMS->GetRow() < iEventRow ) { - iEventRow = itBPMS->m_iStartRow; + iEventRow = itBPMS->GetRow(); iEventType = FOUND_BPM_CHANGE; } if( itSS != m_StopSegments.end() && itSS->m_iStartRow < iEventRow ) @@ -867,7 +866,7 @@ void TimingData::GetBeatAndBPSFromElapsedTimeNoOffset( float fElapsedTime, float bIsWarping = false; break; case FOUND_BPM_CHANGE: - fBPS = itBPMS->m_fBPS; + fBPS = itBPMS->GetBPS(); itBPMS ++; break; case FOUND_STOP: @@ -937,9 +936,9 @@ float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const iEventRow = BeatToNoteRow(fWarpDestination); iEventType = FOUND_WARP_DESTINATION; } - if( itBPMS != m_BPMSegments.end() && itBPMS->m_iStartRow < iEventRow ) + if( itBPMS != m_BPMSegments.end() && itBPMS->GetRow() < iEventRow ) { - iEventRow = itBPMS->m_iStartRow; + iEventRow = itBPMS->GetRow(); iEventType = FOUND_BPM_CHANGE; } if( itSS != m_StopSegments.end() && itSS->m_bDelay && itSS->m_iStartRow < iEventRow ) // delays (come before marker) @@ -971,7 +970,7 @@ float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const bIsWarping = false; break; case FOUND_BPM_CHANGE: - fBPS = itBPMS->m_fBPS; + fBPS = itBPMS->GetBPS(); itBPMS ++; break; case FOUND_STOP: @@ -1020,13 +1019,13 @@ void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool for ( unsigned i = 0; i < m_BPMSegments.size(); i++ ) { - const int iSegStart = m_BPMSegments[i].m_iStartRow; + const int iSegStart = m_BPMSegments[i].GetRow(); if( iSegStart < iStartIndex ) continue; else if( iSegStart > iEndIndex ) - m_BPMSegments[i].m_iStartRow += lrintf( (iEndIndex - iStartIndex) * (fScale - 1) ); + m_BPMSegments[i].SetRow( m_BPMSegments[i].GetRow() + lrintf( (iEndIndex - iStartIndex) * (fScale - 1) ) ); else - m_BPMSegments[i].m_iStartRow = lrintf( (iSegStart - iStartIndex) * fScale ) + iStartIndex; + m_BPMSegments[i].SetRow( lrintf( (iSegStart - iStartIndex) * fScale ) + iStartIndex ); } for( unsigned i = 0; i < m_StopSegments.size(); i++ ) @@ -1161,13 +1160,13 @@ void TimingData::ScaleRegion( float fScale, int iStartIndex, int iEndIndex, bool // adjust BPM changes "between" iStartIndex and iNewEndIndex for ( unsigned i = 0; i < m_BPMSegments.size(); i++ ) { - const int iSegStart = m_BPMSegments[i].m_iStartRow; + const int iSegStart = m_BPMSegments[i].GetRow(); if( iSegStart <= iStartIndex ) continue; else if( iSegStart >= iNewEndIndex ) continue; else - m_BPMSegments[i].m_fBPS *= fScale; + m_BPMSegments[i].SetBPM( m_BPMSegments[i].GetBPM() * fScale ); } // set BPM at iStartIndex and iNewEndIndex. @@ -1183,9 +1182,9 @@ void TimingData::InsertRows( int iStartRow, int iRowsToAdd ) for( unsigned i = 0; i < m_BPMSegments.size(); i++ ) { BPMSegment &bpm = m_BPMSegments[i]; - if( bpm.m_iStartRow < iStartRow ) + if( bpm.GetRow() < iStartRow ) continue; - bpm.m_iStartRow += iRowsToAdd; + bpm.SetRow( bpm.GetRow() + iRowsToAdd ); } for( unsigned i = 0; i < m_StopSegments.size(); i++ ) @@ -1264,7 +1263,7 @@ void TimingData::InsertRows( int iStartRow, int iRowsToAdd ) /* 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 ); - m_BPMSegments[0].m_iStartRow = 0; + m_BPMSegments[0].SetRow(0); } } @@ -1281,11 +1280,11 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete ) BPMSegment &bpm = m_BPMSegments[i]; // Before deleted region: - if( bpm.m_iStartRow < iStartRow ) + if( bpm.GetRow() < iStartRow ) continue; // Inside deleted region: - if( bpm.m_iStartRow < iStartRow+iRowsToDelete ) + if( bpm.GetRow() < iStartRow+iRowsToDelete ) { m_BPMSegments.erase( m_BPMSegments.begin()+i, m_BPMSegments.begin()+i+1 ); --i; @@ -1293,7 +1292,7 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete ) } // After deleted region: - bpm.m_iStartRow -= iRowsToDelete; + bpm.SetRow( bpm.GetRow() - iRowsToDelete ); } for( unsigned i = 0; i < m_StopSegments.size(); i++ ) @@ -1520,8 +1519,8 @@ void TimingData::TidyUpData() } // Make sure the first BPM segment starts at beat 0. - if( m_BPMSegments[0].m_iStartRow != 0 ) - m_BPMSegments[0].m_iStartRow = 0; + if( m_BPMSegments[0].GetRow() != 0 ) + m_BPMSegments[0].SetRow(0); // If no time signature specified, assume 4/4 time for the whole song. if( m_vTimeSignatureSegments.empty() ) @@ -1707,7 +1706,7 @@ public: vector vBPMs; FOREACH_CONST( BPMSegment, p->m_BPMSegments, seg ) { - const float fStartRow = NoteRowToBeat(seg->m_iStartRow); + const float fStartRow = seg->GetBeat(); const float fBPM = seg->GetBPM(); vBPMs.push_back( ssprintf("%f=%f", fStartRow, fBPM) ); } diff --git a/src/TimingData.h b/src/TimingData.h index 2fab07ecca..8c66e205f8 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -9,92 +9,8 @@ struct lua_State; /** @brief Compare a TimingData segment's properties with one another. */ #define COMPARE(x) if(x!=other.x) return false; -/** - * @brief Identifies when a song changes its BPM. - */ -struct BPMSegment -{ - /** - * @brief Creates a simple BPM Segment with default values. - * - * It is best to override the values as soon as possible. - */ - BPMSegment() : m_iStartRow(-1), m_fBPS(-1.0f) { } - /** - * @brief Creates a BPM Segment with the specified starting row and beats per second. - * @param s the starting row of this segment. - * @param b the beats per second to be turned into beats per minute. - */ - BPMSegment( int s, float b ): m_iStartRow(max(0, s)), m_fBPS(0) { SetBPM( b ); } - /** - * @brief The row in which the BPMSegment activates. - */ - int m_iStartRow; - /** - * @brief The BPS to use when this row is reached. - */ - float m_fBPS; - - /** - * @brief Converts the BPS to a BPM. - * @param f The BPM. - */ - void SetBPM( float f ) { m_fBPS = f / 60.0f; } - /** - * @brief Retrieves the BPM from the BPS. - * @return the BPM. - */ - float GetBPM() const { return m_fBPS * 60.0f; } - /** - * @brief Compares two BPMSegments to see if they are equal to each other. - * @param other the other BPMSegment to compare to. - * @return the equality of the two segments. - */ - bool operator==( const BPMSegment &other ) const - { - COMPARE( m_iStartRow ); - COMPARE( m_fBPS ); - return true; - } - /** - * @brief Compares two BPMSegments to see if they are not equal to each other. - * @param other the other BPMSegment to compare to. - * @return the inequality of the two segments. - */ - bool operator!=( const BPMSegment &other ) const { return !operator==(other); } - /** - * @brief Compares two BPMSegments to see if one is less than the other. - * @param other the other BPMSegment to compare to. - * @return the truth/falsehood of if the first is less than the second. - */ - bool operator<( const BPMSegment &other ) const - { - return m_iStartRow < other.m_iStartRow || - ( m_iStartRow == other.m_iStartRow && m_fBPS < other.m_fBPS ); - } - /** - * @brief Compares two BPMSegments to see if one is less than or equal to the other. - * @param other the other BPMSegment to compare to. - * @return the truth/falsehood of if the first is less or equal to than the second. - */ - bool operator<=( const BPMSegment &other ) const - { - return ( operator<(other) || operator==(other) ); - } - /** - * @brief Compares two BPMSegments to see if one is greater than the other. - * @param other the other BPMSegment to compare to. - * @return the truth/falsehood of if the first is greater than the second. - */ - bool operator>( const BPMSegment &other ) const { return !operator<=(other); } - /** - * @brief Compares two BPMSegments to see if one is greater than or equal to the other. - * @param other the other BPMSegment to compare to. - * @return the truth/falsehood of if the first is greater than or equal to the second. - */ - bool operator>=( const BPMSegment &other ) const { return !operator<(other); } -}; + /** * @brief Identifies when a song has a stop or a delay. * diff --git a/src/TimingSegments.cpp b/src/TimingSegments.cpp index 73d5c1919d..dadb2efd9c 100644 --- a/src/TimingSegments.cpp +++ b/src/TimingSegments.cpp @@ -53,6 +53,9 @@ bool FakeSegment::operator<( const FakeSegment &other ) const return false; } + + + float WarpSegment::GetLength() const { return this->lengthBeats; @@ -72,6 +75,7 @@ bool WarpSegment::operator<( const WarpSegment &other ) const + int TickcountSegment::GetTicks() const { return this->ticks; @@ -89,6 +93,9 @@ bool TickcountSegment::operator<( const TickcountSegment &other ) const return false; } + + + int ComboSegment::GetCombo() const { return this->combo; @@ -106,6 +113,9 @@ bool ComboSegment::operator<( const ComboSegment &other ) const return false; } + + + RString LabelSegment::GetLabel() const { return this->label; @@ -123,6 +133,38 @@ bool LabelSegment::operator<( const LabelSegment &other ) const return false; } + + +float BPMSegment::GetBPM() const +{ + return this->bps * 60.0f; +} + +void BPMSegment::SetBPM(const float bpm) +{ + this->bps = bpm / 60.0f; +} + +float BPMSegment::GetBPS() const +{ + return this->bps; +} + +void BPMSegment::SetBPS(const float newBPS) +{ + this->bps = newBPS; +} + +bool BPMSegment::operator<( const BPMSegment &other ) const +{ + LTCOMPARE(GetRow()); + LTCOMPARE(GetBPM()); + return false; +} + + + + /** * @file * @author Jason Felds (c) 2011 diff --git a/src/TimingSegments.h b/src/TimingSegments.h index f9f2b37add..f901973458 100644 --- a/src/TimingSegments.h +++ b/src/TimingSegments.h @@ -383,6 +383,64 @@ private: +/** + * @brief Identifies when a song changes its BPM. + */ +struct BPMSegment : public TimingSegment +{ + /** + * @brief Creates a simple BPM Segment with default values. + * + * It is best to override the values as soon as possible. + */ + BPMSegment() : + TimingSegment(), bps(-1.0f) { } + + /** + * @brief Creates a BPM Segment with the specified starting row and beats per second. + * @param s the starting row / beat of this segment. + * @param b the beats per minute to be turned into beats per second. + */ + template + BPMSegment( StartType s, float bpm ): + TimingSegment(max((StartType)0, s)), bps(0.0f) { SetBPM(bpm); } + + /** + * @brief Get the label in this LabelSegment. + * @return the label. */ + float GetBPM() const; + + /** + * @brief Set the label in this LabelSegment. + * @param l the label. */ + void SetBPM(const float bpm); + + /** + * @brief Get the label in this LabelSegment. + * @return the label. */ + float GetBPS() const; + + /** + * @brief Set the label in this LabelSegment. + * @param l the label. */ + void SetBPS(const float newBPS); + + /** + * @brief Compares two LabelSegments to see if one is less than the other. + * @param other the other LabelSegment to compare to. + * @return the truth/falsehood of if the first is less than the second. + */ + bool operator<( const BPMSegment &other ) const; + +private: + /** + * @brief The label/section name for this point. + */ + float bps; +}; + + + #undef COMPARE