#include "stdafx.h" /* ----------------------------------------------------------------------------- Class: NoteData Desc: See header. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "NoteData.h" #include "RageUtil.h" #include "GameConstantsAndTypes.h" #include "PrefsManager.h" #include "ArrowEffects.h" #include "PrefsManager.h" #include "GameConstantsAndTypes.h" #include "RageException.h" #include "GameState.h" NoteData::NoteData() { Init(); } void NoteData::Init() { memset( m_TapNotes, '0', MAX_NOTE_TRACKS*MAX_TAP_NOTE_ROWS*sizeof(m_TapNotes[0][0]) ); m_iNumTracks = 0; m_iNumHoldNotes = 0; } NoteData::~NoteData() { } void NoteData::LoadFromSMNoteDataString( CString sSMNoteData ) { int iNumTracks = m_iNumTracks; NoteData::Init(); m_iNumTracks = iNumTracks; // strip comments out of sSMNoteData while( sSMNoteData.Find("//") != -1 ) { int iIndexCommentStart = sSMNoteData.Find("//"); int iIndexCommentEnd = sSMNoteData.Find("\n", iIndexCommentStart); if( iIndexCommentEnd == -1 ) // comment doesn't have an end? sSMNoteData.Delete( iIndexCommentStart, 2 ); else sSMNoteData.Delete( iIndexCommentStart, iIndexCommentEnd-iIndexCommentStart ); } CStringArray asMeasures; split( sSMNoteData, ",", asMeasures, true ); // ignore empty is important for( int m=0; mConvert2sAnd3sToHoldNotes(); } CString NoteData::GetSMNoteDataString() { this->ConvertHoldNotesTo2sAnd3s(); float fLastBeat = GetLastBeat(); int iLastMeasure = int( fLastBeat/BEATS_PER_MEASURE ); CStringArray asMeasureStrings; for( int m=0; m<=iLastMeasure; m++ ) // foreach measure { NoteType nt = GetSmallestNoteTypeForMeasure( m ); float fBeatSpacing = NoteTypeToBeat( nt ); int iRowSpacing = roundf( fBeatSpacing * ROWS_PER_BEAT ); CStringArray asMeasureLines; asMeasureLines.Add( ssprintf(" // measure %d", m+1) ); const int iMeasureStartRow = m * ROWS_PER_MEASURE; const int iMeasureLastRow = (m+1) * ROWS_PER_MEASURE - 1; for( int r=iMeasureStartRow; r<=iMeasureLastRow; r+=iRowSpacing ) { char szLineString[MAX_NOTE_TRACKS]; for( int t=0; tConvert2sAnd3sToHoldNotes(); return join( "\n,", asMeasureStrings ); } void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd ) { // delete old TapNotes in the range for( int i=iNoteIndexBegin; i<=iNoteIndexEnd; i++ ) { for( int c=0; c= iNoteIndexBegin && iHoldStartIndex <= iNoteIndexEnd) || (iHoldEndIndex >= iNoteIndexBegin && iHoldEndIndex <= iNoteIndexEnd) ) // overlap (kinda) { ; // do nothing } else // ! overlap { m_HoldNotes[iIndexWrite] = m_HoldNotes[iIndexRead]; iIndexWrite++; } } m_iNumHoldNotes = iIndexWrite; } void NoteData::CopyRange( NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin ) { ASSERT( pFrom->m_iNumTracks == m_iNumTracks ); if( iToIndexBegin == -1 ) iToIndexBegin = 0; pFrom->ConvertHoldNotesTo2sAnd3s(); int f, t; // copy recorded TapNotes f = iFromIndexBegin; t = iToIndexBegin; while( f<=iFromIndexEnd ) { for( int c=0; cm_TapNotes[c][f]; f++; t++; } pFrom->Convert2sAnd3sToHoldNotes(); this->Convert2sAnd3sToHoldNotes(); } void NoteData::AddHoldNote( HoldNote add ) { int i; // look for other hold notes that overlap and merge them for( i=0; i= add.m_fStartBeat ) // these HoldNotes overlap (this isn't entirely correct!) { add.m_fStartBeat = min(add.m_fStartBeat, other.m_fStartBeat); add.m_fEndBeat = max(add.m_fEndBeat, other.m_fEndBeat); // delete this HoldNote for( int j=i; j= 0 && iHoldIndex < m_iNumHoldNotes ); HoldNote& hn = m_HoldNotes[iHoldIndex]; int iHoldStartIndex = BeatToNoteRow(hn.m_fStartBeat); int iHoldEndIndex = BeatToNoteRow(hn.m_fEndBeat); // delete a tap note at the start of this hold m_TapNotes[hn.m_iTrack][iHoldStartIndex] = '0'; // remove from list for( int j=iHoldIndex; j=0; i-- ) // iterate back to front { if( !IsRowEmpty(i) ) { fOldestBeatFoundSoFar = NoteRowToBeat(i); break; } } for( i=0; i fOldestBeatFoundSoFar ) fOldestBeatFoundSoFar = m_HoldNotes[i].m_fEndBeat; } return fOldestBeatFoundSoFar; } int NoteData::GetNumTapNotes( const float fStartBeat, const float fEndBeat ) { int iNumNotes = 0; int iStartIndex = BeatToNoteRow( fStartBeat ); int iEndIndex = BeatToNoteRow( fEndBeat ); for( int i=iStartIndex; i= 2 ) iNumDoubles++; } return iNumDoubles; } int NoteData::GetNumHoldNotes( const float fStartBeat, const float fEndBeat ) { int iNumHolds = 0; for( int i=0; i=0; i-- ) // foreach HoldNote { if( c >= iFirstRightSideColumn ) { // delete this HoldNote by shifting everything down for( int j=i; j=0; i-- ) // foreach HoldNote { HoldNote &hn = m_HoldNotes[i]; if( hn.m_iTrack < iFirstRightSideColumn ) { // delete this HoldNote by shifting everything down RemoveHoldNote( i ); } else { m_HoldNotes[i].m_iTrack -= 4; } } } void NoteData::RemoveHoldNotes() { // turn all the HoldNotes into TapNotes for( int i=0; iGetCurrentStyleDef()->m_NotesType ) { case NOTES_TYPE_DANCE_SINGLE: case NOTES_TYPE_DANCE_DOUBLE: case NOTES_TYPE_DANCE_COUPLE: iTakeFromTrack[0] = 2; iTakeFromTrack[1] = 0; iTakeFromTrack[2] = 3; iTakeFromTrack[3] = 1; iTakeFromTrack[4] = 6; iTakeFromTrack[5] = 4; iTakeFromTrack[6] = 7; iTakeFromTrack[7] = 5; break; case NOTES_TYPE_DANCE_SOLO: iTakeFromTrack[0] = 5; iTakeFromTrack[1] = 4; iTakeFromTrack[2] = 0; iTakeFromTrack[3] = 3; iTakeFromTrack[4] = 1; iTakeFromTrack[5] = 2; break; case NOTES_TYPE_PUMP_SINGLE: case NOTES_TYPE_PUMP_DOUBLE: case NOTES_TYPE_PUMP_COUPLE: iTakeFromTrack[0] = 1; iTakeFromTrack[1] = 3; iTakeFromTrack[2] = 2; iTakeFromTrack[3] = 4; iTakeFromTrack[4] = 0; iTakeFromTrack[5] = 6; iTakeFromTrack[6] = 8; iTakeFromTrack[7] = 7; iTakeFromTrack[8] = 9; iTakeFromTrack[9] = 5; break; case NOTES_TYPE_EZ2_SINGLE: case NOTES_TYPE_EZ2_SINGLE_HARD: case NOTES_TYPE_EZ2_DOUBLE: case NOTES_TYPE_EZ2_REAL: // identity transform. What should we do here? iTakeFromTrack[0] = 0; iTakeFromTrack[1] = 1; iTakeFromTrack[2] = 2; iTakeFromTrack[3] = 3; iTakeFromTrack[4] = 4; iTakeFromTrack[5] = 5; iTakeFromTrack[6] = 6; iTakeFromTrack[7] = 7; iTakeFromTrack[8] = 8; iTakeFromTrack[9] = 9; iTakeFromTrack[10]= 10; iTakeFromTrack[11]= 11; break; } break; case PlayerOptions::TURN_SHUFFLE: CArray aiTracksLeftToMap; for( t=0; tConvertHoldNotesTo2sAnd3s(); // transform notes for( t=0; tCopyAll( &tempNoteData ); // copy note data from newData back into this this->Convert2sAnd3sToHoldNotes(); } void NoteData::MakeLittle() { // filter out all non-quarter notes for( int i=0; i= NOTE_TYPE_12TH ) iNumChaosNotes++; } float fReturn = iNumChaosNotes / fSongSeconds * 0.5f; return min( fReturn, 1.0f ); } float NoteData::GetFreezeRadarValue( float fSongSeconds ) { // number of hold steps float fReturn = GetNumHoldNotes() / fSongSeconds; return min( fReturn, 1.0f ); } void NoteData::LoadTransformed( const NoteData* pOriginal, int iNewNumTracks, const int iNewToOriginalTrack[] ) { // init Init(); m_iNumTracks = iNewNumTracks; // copy tracks for( int t=0; tm_TapNotes[iOriginalTrack], MAX_TAP_NOTE_ROWS*sizeof(m_TapNotes[0][0]) ); for( i=0; im_iNumHoldNotes; i++ ) { HoldNote hn = pOriginal->m_HoldNotes[i]; if( hn.m_iTrack == iOriginalTrack ) { hn.m_iTrack = t; this->AddHoldNote( hn ); } } } } NoteType NoteData::GetSmallestNoteTypeForMeasure( int iMeasureIndex ) { const int iMeasureStartIndex = iMeasureIndex * ROWS_PER_MEASURE; const int iMeasureLastIndex = (iMeasureIndex+1) * ROWS_PER_MEASURE - 1; // probe to find the smallest note type NoteType nt; for( nt=(NoteType)0; nt