diff --git a/src/NotesLoaderBMS.cpp b/src/NotesLoaderBMS.cpp index c6bab7c292..b8edfde57e 100644 --- a/src/NotesLoaderBMS.cpp +++ b/src/NotesLoaderBMS.cpp @@ -573,8 +573,8 @@ static bool LoadFromBMSFile( const RString &sPath, const NameToData_t &mapNameTo if( fBPM > 0.0f ) { - BPMSegment newSeg( 0, fBPM ); - out.m_Timing.AddBPMSegment( newSeg ); + BPMSegment * newSeg = new BPMSegment( 0, fBPM ); + out.m_Timing.AddSegment(SEGMENT_BPM, newSeg ); LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", NoteRowToBeat(0), fBPM ); } else @@ -663,9 +663,9 @@ static bool LoadFromBMSFile( const RString &sPath, const NameToData_t &mapNameTo float fBeats = StringToFloat( sBeats ) / 48.0f; float fFreezeSecs = fBeats / fBPS; - StopSegment newSeg( BeatToNoteRow(fBeat), fFreezeSecs ); - out.m_Timing.AddStopSegment( newSeg ); - LOG->Trace( "Inserting new Freeze at beat %f, secs %f", fBeat, newSeg.GetPause() ); + StopSegment * newSeg = new StopSegment( fBeat, fFreezeSecs ); + out.m_Timing.AddSegment( SEGMENT_STOP_DELAY, newSeg ); + LOG->Trace( "Inserting new Freeze at beat %f, secs %f", fBeat, newSeg->GetPause() ); } else { diff --git a/src/NotesLoaderDWI.cpp b/src/NotesLoaderDWI.cpp index e7483e6fb6..9d1f2fc9b6 100644 --- a/src/NotesLoaderDWI.cpp +++ b/src/NotesLoaderDWI.cpp @@ -515,14 +515,16 @@ bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set &Bla if( PREFSMAN->m_bQuirksMode ) { - out.m_SongTiming.AddBPMSegment( BPMSegment(0, fBPM) ); + out.m_SongTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, fBPM) ); } else{ if( fBPM > 0.0f ) - out.m_SongTiming.AddBPMSegment( BPMSegment(0, fBPM) ); + out.m_SongTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, fBPM) ); else - LOG->UserLog( "Song file", sPath, "has an invalid BPM change at beat %f, BPM %f.", - NoteRowToBeat(0), fBPM ); + LOG->UserLog("Song file", + sPath, + "has an invalid BPM change at beat %f, BPM %f.", + 0.0f, fBPM ); } } else if( sValueName.EqualsNoCase("DISPLAYBPM") ) @@ -576,7 +578,7 @@ bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set &Bla int iFreezeRow = BeatToNoteRow( StringToFloat(arrayFreezeValues[0]) / 4.0f ); float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ) / 1000.0f; - out.m_SongTiming.AddStopSegment( StopSegment(iFreezeRow, fFreezeSeconds) ); + out.m_SongTiming.AddSegment( SEGMENT_STOP_DELAY, new StopSegment(iFreezeRow, fFreezeSeconds) ); // LOG->Trace( "Adding a freeze segment: beat: %f, seconds = %f", fFreezeBeat, fFreezeSeconds ); } } @@ -600,8 +602,8 @@ bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set &Bla float fBPM = StringToFloat( arrayBPMChangeValues[1] ); if( fBPM > 0.0f ) { - BPMSegment bs( iStartIndex, fBPM ); - out.m_SongTiming.AddBPMSegment( bs ); + BPMSegment * bs = new BPMSegment( iStartIndex, fBPM ); + out.m_SongTiming.AddSegment( SEGMENT_BPM, bs ); } else { diff --git a/src/NotesLoaderKSF.cpp b/src/NotesLoaderKSF.cpp index 133096ce5d..0e078bb7ad 100644 --- a/src/NotesLoaderKSF.cpp +++ b/src/NotesLoaderKSF.cpp @@ -17,7 +17,7 @@ static void HandleBunki( TimingData &timing, const float fEarlyBPM, const float beat = (fPos + fGap) * BeatsPerSecond; LOG->Trace( "BPM %f, BPS %f, BPMPos %f, beat %f", fEarlyBPM, BeatsPerSecond, fPos, beat ); - timing.AddBPMSegment( BPMSegment(BeatToNoteRow(beat), fCurBPM) ); + timing.AddSegment( SEGMENT_BPM, new BPMSegment(beat, fCurBPM) ); } static bool LoadFromKSFFile( const RString &sPath, Steps &out, const Song &song, bool bKIUCompliant ) @@ -60,7 +60,7 @@ static bool LoadFromKSFFile( const RString &sPath, Steps &out, const Song &song, else if( sValueName=="BPM" ) { BPM1 = StringToFloat(sParams[1]); - stepsTiming.AddBPMSegment( BPMSegment(0, BPM1) ); + stepsTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, BPM1) ); } else if( sValueName=="BPM2" ) { @@ -137,7 +137,7 @@ static bool LoadFromKSFFile( const RString &sPath, Steps &out, const Song &song, LOG->UserLog( "Song file", sPath, "has an invalid tick count: %d.", iTickCount ); return false; } - stepsTiming.AddTickcountSegment(TickcountSegment(0, iTickCount)); + stepsTiming.AddSegment( SEGMENT_TICKCOUNT, new TickcountSegment(0, iTickCount)); } else if( sValueName=="DIFFICULTY" ) @@ -554,7 +554,7 @@ static bool LoadGlobalData( const RString &sPath, Song &out, bool bKIUCompliant else if( sValueName=="BPM" ) { BPM1 = StringToFloat(sParams[1]); - out.m_SongTiming.AddBPMSegment( BPMSegment(0, BPM1) ); + out.m_SongTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, BPM1) ); } else if( sValueName=="BPM2" ) { @@ -602,9 +602,9 @@ static bool LoadGlobalData( const RString &sPath, Song &out, bool bKIUCompliant // add a tickcount for those using the [Player] // CheckpointsUseTimeSignatures metric. -aj // It's not with timesigs now -DaisuMaster - TickcountSegment tcs(0); - tcs.SetTicks(iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount); - out.m_SongTiming.AddTickcountSegment( tcs ); + TickcountSegment * tcs = new TickcountSegment(0); + tcs->SetTicks(iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount); + out.m_SongTiming.AddSegment( SEGMENT_TICKCOUNT, tcs ); } else if ( sValueName=="STEP" ) { diff --git a/src/NotesLoaderMidi.cpp b/src/NotesLoaderMidi.cpp index 8a3377b527..d34e5434a6 100644 --- a/src/NotesLoaderMidi.cpp +++ b/src/NotesLoaderMidi.cpp @@ -677,21 +677,22 @@ static bool LoadFromMidi( const RString &sPath, Song &songOut ) FOREACH_CONST( MidiFileIn::TempoChange, midi.tempoEvents_, iter ) { - BPMSegment bpmSeg; - bpmSeg.SetRow( MidiCountToNoteRow( iter->count ) ); + BPMSegment * bpmSeg; + bpmSeg->SetRow( MidiCountToNoteRow( iter->count ) ); double fSecondsPerBeat = (iter->tickSeconds * GUITAR_MIDI_COUNTS_PER_BEAT); - bpmSeg.SetBPS( float( 1. / fSecondsPerBeat ) ); + bpmSeg->SetBPS( float( 1. / fSecondsPerBeat ) ); - songOut.m_SongTiming.AddBPMSegment( bpmSeg ); + songOut.m_SongTiming.AddSegment( SEGMENT_BPM, bpmSeg ); } FOREACH_CONST( MidiFileIn::TimeSignatureChange, midi.timeSignatureEvents_, iter ) { - TimeSignatureSegment seg(MidiCountToNoteRow( iter->count ), - iter->numerator, - iter->denominator); + TimeSignatureSegment * seg = + new TimeSignatureSegment(MidiCountToNoteRow( iter->count ), + iter->numerator, + iter->denominator); - songOut.m_SongTiming.AddTimeSignatureSegment( seg ); + songOut.m_SongTiming.AddSegment( SEGMENT_TIME_SIG, seg ); } diff --git a/src/TimingData.cpp b/src/TimingData.cpp index 6bc31eca46..1988a0c677 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -28,56 +28,11 @@ void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut, float highe } } - -void TimingData::AddBPMSegment( const BPMSegment &seg ) +void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg) { - const vector &segs = this->allTimingSegments[SEGMENT_BPM]; - segs.insert( upper_bound(segs.begin(), segs.end(), seg), seg ); -} - -void TimingData::AddStopSegment( const StopSegment &seg ) -{ - m_StopSegments.insert( upper_bound(m_StopSegments.begin(), m_StopSegments.end(), seg), seg ); -} - -void TimingData::AddTimeSignatureSegment( const TimeSignatureSegment &seg ) -{ - m_vTimeSignatureSegments.insert( upper_bound(m_vTimeSignatureSegments.begin(), m_vTimeSignatureSegments.end(), seg), seg ); -} - -void TimingData::AddWarpSegment( const WarpSegment &seg ) -{ - m_WarpSegments.insert( upper_bound(m_WarpSegments.begin(), m_WarpSegments.end(), seg), seg ); -} - -void TimingData::AddTickcountSegment( const TickcountSegment &seg ) -{ - m_TickcountSegments.insert( upper_bound(m_TickcountSegments.begin(), m_TickcountSegments.end(), seg), seg ); -} - -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 ); -} - -void TimingData::AddSpeedSegment( const SpeedSegment &seg ) -{ - m_SpeedSegments.insert( upper_bound(m_SpeedSegments.begin(), m_SpeedSegments.end(), seg), seg ); -} - -void TimingData::AddScrollSegment( const ScrollSegment &seg ) -{ - m_ScrollSegments.insert( upper_bound(m_ScrollSegments.begin(), m_ScrollSegments.end(), seg), seg ); -} - -void TimingData::AddFakeSegment( const FakeSegment &seg ) -{ - m_FakeSegments.insert( upper_bound(m_FakeSegments.begin(), m_FakeSegments.end(), seg), seg ); + vector &segs = this->allTimingSegments[tst]; + // Unsure if this uses the proper comparison. + segs.insert(upper_bound(segs.begin(), segs.end(), seg), seg); } /* Change an existing BPM segment, merge identical segments together or insert a new one. */ diff --git a/src/TimingData.h b/src/TimingData.h index 27a3946ef4..8eb08cacc3 100644 --- a/src/TimingData.h +++ b/src/TimingData.h @@ -16,6 +16,8 @@ struct lua_State; class TimingData { public: + void AddSegment(TimingSegmentType tst, TimingSegment * seg); + /** * @brief Sets up initial timing data with a defined offset. * @param fOffset the offset from the 0th beat. */ @@ -78,12 +80,7 @@ public: * @return the BPMSegment's index in question. */ int GetBPMSegmentIndexAtBeat( float fBeat ) const { return GetBPMSegmentIndexAtRow( BeatToNoteRow(fBeat)); } - /** - * @brief Add the BPMSegment to the TimingData. - * @param seg the new BPMSegment. - */ - void AddBPMSegment( const BPMSegment &seg ); - + /** * @brief Retrieve the next beat that contains a BPMSegment. * @param iRow the present row. @@ -276,11 +273,6 @@ public: * @return the StopSegment's index in question. */ int GetDelaySegmentIndexAtBeat( float fBeat ) const { return GetStopSegmentIndexAtRow( BeatToNoteRow(fBeat), true ); } - /** - * @brief Add the StopSegment to the TimingData. - * @param seg the new StopSegment. - */ - void AddStopSegment( const StopSegment &seg ); /** * @brief Retrieve the next beat that contains a StopSegment. @@ -430,16 +422,7 @@ public: * @return the TimeSignatureSegment's index in question. */ int GetTimeSignatureSegmentIndexAtBeat( float fBeat ) const { return GetTimeSignatureSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } - /** - * @brief Add the TimeSignatureSegment to the TimingData. - * @param seg the new TimeSignatureSegment. - */ - void AddTimeSignatureSegment( const TimeSignatureSegment &seg ); - /** - * @brief Determine the beat to warp to. - * @param iRow The row you start on. - * @return the beat you warp to. - */ + /** * @brief Retrieve the next beat that contains a TimeSignatureSegment. @@ -472,7 +455,11 @@ public: return this->GetPreviousTimeSignatureSegmentBeatAtRow( BeatToNoteRow(fBeat) ); } - + /** + * @brief Determine the beat to warp to. + * @param iRow The row you start on. + * @return the beat you warp to. + */ float GetWarpAtRow( int iRow ) const; /** * @brief Determine the beat to warp to. @@ -528,11 +515,6 @@ public: * @return true if the row is inside a warp, false otherwise. */ bool IsWarpAtBeat( float fBeat ) const { return IsWarpAtRow( BeatToNoteRow( fBeat ) ); } - /** - * @brief Add the WarpSegment to the TimingData. - * @param seg the new WarpSegment. - */ - void AddWarpSegment( const WarpSegment &seg ); /** @@ -614,11 +596,6 @@ public: * @return the TickcountSegment's index in question. */ int GetTickcountSegmentIndexAtBeat( float fBeat ) const { return GetTickcountSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } - /** - * @brief Add the TickcountSegment to the TimingData. - * @param seg the new TickcountSegment. - */ - void AddTickcountSegment( const TickcountSegment &seg ); /** * @brief Retrieve the next beat that contains a TickcountSegment. @@ -750,11 +727,6 @@ public: * @return the ComboSegment's index in question. */ int GetComboSegmentIndexAtBeat( float fBeat ) const { return GetComboSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } - /** - * @brief Add the ComboSegment to the TimingData. - * @param seg the new ComboSegment. - */ - void AddComboSegment( const ComboSegment &seg ); /** * @brief Retrieve the next beat that contains a ComboSegment. @@ -836,11 +808,6 @@ public: * @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 ); /** * @brief Retrieve the previous beat that contains a LabelSegment. @@ -993,11 +960,6 @@ public: * @return the SpeedSegment's index in question. */ int GetSpeedSegmentIndexAtBeat( float fBeat ) const { return GetSpeedSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } - /** - * @brief Add the SpeedSegment to the TimingData. - * @param seg the new SpeedSegment. - */ - void AddSpeedSegment( const SpeedSegment &seg ); float GetDisplayedSpeedPercent( float fBeat, float fMusicSeconds ) const; @@ -1085,12 +1047,6 @@ public: */ int GetScrollSegmentIndexAtBeat( float fBeat ) const { return GetScrollSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } - /** - * @brief Add the ScrollSegment to the TimingData. - * @param seg the new ScrollSegment. - */ - void AddScrollSegment( const ScrollSegment &seg ); - /** * @brief Retrieve the next beat that contains a ScrollSegment. * @param iRow the present row. @@ -1183,11 +1139,6 @@ public: * @return true if the row is inside a fake, false otherwise. */ bool IsFakeAtBeat( float fBeat ) const { return IsFakeAtRow( BeatToNoteRow( fBeat ) ); } - /** - * @brief Add the FakeSegment to the TimingData. - * @param seg the new FakeSegment. - */ - void AddFakeSegment( const FakeSegment &seg ); /** * @brief Retrieve the next beat that contains a FakeSegment.