From 53971e16e38f0151f4f91634ccd6a54d5663d6a8 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Mon, 4 Apr 2011 23:03:10 -0400 Subject: [PATCH] [sm130labels] Add the other definitions. --- src/TimingData.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++ src/TimingData.h | 4 +-- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/TimingData.cpp b/src/TimingData.cpp index a5b632e92b..b1f36960fa 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -224,6 +224,27 @@ void TimingData::SetComboAtRow( int iRow, int iCombo ) } } +void TimingData::SetLabelAtRow( int iRow, const RString sLabel ) +{ + unsigned i; + for( i=0; i= iRow ) + break; + + if( i == m_LabelSegments.size() || m_LabelSegments[i].m_iStartRow != iRow ) + { + if( i == 0 || m_LabelSegments[i-1].m_sLabel != sLabel ) + AddLabelSegment( LabelSegment(iRow, sLabel ) ); + } + else + { + if( i > 0 && m_LabelSegments[i-1].m_sLabel == sLabel ) + m_LabelSegments.erase( m_LabelSegments.begin()+i, m_LabelSegments.begin()+i+1 ); + else + m_LabelSegments[i].m_sLabel = sLabel; + } +} + float TimingData::GetStopAtRow( int iNoteRow, bool bDelay ) const { for( unsigned i=0; i(i); } +int TimingData::GetLabelSegmentIndexAtRow( int iRow ) const +{ + unsigned i; + for( i=0; i iRow ) + break; + } + return static_cast(i); +} + BPMSegment& TimingData::GetBPMSegmentAtRow( int iNoteRow ) { static BPMSegment empty; @@ -427,6 +465,15 @@ ComboSegment& TimingData::GetComboSegmentAtRow( int iRow ) return m_ComboSegments[i]; } +LabelSegment& TimingData::GetLabelSegmentAtRow( int iRow ) +{ + unsigned i; + for( i=0; i iRow ) + break; + return m_LabelSegments[i]; +} + StopSegment& TimingData::GetStopSegmentAtRow( int iNoteRow, bool bDelay ) { static StopSegment empty; @@ -803,6 +850,13 @@ void TimingData::InsertRows( int iStartRow, int iRowsToAdd ) continue; comb.m_iStartRow += iRowsToAdd; } + for( unsigned i = 0; i < m_LabelSegments.size(); i++ ) + { + LabelSegment &labl = m_LabelSegments[i]; + if( labl.m_iStartRow < iStartRow ) + continue; + labl.m_iStartRow += iRowsToAdd; + } if( iStartRow == 0 ) { @@ -944,6 +998,22 @@ void TimingData::DeleteRows( int iStartRow, int iRowsToDelete ) // After deleted region: comb.m_iStartRow -= iRowsToDelete; } + + for( unsigned i = 0; i < m_LabelSegments.size(); i++ ) + { + LabelSegment &labl = m_LabelSegments[i]; + + if( labl.m_iStartRow < iStartRow ) + continue; + + if( labl.m_iStartRow < iStartRow+iRowsToDelete ) + { + m_LabelSegments.erase( m_LabelSegments.begin()+i, m_LabelSegments.begin()+i+1 ); + --i; + continue; + } + labl.m_iStartRow -= iRowsToDelete; + } this->SetBPMAtRow( iStartRow, fNewBPM ); } @@ -1049,6 +1119,18 @@ public: LuaHelpers::CreateTableFromArray(vBPMs, L); return 1; } + static int GetLabels( T* p, lua_State *L ) + { + vector vLabels; + FOREACH_CONST( LabelSegment, p->m_LabelSegments, seg ) + { + const float fStartRow = NoteRowToBeat(seg->m_iStartRow); + const RString sLabel = seg->m_sLabel; + vLabels.push_back( ssprintf("%f=%s", fStartRow, sLabel.c_str()) ); + } + LuaHelpers::CreateTableFromArray(vLabels, L); + return 1; + } static int GetBPMsAndTimes( T* p, lua_State *L ) { vector vBPMs; @@ -1087,6 +1169,7 @@ public: ADD_METHOD( GetStops ); ADD_METHOD( GetDelays ); ADD_METHOD( GetBPMs ); + ADD_METHOD( GetLabels ); ADD_METHOD( GetBPMsAndTimes ); ADD_METHOD( GetActualBPM ); ADD_METHOD( HasNegativeBPMs ); diff --git a/src/TimingData.h b/src/TimingData.h index 4b49e93825..c8f7c9dce4 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -1158,13 +1158,13 @@ public: * @param iNoteRow the row to have the new Label. * @param sLabel the Label. */ - void SetLabelAtRow( int iNoteRow, RString sLabel ); + void SetLabelAtRow( int iNoteRow, const 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 ); } + void SetLabelAtBeat( float fBeat, const RString sLabel ) { SetLabelAtRow( BeatToNoteRow( fBeat ), sLabel ); } /** * @brief Retrieve the LabelSegment at the specified row. * @param iNoteRow the row that has a LabelSegment.