Get inserts working via passing TimingSegments.

Unsure if this is the right way:
code review may be needed.
This commit is contained in:
Jason Felds
2011-07-14 19:01:12 -04:00
parent 312498be94
commit 199af25f31
6 changed files with 43 additions and 134 deletions
+5 -5
View File
@@ -573,8 +573,8 @@ static bool LoadFromBMSFile( const RString &sPath, const NameToData_t &mapNameTo
if( fBPM > 0.0f ) if( fBPM > 0.0f )
{ {
BPMSegment newSeg( 0, fBPM ); BPMSegment * newSeg = new BPMSegment( 0, fBPM );
out.m_Timing.AddBPMSegment( newSeg ); out.m_Timing.AddSegment(SEGMENT_BPM, newSeg );
LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", NoteRowToBeat(0), fBPM ); LOG->Trace( "Inserting new BPM change at beat %f, BPM %f", NoteRowToBeat(0), fBPM );
} }
else else
@@ -663,9 +663,9 @@ static bool LoadFromBMSFile( const RString &sPath, const NameToData_t &mapNameTo
float fBeats = StringToFloat( sBeats ) / 48.0f; float fBeats = StringToFloat( sBeats ) / 48.0f;
float fFreezeSecs = fBeats / fBPS; float fFreezeSecs = fBeats / fBPS;
StopSegment newSeg( BeatToNoteRow(fBeat), fFreezeSecs ); StopSegment * newSeg = new StopSegment( fBeat, fFreezeSecs );
out.m_Timing.AddStopSegment( newSeg ); out.m_Timing.AddSegment( SEGMENT_STOP_DELAY, newSeg );
LOG->Trace( "Inserting new Freeze at beat %f, secs %f", fBeat, newSeg.GetPause() ); LOG->Trace( "Inserting new Freeze at beat %f, secs %f", fBeat, newSeg->GetPause() );
} }
else else
{ {
+9 -7
View File
@@ -515,14 +515,16 @@ bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set<RString> &Bla
if( PREFSMAN->m_bQuirksMode ) if( PREFSMAN->m_bQuirksMode )
{ {
out.m_SongTiming.AddBPMSegment( BPMSegment(0, fBPM) ); out.m_SongTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, fBPM) );
} }
else{ else{
if( fBPM > 0.0f ) if( fBPM > 0.0f )
out.m_SongTiming.AddBPMSegment( BPMSegment(0, fBPM) ); out.m_SongTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, fBPM) );
else else
LOG->UserLog( "Song file", sPath, "has an invalid BPM change at beat %f, BPM %f.", LOG->UserLog("Song file",
NoteRowToBeat(0), fBPM ); sPath,
"has an invalid BPM change at beat %f, BPM %f.",
0.0f, fBPM );
} }
} }
else if( sValueName.EqualsNoCase("DISPLAYBPM") ) else if( sValueName.EqualsNoCase("DISPLAYBPM") )
@@ -576,7 +578,7 @@ bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set<RString> &Bla
int iFreezeRow = BeatToNoteRow( StringToFloat(arrayFreezeValues[0]) / 4.0f ); int iFreezeRow = BeatToNoteRow( StringToFloat(arrayFreezeValues[0]) / 4.0f );
float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ) / 1000.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 ); // 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<RString> &Bla
float fBPM = StringToFloat( arrayBPMChangeValues[1] ); float fBPM = StringToFloat( arrayBPMChangeValues[1] );
if( fBPM > 0.0f ) if( fBPM > 0.0f )
{ {
BPMSegment bs( iStartIndex, fBPM ); BPMSegment * bs = new BPMSegment( iStartIndex, fBPM );
out.m_SongTiming.AddBPMSegment( bs ); out.m_SongTiming.AddSegment( SEGMENT_BPM, bs );
} }
else else
{ {
+7 -7
View File
@@ -17,7 +17,7 @@ static void HandleBunki( TimingData &timing, const float fEarlyBPM,
const float beat = (fPos + fGap) * BeatsPerSecond; const float beat = (fPos + fGap) * BeatsPerSecond;
LOG->Trace( "BPM %f, BPS %f, BPMPos %f, beat %f", LOG->Trace( "BPM %f, BPS %f, BPMPos %f, beat %f",
fEarlyBPM, BeatsPerSecond, fPos, beat ); 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 ) 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" ) else if( sValueName=="BPM" )
{ {
BPM1 = StringToFloat(sParams[1]); BPM1 = StringToFloat(sParams[1]);
stepsTiming.AddBPMSegment( BPMSegment(0, BPM1) ); stepsTiming.AddSegment( SEGMENT_BPM, new BPMSegment(0, BPM1) );
} }
else if( sValueName=="BPM2" ) 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 ); LOG->UserLog( "Song file", sPath, "has an invalid tick count: %d.", iTickCount );
return false; return false;
} }
stepsTiming.AddTickcountSegment(TickcountSegment(0, iTickCount)); stepsTiming.AddSegment( SEGMENT_TICKCOUNT, new TickcountSegment(0, iTickCount));
} }
else if( sValueName=="DIFFICULTY" ) else if( sValueName=="DIFFICULTY" )
@@ -554,7 +554,7 @@ static bool LoadGlobalData( const RString &sPath, Song &out, bool bKIUCompliant
else if( sValueName=="BPM" ) else if( sValueName=="BPM" )
{ {
BPM1 = StringToFloat(sParams[1]); 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" ) 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] // add a tickcount for those using the [Player]
// CheckpointsUseTimeSignatures metric. -aj // CheckpointsUseTimeSignatures metric. -aj
// It's not with timesigs now -DaisuMaster // It's not with timesigs now -DaisuMaster
TickcountSegment tcs(0); TickcountSegment * tcs = new TickcountSegment(0);
tcs.SetTicks(iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount); tcs->SetTicks(iTickCount > ROWS_PER_BEAT ? ROWS_PER_BEAT : iTickCount);
out.m_SongTiming.AddTickcountSegment( tcs ); out.m_SongTiming.AddSegment( SEGMENT_TICKCOUNT, tcs );
} }
else if ( sValueName=="STEP" ) else if ( sValueName=="STEP" )
{ {
+7 -6
View File
@@ -677,21 +677,22 @@ static bool LoadFromMidi( const RString &sPath, Song &songOut )
FOREACH_CONST( MidiFileIn::TempoChange, midi.tempoEvents_, iter ) FOREACH_CONST( MidiFileIn::TempoChange, midi.tempoEvents_, iter )
{ {
BPMSegment bpmSeg; BPMSegment * bpmSeg;
bpmSeg.SetRow( MidiCountToNoteRow( iter->count ) ); bpmSeg->SetRow( MidiCountToNoteRow( iter->count ) );
double fSecondsPerBeat = (iter->tickSeconds * GUITAR_MIDI_COUNTS_PER_BEAT); 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 ) FOREACH_CONST( MidiFileIn::TimeSignatureChange, midi.timeSignatureEvents_, iter )
{ {
TimeSignatureSegment seg(MidiCountToNoteRow( iter->count ), TimeSignatureSegment * seg =
new TimeSignatureSegment(MidiCountToNoteRow( iter->count ),
iter->numerator, iter->numerator,
iter->denominator); iter->denominator);
songOut.m_SongTiming.AddTimeSignatureSegment( seg ); songOut.m_SongTiming.AddSegment( SEGMENT_TIME_SIG, seg );
} }
+4 -49
View File
@@ -28,56 +28,11 @@ void TimingData::GetActualBPM( float &fMinBPMOut, float &fMaxBPMOut, float highe
} }
} }
void TimingData::AddSegment(TimingSegmentType tst, TimingSegment * seg)
void TimingData::AddBPMSegment( const BPMSegment &seg )
{ {
const vector<TimingSegment *> &segs = this->allTimingSegments[SEGMENT_BPM]; vector<TimingSegment *> &segs = this->allTimingSegments[tst];
segs.insert( upper_bound(segs.begin(), segs.end(), seg), seg ); // Unsure if this uses the proper comparison.
} 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 );
} }
/* Change an existing BPM segment, merge identical segments together or insert a new one. */ /* Change an existing BPM segment, merge identical segments together or insert a new one. */
+8 -57
View File
@@ -16,6 +16,8 @@ struct lua_State;
class TimingData class TimingData
{ {
public: public:
void AddSegment(TimingSegmentType tst, TimingSegment * seg);
/** /**
* @brief Sets up initial timing data with a defined offset. * @brief Sets up initial timing data with a defined offset.
* @param fOffset the offset from the 0th beat. */ * @param fOffset the offset from the 0th beat. */
@@ -78,11 +80,6 @@ public:
* @return the BPMSegment's index in question. * @return the BPMSegment's index in question.
*/ */
int GetBPMSegmentIndexAtBeat( float fBeat ) const { return GetBPMSegmentIndexAtRow( BeatToNoteRow(fBeat)); } 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. * @brief Retrieve the next beat that contains a BPMSegment.
@@ -276,11 +273,6 @@ public:
* @return the StopSegment's index in question. * @return the StopSegment's index in question.
*/ */
int GetDelaySegmentIndexAtBeat( float fBeat ) const { return GetStopSegmentIndexAtRow( BeatToNoteRow(fBeat), true ); } 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. * @brief Retrieve the next beat that contains a StopSegment.
@@ -430,16 +422,7 @@ public:
* @return the TimeSignatureSegment's index in question. * @return the TimeSignatureSegment's index in question.
*/ */
int GetTimeSignatureSegmentIndexAtBeat( float fBeat ) const { return GetTimeSignatureSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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. * @brief Retrieve the next beat that contains a TimeSignatureSegment.
@@ -472,7 +455,11 @@ public:
return this->GetPreviousTimeSignatureSegmentBeatAtRow( BeatToNoteRow(fBeat) ); 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; float GetWarpAtRow( int iRow ) const;
/** /**
* @brief Determine the beat to warp to. * @brief Determine the beat to warp to.
@@ -528,11 +515,6 @@ public:
* @return true if the row is inside a warp, false otherwise. * @return true if the row is inside a warp, false otherwise.
*/ */
bool IsWarpAtBeat( float fBeat ) const { return IsWarpAtRow( BeatToNoteRow( fBeat ) ); } 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. * @return the TickcountSegment's index in question.
*/ */
int GetTickcountSegmentIndexAtBeat( float fBeat ) const { return GetTickcountSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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. * @brief Retrieve the next beat that contains a TickcountSegment.
@@ -750,11 +727,6 @@ public:
* @return the ComboSegment's index in question. * @return the ComboSegment's index in question.
*/ */
int GetComboSegmentIndexAtBeat( float fBeat ) const { return GetComboSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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. * @brief Retrieve the next beat that contains a ComboSegment.
@@ -836,11 +808,6 @@ public:
* @return the LabelSegment's index in question. * @return the LabelSegment's index in question.
*/ */
int GetLabelSegmentIndexAtBeat( float fBeat ) const { return GetLabelSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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. * @brief Retrieve the previous beat that contains a LabelSegment.
@@ -993,11 +960,6 @@ public:
* @return the SpeedSegment's index in question. * @return the SpeedSegment's index in question.
*/ */
int GetSpeedSegmentIndexAtBeat( float fBeat ) const { return GetSpeedSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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; float GetDisplayedSpeedPercent( float fBeat, float fMusicSeconds ) const;
@@ -1085,12 +1047,6 @@ public:
*/ */
int GetScrollSegmentIndexAtBeat( float fBeat ) const { return GetScrollSegmentIndexAtRow( BeatToNoteRow(fBeat) ); } 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. * @brief Retrieve the next beat that contains a ScrollSegment.
* @param iRow the present row. * @param iRow the present row.
@@ -1183,11 +1139,6 @@ public:
* @return true if the row is inside a fake, false otherwise. * @return true if the row is inside a fake, false otherwise.
*/ */
bool IsFakeAtBeat( float fBeat ) const { return IsFakeAtRow( BeatToNoteRow( fBeat ) ); } 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. * @brief Retrieve the next beat that contains a FakeSegment.