From 315aaf774dfe1a9461561e0503d1f47da43c5ff9 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Mon, 4 Apr 2011 22:47:59 -0400 Subject: [PATCH] New branch from [sm130futures]: [sm130labels] Time to simulate the Rock Band/Guitar Hero styled labeling of note sections. --- src/TimingData.cpp | 5 ++ src/TimingData.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/src/TimingData.cpp b/src/TimingData.cpp index 0fa5d50889..a5b632e92b 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -57,6 +57,11 @@ void TimingData::AddComboSegment( const ComboSegment &seg ) m_ComboSegments.insert( upper_bound(m_ComboSegments.begin(), m_ComboSegments.end(), seg), seg ); } +void TimingData::AddLabelSegment( const LabelSegment &seg ) +{ + m_LabelSegments.insert( upper_bound(m_LabelSegments.begin(), m_LabelSegments.end(), seg), seg ); +} + /* Change an existing BPM segment, merge identical segments together or insert a new one. */ void TimingData::SetBPMAtRow( int iNoteRow, float fBPM ) { diff --git a/src/TimingData.h b/src/TimingData.h index f61afb6d9c..4b49e93825 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -564,6 +564,83 @@ struct ComboSegment bool operator>=( const ComboSegment &other ) const { return !operator<(other); } }; +/** + * @brief Identifies when a chart is entering a different section. + * + * This is meant for helping to identify different sections of a chart + * versus relying on measures and beats alone. + */ +struct LabelSegment +{ + /** + * @brief Creates a simple Label Segment with default values. + * + * It is best to override the values as soon as possible. + */ + LabelSegment() : m_iStartRow(-1), m_sLabel("") { } + /** + * @brief Creates a Label Segment with the specified starting row and label. + * @param s the starting row of this segment. + * @param l the label for this section. + */ + LabelSegment( int s, RString l ): m_iStartRow(max(0, s)), + m_sLabel(l) {} + /** + * @brief The row in which the ComboSegment activates. + */ + int m_iStartRow; + /** + * @brief The label/section name for this point. + */ + RString m_sLabel; + + /** + * @brief Compares two LabelSegments to see if they are equal to each other. + * @param other the other LabelSegment to compare to. + * @return the equality of the two segments. + */ + bool operator==( const LabelSegment &other ) const + { + COMPARE( m_iStartRow ); + COMPARE( m_sLabel ); + return true; + } + /** + * @brief Compares two LabelSegments to see if they are not equal to each other. + * @param other the other LabelSegment to compare to. + * @return the inequality of the two segments. + */ + bool operator!=( const LabelSegment &other ) const { return !operator==(other); } + /** + * @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 LabelSegment &other ) const { return m_iStartRow < other.m_iStartRow; } + /** + * @brief Compares two LabelSegments to see if one is less than or equal to the other. + * @param other the other LabelSegment to compare to. + * @return the truth/falsehood of if the first is less or equal to than the second. + */ + bool operator<=( const LabelSegment &other ) const + { + return ( operator<(other) || operator==(other) ); + } + /** + * @brief Compares two LabelSegments to see if one is greater than the other. + * @param other the other LabelSegment to compare to. + * @return the truth/falsehood of if the first is greater than the second. + */ + bool operator>( const LabelSegment &other ) const { return !operator<=(other); } + /** + * @brief Compares two LabelSegments to see if one is greater than or equal to the other. + * @param other the other LabelSegment to compare to. + * @return the truth/falsehood of if the first is greater than or equal to the second. + */ + bool operator>=( const LabelSegment &other ) const { return !operator<(other); } +}; + + /** * @brief Holds data for translating beats<->seconds. */ @@ -1064,6 +1141,60 @@ public: */ void AddComboSegment( const ComboSegment &seg ); + /** + * @brief Retrieve the Label at the given row. + * @param iNoteRow the row in question. + * @return the Label. + */ + RString GetLabelAtRow( int iNoteRow ) const; + /** + * @brief Retrieve the Label at the given beat. + * @param fBeat the beat in question. + * @return the Label. + */ + RString GetLabelAtBeat( float fBeat ) const { return GetLabelAtRow( BeatToNoteRow(fBeat) ); } + /** + * @brief Set the row to have the new Label. + * @param iNoteRow the row to have the new Label. + * @param sLabel the Label. + */ + void SetLabelAtRow( int iNoteRow, RString sLabel ); + /** + * @brief Set the beat to have the new Label. + * @param fBeat the beat to have the new Label. + * @param sLabel the Label. + */ + void SetLabelAtBeat( float fBeat, RString sLabel ) { SetLabelAtRow( BeatToNoteRow( fBeat ), sLabel ); } + /** + * @brief Retrieve the LabelSegment at the specified row. + * @param iNoteRow the row that has a LabelSegment. + * @return the LabelSegment in question. + */ + LabelSegment& GetLabelSegmentAtRow( int iNoteRow ); + /** + * @brief Retrieve the LabelSegment at the specified beat. + * @param fBeat the beat that has a LabelSegment. + * @return the LabelSegment in question. + */ + LabelSegment& GetLabelSegmentAtBeat( float fBeat ) { return GetLabelSegmentAtRow( BeatToNoteRow(fBeat) ); } + /** + * @brief Retrieve the index of the LabelSegments at the specified row. + * @param iNoteRow the row that has a LabelSegment. + * @return the LabelSegment's index in question. + */ + int GetLabelSegmentIndexAtRow( int iNoteRow ) const; + /** + * @brief Retrieve the index of the LabelSegments at the specified beat. + * @param fBeat the beat that has a LabelSegment. + * @return the LabelSegment's index in question. + */ + int GetLabelSegmentIndexAtBeat( float fBeat ) const { return GetLabelSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } + /** + * @brief Add the LabelSegment to the TimingData. + * @param seg the new LabelSegment. + */ + void AddLabelSegment( const LabelSegment &seg ); + void MultiplyBPMInBeatRange( int iStartIndex, int iEndIndex, float fFactor ); void NoteRowToMeasureAndBeat( int iNoteRow, int &iMeasureIndexOut, int &iBeatIndexOut, int &iRowsRemainder ) const; @@ -1131,6 +1262,8 @@ public: COMPARE( m_ComboSegments.size() ); for( unsigned i=0; i m_ComboSegments; + /** + * @brief The collection of LabelSegments. + */ + vector m_LabelSegments; /** * @brief The initial offset of a song. */