Files
itgmania212121/stepmania/src/NoteData.cpp
T

947 lines
22 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-04-16 17:31:00 +00:00
/*
-----------------------------------------------------------------------------
2002-07-27 19:29:51 +00:00
Class: NoteData
2002-04-16 17:31:00 +00:00
2002-07-02 00:27:58 +00:00
Desc: See header.
2002-04-16 17:31:00 +00:00
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-04-16 17:31:00 +00:00
Chris Danford
-----------------------------------------------------------------------------
*/
#include "NoteData.h"
#include "RageUtil.h"
#include "RageLog.h"
2002-04-16 17:31:00 +00:00
NoteData::NoteData()
2002-06-24 22:04:31 +00:00
{
m_iNumTracks = 0;
2002-06-24 22:04:31 +00:00
Init();
}
void NoteData::Init()
2002-04-16 17:31:00 +00:00
{
2003-02-09 19:16:25 +00:00
ClearAll();
m_iNumTracks = 0; // must do this after calling ClearAll()!
2002-04-16 17:31:00 +00:00
}
2002-05-19 01:59:48 +00:00
NoteData::~NoteData()
{
}
2003-03-26 17:53:31 +00:00
int NoteData::GetNumTracks() const
2003-02-01 05:16:38 +00:00
{
return m_iNumTracks;
}
void NoteData::SetNumTracks( int iNewNumTracks )
{
m_iNumTracks = iNewNumTracks;
2003-02-01 05:27:49 +00:00
// Make sure that all tracks are of the same length
ASSERT( m_iNumTracks > 0 );
int rows = m_TapNotes[0].size();
for( int t=0; t<MAX_NOTE_TRACKS; t++ )
{
if( t<m_iNumTracks )
m_TapNotes[t].resize( rows, TAP_EMPTY );
else
m_TapNotes[t].clear();
}
/* Remove all hold notes that are out of bounds. */
for( int h = m_HoldNotes.size()-1; h >= 0; --h )
if( m_HoldNotes[h].iTrack >= iNewNumTracks )
m_HoldNotes.erase( m_HoldNotes.begin()+h );
2003-02-01 05:16:38 +00:00
}
/* Clear [iNoteIndexBegin,iNoteIndexEnd]; that is, including iNoteIndexEnd. */
2002-05-27 08:23:27 +00:00
void NoteData::ClearRange( int iNoteIndexBegin, int iNoteIndexEnd )
2002-04-16 17:31:00 +00:00
{
2002-08-25 05:00:23 +00:00
this->ConvertHoldNotesTo4s();
for( int c=0; c<m_iNumTracks; c++ )
2002-04-16 17:31:00 +00:00
{
2002-12-18 07:35:21 +00:00
for( int i=iNoteIndexBegin; i <= iNoteIndexEnd; i++ )
2002-10-25 05:19:27 +00:00
SetTapNote(c, i, TAP_EMPTY);
2002-04-16 17:31:00 +00:00
}
2002-08-25 05:00:23 +00:00
this->Convert4sToHoldNotes();
2002-04-16 17:31:00 +00:00
}
2002-08-25 05:00:23 +00:00
2002-12-14 20:30:49 +00:00
void NoteData::ClearAll()
{
for( int t=0; t<m_iNumTracks; t++ )
m_TapNotes[t].clear();
m_HoldNotes.clear();
}
2002-08-25 05:00:23 +00:00
/* Copy a range from pFrom to this. (Note that this does *not* overlay;
* all data in the range is overwritten.) */
2003-10-04 04:05:29 +00:00
void NoteData::CopyRange( const NoteData* pFrom, int iFromIndexBegin, int iFromIndexEnd, int iToIndexBegin )
2002-04-16 17:31:00 +00:00
{
ASSERT( pFrom->m_iNumTracks == m_iNumTracks );
2003-10-04 04:05:29 +00:00
NoteData From, To;
From.To4s( *pFrom );
To.To4s( *this );
2002-04-16 17:31:00 +00:00
// copy recorded TapNotes
2002-08-25 05:00:23 +00:00
int f = iFromIndexBegin, t = iToIndexBegin;
2002-06-29 11:59:09 +00:00
while( f<=iFromIndexEnd )
2002-04-16 17:31:00 +00:00
{
for( int c=0; c<m_iNumTracks; c++ )
2003-11-17 03:38:24 +00:00
{
TapNote tn = From.GetTapNote(c, f);
if( IsTapAttack(tn) )
{
Attack attack = From.GetAttackAt(c,f);
To.SetTapAttackNote( c, t, attack );
}
else
{
To.SetTapNote(c, t, tn);
}
}
2002-06-29 11:59:09 +00:00
f++;
t++;
2002-04-16 17:31:00 +00:00
}
2003-10-04 04:05:29 +00:00
this->From4s( To );
2002-04-16 17:31:00 +00:00
}
2002-12-13 01:23:26 +00:00
void NoteData::Config( const NoteData &From )
{
m_iNumTracks = From.m_iNumTracks;
}
2003-10-04 02:30:06 +00:00
void NoteData::CopyAll( const NoteData* pFrom )
2002-12-13 01:23:26 +00:00
{
Config(*pFrom);
ClearAll();
2003-10-04 02:30:06 +00:00
for( int c=0; c<m_iNumTracks; c++ )
m_TapNotes[c] = pFrom->m_TapNotes[c];
m_HoldNotes = pFrom->m_HoldNotes;
2003-11-17 03:38:24 +00:00
m_AttackMap = pFrom->m_AttackMap;
2002-12-13 01:23:26 +00:00
}
2003-12-11 04:52:23 +00:00
bool NoteData::IsRowEmpty( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return true;
for( int t=0; t<m_iNumTracks; t++ )
if( GetTapNoteX(t, index) != TAP_EMPTY )
return false;
return true;
}
int NoteData::GetNumTapNonEmptyTracks( int index ) const
{
int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ )
if( GetTapNote(t, index) != TAP_EMPTY )
iNum++;
return iNum;
}
int NoteData::GetFirstNonEmptyTrack( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return 0;
for( int t=0; t<m_iNumTracks; t++ )
if( GetTapNoteX( t, index ) != TAP_EMPTY )
return t;
return -1;
}
int NoteData::GetNumTracksWithTap( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return 0;
int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ )
{
TapNote tn = GetTapNoteX( t, index );
if( tn == TAP_TAP )
iNum++;
}
return iNum;
}
int NoteData::GetNumTracksWithTapOrHoldHead( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return 0;
int iNum = 0;
for( int t=0; t<m_iNumTracks; t++ )
{
TapNote tn = GetTapNoteX( t, index );
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
iNum++;
}
return iNum;
}
int NoteData::GetFirstTrackWithTap( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return -1;
for( int t=0; t<m_iNumTracks; t++ )
{
TapNote tn = GetTapNoteX( t, index );
if( tn == TAP_TAP || tn == TAP_ADDITION )
return t;
}
return -1;
}
int NoteData::GetFirstTrackWithTapOrHoldHead( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
if( index < 0 || index >= GetMaxRow() )
return -1;
for( int t=0; t<m_iNumTracks; t++ )
{
TapNote tn = GetTapNoteX( t, index );
if( tn == TAP_TAP || tn == TAP_ADDITION || tn == TAP_HOLD_HEAD )
return t;
}
return -1;
}
2002-04-16 17:31:00 +00:00
void NoteData::AddHoldNote( HoldNote add )
{
2003-12-16 04:00:39 +00:00
ASSERT( add.iStartRow>=0 && add.iEndRow>=0 );
2002-04-16 17:31:00 +00:00
int i;
// look for other hold notes that overlap and merge them
// XXX: this is done implicitly with 4s, but 4s uses this function.
// Rework this later.
2002-11-02 22:59:12 +00:00
for( i=0; i<GetNumHoldNotes(); i++ ) // for each HoldNote
2002-04-16 17:31:00 +00:00
{
2002-11-02 22:53:04 +00:00
HoldNote &other = GetHoldNote(i);
if( add.iTrack == other.iTrack && // the tracks correspond
2003-12-16 04:00:39 +00:00
add.RangeOverlaps(other) ) // they overlap
2002-04-16 17:31:00 +00:00
{
2003-12-16 04:00:39 +00:00
add.iStartRow = min(add.iStartRow, other.iStartRow);
add.iEndRow = max(add.iEndRow, other.iEndRow);
2002-04-16 17:31:00 +00:00
// delete this HoldNote
RemoveHoldNote( i );
--i;
2002-04-16 17:31:00 +00:00
}
}
2003-12-16 04:00:39 +00:00
int iAddStartIndex = add.iStartRow;
int iAddEndIndex = add.iEndRow;
2002-04-16 17:31:00 +00:00
// delete TapNotes under this HoldNote
for( i=iAddStartIndex+1; i<=iAddEndIndex; i++ )
SetTapNote(add.iTrack, i, TAP_EMPTY);
2002-04-16 17:31:00 +00:00
2002-06-14 22:25:22 +00:00
// add a tap note at the start of this hold
SetTapNote(add.iTrack, iAddStartIndex, TAP_HOLD_HEAD); // Hold begin marker. Don't draw this, but do grade it.
2002-06-14 22:25:22 +00:00
2002-11-02 23:10:38 +00:00
m_HoldNotes.push_back(add);
2002-04-16 17:31:00 +00:00
}
void NoteData::RemoveHoldNote( int iHoldIndex )
2002-04-16 17:31:00 +00:00
{
2002-11-02 23:10:38 +00:00
ASSERT( iHoldIndex >= 0 && iHoldIndex < GetNumHoldNotes() );
2002-11-02 22:53:04 +00:00
HoldNote& hn = GetHoldNote(iHoldIndex);
2003-12-16 04:00:39 +00:00
const int iHoldStartIndex = hn.iStartRow;
2002-04-16 17:31:00 +00:00
2002-06-14 22:25:22 +00:00
// delete a tap note at the start of this hold
SetTapNote(hn.iTrack, iHoldStartIndex, TAP_EMPTY);
2002-06-14 22:25:22 +00:00
// remove from list
2002-11-02 23:10:38 +00:00
m_HoldNotes.erase(m_HoldNotes.begin()+iHoldIndex, m_HoldNotes.begin()+iHoldIndex+1);
2002-04-16 17:31:00 +00:00
}
2003-12-18 02:34:59 +00:00
/* Get a hold note with the same track and end row as hn. */
int NoteData::GetMatchingHoldNote( const HoldNote &hn ) const
{
for( int i=0; i<GetNumHoldNotes(); i++ ) // for each HoldNote
{
const HoldNote &ret = GetHoldNote(i);
if( ret.iTrack == hn.iTrack && ret.iEndRow == hn.iEndRow )
return i;
}
FAIL_M( ssprintf("%i..%i, %i", hn.iStartRow, hn.iEndRow, hn.iTrack) );
2003-12-18 02:34:59 +00:00
}
2003-11-17 03:38:24 +00:00
void NoteData::SetTapAttackNote( int track, int row, Attack attack )
2003-11-15 08:51:47 +00:00
{
2003-11-15 23:19:13 +00:00
PruneUnusedAttacksFromMap();
2003-11-15 08:51:47 +00:00
2003-11-15 23:19:13 +00:00
// find first unused attack index
TapNote tn;
for( tn = TAP_ATTACK_BEGIN; tn<=TAP_ATTACK_END; tn++ )
{
if( m_AttackMap.find(tn) == m_AttackMap.end() ) // this TapNote value is free to use
goto done_searching;
}
ASSERT(0);
2003-11-15 08:51:47 +00:00
2003-11-15 23:19:13 +00:00
done_searching:
m_AttackMap[tn] = attack;
SetTapNote( track, row, tn );
2003-11-15 08:51:47 +00:00
}
2003-11-15 23:19:13 +00:00
void NoteData::PruneUnusedAttacksFromMap()
2003-11-15 08:51:47 +00:00
{
2003-11-15 23:19:13 +00:00
// Add all used AttackNote values to a map.
map<TapNote,int> mapAttackToNothing;
2003-11-15 08:51:47 +00:00
2003-11-15 23:19:13 +00:00
int max_row = GetMaxRow();
for( int t=0; t<m_iNumTracks; t++ )
2003-11-15 08:51:47 +00:00
{
2003-11-15 23:19:13 +00:00
for( int r=0; r<=max_row; r++ )
2003-11-15 08:51:47 +00:00
{
2003-11-15 23:19:13 +00:00
TapNote tn = GetTapNote(t, r);
if( IsTapAttack( tn ) )
mapAttackToNothing[tn] = 1;
2003-11-15 08:51:47 +00:00
}
}
2003-11-15 23:19:13 +00:00
// Remove all items from m_AttackMap that don't have corresponding
// TapNotes in use.
for( TapNote tn = TAP_ATTACK_BEGIN; tn<=TAP_ATTACK_END; tn++ )
{
bool bInAttackMap = m_AttackMap.find(tn) != m_AttackMap.end();
bool bActuallyUsed = mapAttackToNothing.find(tn) != mapAttackToNothing.end();
if( bActuallyUsed && !bInAttackMap )
ASSERT( 0 );
if( bInAttackMap && !bActuallyUsed )
{
m_AttackMap.erase( tn );
}
}
}
const Attack& NoteData::GetAttackAt( int track, int row )
{
TapNote tn = GetTapNote(track, row);
ASSERT( IsTapAttack(tn) );
2003-11-20 06:50:05 +00:00
ASSERT( m_AttackMap.find(tn) != m_AttackMap.end() );
2003-11-15 23:19:13 +00:00
return m_AttackMap[tn];
2003-11-15 08:51:47 +00:00
}
2003-11-15 23:19:13 +00:00
int NoteData::GetFirstRow() const
2002-04-16 17:31:00 +00:00
{
2003-12-16 04:00:39 +00:00
int iEarliestRowFoundSoFar = -1;
2002-04-16 17:31:00 +00:00
int i;
2003-12-16 04:00:39 +00:00
for( i=0; i < int(m_TapNotes[0].size()); i++ )
2002-07-11 19:02:26 +00:00
{
if( !IsRowEmpty(i) )
{
2003-12-16 04:00:39 +00:00
iEarliestRowFoundSoFar = i;
2002-07-11 19:02:26 +00:00
break;
}
}
2002-11-02 22:59:12 +00:00
for( i=0; i<GetNumHoldNotes(); i++ )
2003-03-06 22:40:04 +00:00
{
2003-12-16 04:00:39 +00:00
if( iEarliestRowFoundSoFar == -1 ||
GetHoldNote(i).iStartRow < iEarliestRowFoundSoFar )
iEarliestRowFoundSoFar = GetHoldNote(i).iStartRow;
2003-03-06 22:40:04 +00:00
}
2002-04-16 17:31:00 +00:00
2003-12-16 04:00:39 +00:00
if( iEarliestRowFoundSoFar == -1 ) // there are no notes
return 0;
2003-03-06 22:40:04 +00:00
2003-12-16 04:00:39 +00:00
return iEarliestRowFoundSoFar;
2002-07-11 19:02:26 +00:00
}
2003-12-16 04:00:39 +00:00
float NoteData::GetFirstBeat() const
2002-07-11 19:02:26 +00:00
{
2003-12-16 04:00:39 +00:00
return NoteRowToBeat( GetFirstRow() );
2002-07-11 19:02:26 +00:00
}
2003-12-16 04:00:39 +00:00
int NoteData::GetLastRow() const
2002-07-11 19:02:26 +00:00
{
2003-12-16 04:00:39 +00:00
int iOldestRowFoundSoFar = 0;
2002-07-11 19:02:26 +00:00
int i;
2002-12-20 02:45:23 +00:00
for( i = int(m_TapNotes[0].size()); i>=0; i-- ) // iterate back to front
2002-04-16 17:31:00 +00:00
{
2002-07-11 19:02:26 +00:00
if( !IsRowEmpty(i) )
2002-04-16 17:31:00 +00:00
{
2003-12-16 04:00:39 +00:00
iOldestRowFoundSoFar = i;
2002-07-11 19:02:26 +00:00
break;
2002-04-16 17:31:00 +00:00
}
}
2002-11-02 22:59:12 +00:00
for( i=0; i<GetNumHoldNotes(); i++ )
2002-07-11 19:02:26 +00:00
{
2003-12-16 04:00:39 +00:00
if( GetHoldNote(i).iEndRow > iOldestRowFoundSoFar )
iOldestRowFoundSoFar = GetHoldNote(i).iEndRow;
2002-07-11 19:02:26 +00:00
}
2002-04-16 17:31:00 +00:00
2003-12-16 04:00:39 +00:00
return iOldestRowFoundSoFar;
}
float NoteData::GetLastBeat() const
{
return NoteRowToBeat( GetLastRow() );
2002-04-16 17:31:00 +00:00
}
2003-02-25 19:49:16 +00:00
int NoteData::GetNumTapNotes( float fStartBeat, float fEndBeat ) const
2002-12-14 20:34:38 +00:00
{
2002-06-24 22:04:31 +00:00
int iNumNotes = 0;
2003-01-02 09:44:09 +00:00
2003-12-11 04:52:23 +00:00
if( fEndBeat == -1 )
fEndBeat = GetMaxBeat();
2002-05-19 01:59:48 +00:00
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
2003-12-11 04:52:23 +00:00
/* Clamp to known-good ranges. */
2003-12-11 21:26:57 +00:00
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 );
2003-01-02 09:44:09 +00:00
2002-12-14 20:34:38 +00:00
for( int t=0; t<m_iNumTracks; t++ )
{
2002-12-19 04:46:55 +00:00
for( int i=iStartIndex; i<=iEndIndex; i++ )
2002-12-14 20:34:38 +00:00
{
2003-12-11 04:52:23 +00:00
TapNote tn = GetTapNoteX(t, i);
if( tn != TAP_EMPTY && tn != TAP_MINE )
2002-06-24 22:04:31 +00:00
iNumNotes++;
2002-12-14 20:34:38 +00:00
}
}
2002-04-16 17:31:00 +00:00
2002-06-24 22:04:31 +00:00
return iNumNotes;
2002-04-16 17:31:00 +00:00
}
2003-11-10 01:24:46 +00:00
int NoteData::GetNumRowsWithTap( float fStartBeat, float fEndBeat ) const
{
int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetMaxBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
for( int i=iStartIndex; i<=iEndIndex; i++ )
if( IsThereATapAtRow(i) )
iNumNotes++;
return iNumNotes;
}
2003-11-26 04:21:59 +00:00
int NoteData::GetNumMines( float fStartBeat, float fEndBeat ) const
{
int iNumMines = 0;
2003-12-11 04:52:23 +00:00
if( fEndBeat == -1 )
fEndBeat = GetMaxBeat();
2003-11-26 04:21:59 +00:00
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
2003-12-11 04:52:23 +00:00
/* Clamp to known-good ranges. */
2003-12-11 21:26:57 +00:00
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 );
2003-11-26 04:21:59 +00:00
for( int t=0; t<m_iNumTracks; t++ )
{
for( int i=iStartIndex; i<=iEndIndex; i++ )
2003-12-11 04:52:23 +00:00
if( GetTapNoteX(t, i) == TAP_MINE )
2003-11-26 04:21:59 +00:00
iNumMines++;
}
return iNumMines;
}
2003-11-10 01:24:46 +00:00
int NoteData::GetNumRowsWithTapOrHoldHead( float fStartBeat, float fEndBeat ) const
{
int iNumNotes = 0;
if(fEndBeat == -1) fEndBeat = GetMaxBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
for( int i=iStartIndex; i<=iEndIndex; i++ )
if( IsThereATapOrHoldHeadAtRow(i) )
iNumNotes++;
return iNumNotes;
}
2003-12-16 07:58:37 +00:00
int NoteData::RowNeedsHands( const int row ) const
{
int iNumNotesThisIndex = 0;
for( int t=0; t<m_iNumTracks; t++ )
{
TapNote tn = GetTapNoteX(t, row);
if( tn == TAP_MINE || tn == TAP_EMPTY ) // mines don't count
continue;
++iNumNotesThisIndex;
}
/* We must have at least one non-hold-body at this row to count it. */
if( !iNumNotesThisIndex )
return false;
if( iNumNotesThisIndex < 3 )
{
/* We have at least one, but not enough. Count holds. */
for( int j=0; j<GetNumHoldNotes(); j++ )
{
const HoldNote &hn = GetHoldNote(j);
if( hn.iStartRow+1 <= row && row <= hn.iEndRow )
++iNumNotesThisIndex;
}
}
return iNumNotesThisIndex >= 3;
}
2003-11-26 04:31:29 +00:00
int NoteData::GetNumHands( float fStartBeat, float fEndBeat ) const
{
2003-12-16 04:00:39 +00:00
/* Count the number of times you have to use your hands. This includes
* three taps at the same time, a tap while two hold notes are being held,
* etc. Only count rows that have at least one tap note (hold heads count).
* Otherwise, every row of hold notes counts, so three simultaneous hold
* notes will count as hundreds of "hands". */
2003-11-26 04:31:29 +00:00
if( fEndBeat == -1 )
2003-12-16 04:00:39 +00:00
fEndBeat = GetMaxBeat();
2003-11-26 04:31:29 +00:00
2003-12-11 04:52:23 +00:00
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
2003-12-11 21:26:57 +00:00
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 );
2003-11-26 04:31:29 +00:00
int iNum = 0;
2003-12-16 04:01:26 +00:00
for( int i=iStartIndex; i<=iEndIndex; i++ )
2003-11-26 04:31:29 +00:00
{
2003-12-16 07:58:37 +00:00
if( !RowNeedsHands(i) )
2003-12-16 04:00:39 +00:00
continue;
2003-12-16 04:01:26 +00:00
2003-12-16 07:58:37 +00:00
iNum++;
2003-11-26 04:31:29 +00:00
}
2003-12-16 04:01:26 +00:00
2003-11-26 04:31:29 +00:00
return iNum;
}
2003-11-26 04:21:59 +00:00
int NoteData::GetNumN( int MinTaps, float fStartBeat, float fEndBeat ) const
2002-05-19 01:59:48 +00:00
{
2003-11-26 04:21:59 +00:00
if( fEndBeat == -1 )
fEndBeat = GetMaxBeat();
2002-05-19 01:59:48 +00:00
2003-12-11 04:52:23 +00:00
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
/* Clamp to known-good ranges. */
2003-12-11 21:26:57 +00:00
iStartIndex = max( iStartIndex, 0 );
iEndIndex = min( iEndIndex, GetMaxRow()-1 );
2002-05-19 01:59:48 +00:00
2003-11-26 04:21:59 +00:00
int iNum = 0;
2002-12-18 07:35:21 +00:00
for( int i=iStartIndex; i<=iEndIndex; i++ )
2002-05-19 01:59:48 +00:00
{
int iNumNotesThisIndex = 0;
for( int t=0; t<m_iNumTracks; t++ )
{
2003-12-11 04:52:23 +00:00
TapNote tn = GetTapNoteX(t, i);
if( tn != TAP_MINE && tn != TAP_EMPTY ) // mines don't count
2002-05-19 01:59:48 +00:00
iNumNotesThisIndex++;
}
2003-11-26 04:21:59 +00:00
if( iNumNotesThisIndex >= MinTaps )
iNum++;
2002-05-19 01:59:48 +00:00
}
2003-11-26 04:21:59 +00:00
return iNum;
2002-05-19 01:59:48 +00:00
}
2003-02-25 19:49:16 +00:00
int NoteData::GetNumHoldNotes( float fStartBeat, float fEndBeat ) const
2002-05-19 01:59:48 +00:00
{
2003-12-16 04:00:39 +00:00
if( fEndBeat == -1 )
fEndBeat = GetMaxBeat();
int iStartIndex = BeatToNoteRow( fStartBeat );
int iEndIndex = BeatToNoteRow( fEndBeat );
2002-05-19 01:59:48 +00:00
2003-12-16 04:00:39 +00:00
int iNumHolds = 0;
2002-11-02 22:59:12 +00:00
for( int i=0; i<GetNumHoldNotes(); i++ )
2002-05-19 01:59:48 +00:00
{
2002-11-02 22:53:04 +00:00
const HoldNote &hn = GetHoldNote(i);
2003-12-16 04:00:39 +00:00
if( iStartIndex <= hn.iStartRow && hn.iEndRow <= iEndIndex )
2002-06-24 22:04:31 +00:00
iNumHolds++;
2002-05-19 01:59:48 +00:00
}
2002-06-24 22:04:31 +00:00
return iNumHolds;
2002-04-16 17:31:00 +00:00
}
void NoteData::Convert2sAnd3sToHoldNotes()
{
2002-10-25 05:06:52 +00:00
// Any note will end a hold (not just a TAP_HOLD_TAIL). This makes parsing DWIs much easier.
// Plus, allowing tap notes in the middle of a hold doesn't make sense!
2002-04-16 17:31:00 +00:00
2002-11-24 06:59:58 +00:00
int rows = GetLastRow();
2002-04-16 17:31:00 +00:00
for( int col=0; col<m_iNumTracks; col++ ) // foreach column
{
2002-11-24 06:59:58 +00:00
for( int i=0; i<=rows; i++ ) // foreach TapNote element
2002-04-16 17:31:00 +00:00
{
2002-10-25 05:19:27 +00:00
if( GetTapNote(col, i) != TAP_HOLD_HEAD ) // this is a HoldNote begin marker
continue;
2002-10-25 05:19:27 +00:00
SetTapNote(col, i, TAP_EMPTY);
2002-11-24 06:59:58 +00:00
for( int j=i+1; j<=rows; j++ ) // search for end of HoldNote
2002-04-16 17:31:00 +00:00
{
// end hold on the next note we see
2002-10-25 05:19:27 +00:00
if( GetTapNote(col, j) == TAP_EMPTY )
continue;
2002-10-25 05:19:27 +00:00
SetTapNote(col, j, TAP_EMPTY);
2003-12-16 04:00:39 +00:00
AddHoldNote( HoldNote(col, i, j) );
break;
2002-04-16 17:31:00 +00:00
}
}
}
}
2002-08-25 05:00:23 +00:00
/* "102000301" ==
* "104444001" */
2002-04-16 17:31:00 +00:00
void NoteData::ConvertHoldNotesTo2sAnd3s()
{
// copy HoldNotes into the new structure, but expand them into 2s and 3s
2002-11-02 22:59:12 +00:00
for( int i=0; i<GetNumHoldNotes(); i++ )
2002-04-16 17:31:00 +00:00
{
2002-11-02 22:53:04 +00:00
const HoldNote &hn = GetHoldNote(i);
/* If they're the same, then they got clamped together, so just ignore it. */
2003-12-16 04:00:39 +00:00
if( hn.iStartRow != hn.iEndRow )
{
SetTapNote( hn.iTrack, hn.iStartRow, TAP_HOLD_HEAD );
SetTapNote( hn.iTrack, hn.iEndRow, TAP_HOLD_TAIL );
}
2002-04-16 17:31:00 +00:00
}
2002-11-02 23:10:38 +00:00
m_HoldNotes.clear();
2002-04-16 17:31:00 +00:00
}
2003-10-04 03:12:45 +00:00
void NoteData::To2sAnd3s( const NoteData &out )
{
2003-10-04 03:12:45 +00:00
CopyAll( &out );
ConvertHoldNotesTo2sAnd3s();
}
void NoteData::From2sAnd3s( const NoteData &out )
{
CopyAll( &out );
Convert2sAnd3sToHoldNotes();
}
2003-10-04 04:05:29 +00:00
void NoteData::To4s( const NoteData &out )
{
CopyAll( &out );
ConvertHoldNotesTo4s();
}
void NoteData::From4s( const NoteData &out )
{
CopyAll( &out );
Convert4sToHoldNotes();
}
2002-08-25 05:00:23 +00:00
/* "104444001" ==
* "102000301"
*
* "4441" basically means "hold for three rows then hold for another tap";
* since taps don't really have a length, it's equivalent to "4440".
* So, make sure the character after a 4 is always a 0. */
void NoteData::Convert4sToHoldNotes()
{
int rows = GetLastRow();
2002-08-25 05:00:23 +00:00
for( int col=0; col<m_iNumTracks; col++ ) // foreach column
{
for( int i=0; i<=rows; i++ ) // foreach TapNote element
2002-08-25 05:00:23 +00:00
{
2002-10-25 05:19:27 +00:00
if( GetTapNote(col, i) != TAP_HOLD ) // this is a HoldNote body
2002-08-25 05:00:23 +00:00
continue;
2003-12-16 04:00:39 +00:00
HoldNote hn( col, i, 0 );
2002-08-25 05:00:23 +00:00
// search for end of HoldNote
do {
2002-10-25 04:59:12 +00:00
SetTapNote(col, i, TAP_EMPTY);
2002-08-25 05:00:23 +00:00
i++;
2002-10-25 05:06:52 +00:00
} while( GetTapNote(col, i) == TAP_HOLD);
2002-10-25 04:59:12 +00:00
SetTapNote(col, i, TAP_EMPTY);
2002-08-25 05:00:23 +00:00
2003-12-16 04:00:39 +00:00
hn.iEndRow = i;
2002-08-25 05:00:23 +00:00
AddHoldNote( hn );
}
}
}
void NoteData::ConvertHoldNotesTo4s()
{
// copy HoldNotes into the new structure, but expand them into 4s
2002-11-02 22:59:12 +00:00
for( int i=0; i<GetNumHoldNotes(); i++ )
2002-08-25 05:00:23 +00:00
{
2002-11-02 22:53:04 +00:00
const HoldNote &hn = GetHoldNote(i);
2003-12-16 04:00:39 +00:00
for( int j = hn.iStartRow; j < hn.iEndRow; ++j)
SetTapNote(hn.iTrack, j, TAP_HOLD);
2002-08-25 05:00:23 +00:00
}
2002-11-02 23:10:38 +00:00
m_HoldNotes.clear();
2002-08-25 05:00:23 +00:00
}
// -1 for iOriginalTracksToTakeFrom means no track
void NoteData::LoadTransformed( const NoteData* pOriginal, int iNewNumTracks, const int iOriginalTrackToTakeFrom[] )
2002-04-16 17:31:00 +00:00
{
// reset all notes
2002-07-03 21:27:26 +00:00
Init();
2002-04-16 17:31:00 +00:00
NoteData Original;
Original.To4s( *pOriginal );
2002-10-20 19:34:17 +00:00
Config( Original );
2002-04-16 17:31:00 +00:00
m_iNumTracks = iNewNumTracks;
// copy tracks
for( int t=0; t<m_iNumTracks; t++ )
{
const int iOriginalTrack = iOriginalTrackToTakeFrom[t];
RAGE_ASSERT_M( iOriginalTrack < Original.m_iNumTracks, ssprintf("from %i >= %i (to %i)",
iOriginalTrack, Original.m_iNumTracks, iOriginalTrackToTakeFrom[t]));
2002-12-28 16:07:19 +00:00
if( iOriginalTrack == -1 )
continue;
m_TapNotes[t] = Original.m_TapNotes[iOriginalTrack];
2002-04-16 17:31:00 +00:00
}
Convert4sToHoldNotes();
2003-11-17 04:01:21 +00:00
m_AttackMap = Original.GetAttackMap();
2002-04-16 17:31:00 +00:00
}
2002-06-24 22:04:31 +00:00
2003-11-01 19:59:50 +00:00
void NoteData::LoadOverlapped( const NoteData* pOriginal, int iNewNumTracks )
{
2003-11-02 02:12:04 +00:00
SetNumTracks( iNewNumTracks );
NoteData in;
2003-11-04 20:22:49 +00:00
in.To4s( *pOriginal );
2003-11-01 19:59:50 +00:00
2003-12-02 22:55:55 +00:00
/* Keep track of the last source track that put a tap into each destination track,
* and the row of that tap. Then, if two rows are trying to put taps into the
* same row within the shift threshold, shift the newcomer source row. */
int LastSourceTrack[MAX_NOTE_TRACKS];
int LastSourceRow[MAX_NOTE_TRACKS];
int DestRow[MAX_NOTE_TRACKS];
for( unsigned tr = 0; tr < MAX_NOTE_TRACKS; ++tr )
2003-11-01 19:59:50 +00:00
{
2003-12-02 22:55:55 +00:00
LastSourceTrack[tr] = -1;
LastSourceRow[tr] = -9999;
DestRow[tr] = tr;
wrap( DestRow[tr], iNewNumTracks );
}
2003-11-02 02:12:04 +00:00
2003-12-02 22:55:55 +00:00
const int ShiftThreshold = BeatToNoteRow(1);
const int iLastRow = in.GetMaxRow();
for( int row = 0; row < iLastRow; ++row )
{
for ( int i = 0; i < in.GetNumTracks(); i++ )
2003-11-01 19:59:50 +00:00
{
2003-12-02 22:55:55 +00:00
const int iTrackFrom = i;
int &iTrackTo = DestRow[i];
2003-11-02 02:12:04 +00:00
2003-12-02 22:55:55 +00:00
const TapNote iStepFrom = in.m_TapNotes[iTrackFrom][row];
if( iStepFrom == TAP_EMPTY )
2003-11-04 20:22:49 +00:00
continue;
2003-12-02 22:55:55 +00:00
if( LastSourceTrack[iTrackTo] != iTrackFrom &&
row - LastSourceRow[iTrackTo] < ShiftThreshold )
{
/* This destination track is in use by a different source track. Use the
* least-recently-used track. */
for( int DestTrack = 0; DestTrack < iNewNumTracks; ++DestTrack )
if( LastSourceRow[DestTrack] < LastSourceRow[iTrackTo] )
iTrackTo = DestTrack;
}
2003-11-13 07:40:49 +00:00
2003-12-02 22:55:55 +00:00
/* If it's still in use, then we just don't have an available track. */
if( LastSourceTrack[iTrackTo] != iTrackFrom &&
row - LastSourceRow[iTrackTo] < ShiftThreshold )
2003-11-13 07:40:49 +00:00
continue;
2003-12-02 22:55:55 +00:00
LastSourceTrack[iTrackTo] = iTrackFrom;
LastSourceRow[iTrackTo] = row;
2003-11-04 20:22:49 +00:00
SetTapNote( iTrackTo, row, iStepFrom );
2003-11-01 19:59:50 +00:00
}
}
2003-11-02 02:12:04 +00:00
2003-11-04 20:22:49 +00:00
Convert4sToHoldNotes();
2003-11-01 19:59:50 +00:00
}
void NoteData::LoadTransformedSlidingWindow( const NoteData* pOriginal, int iNewNumTracks )
{
2002-10-20 19:34:17 +00:00
// reset all notes
Init();
2003-11-01 19:59:50 +00:00
if( pOriginal->GetNumTracks() > iNewNumTracks )
{
2003-12-02 22:55:55 +00:00
/* Use a different algorithm for reducing tracks. */
2003-11-01 19:59:50 +00:00
LoadOverlapped( pOriginal, iNewNumTracks );
return;
}
NoteData Original;
Original.To4s( *pOriginal );
2002-12-13 01:23:26 +00:00
Config(*pOriginal);
m_iNumTracks = iNewNumTracks;
2002-12-19 04:39:16 +00:00
2002-10-05 20:03:14 +00:00
int iCurTrackOffset = 0;
int iTrackOffsetMin = 0;
int iTrackOffsetMax = abs( iNewNumTracks - Original.m_iNumTracks );
2002-10-05 20:03:14 +00:00
int bOffsetIncreasing = true;
int iLastRow = Original.GetLastRow();
for( int r=0; r<=iLastRow; )
{
2002-12-19 04:39:16 +00:00
// copy notes in this measure
for( int t=0; t<Original.m_iNumTracks; t++ )
2002-12-19 04:39:16 +00:00
{
int iOldTrack = t;
int iNewTrack = (iOldTrack + iCurTrackOffset) % iNewNumTracks;
this->SetTapNote(iNewTrack, r, Original.GetTapNote(iOldTrack, r));
}
2002-12-19 04:39:16 +00:00
r++;
if( r % (ROWS_PER_MEASURE*4) == 0 ) // adjust sliding window every 4 measures
{
2002-10-05 20:03:14 +00:00
// See if there is a hold crossing the beginning of this measure
bool bHoldCrossesThisMeasure = false;
if( r )
for( int t=0; t<=Original.m_iNumTracks; t++ )
{
if( Original.GetTapNote(t, r) == TAP_HOLD &&
Original.GetTapNote(t, r-1) == TAP_HOLD)
{
bHoldCrossesThisMeasure = true;
break;
}
}
2002-10-05 20:03:14 +00:00
// adjust offset
if( !bHoldCrossesThisMeasure )
{
iCurTrackOffset += bOffsetIncreasing ? 1 : -1;
if( iCurTrackOffset == iTrackOffsetMin || iCurTrackOffset == iTrackOffsetMax )
bOffsetIncreasing ^= true;
CLAMP( iCurTrackOffset, iTrackOffsetMin, iTrackOffsetMax );
}
}
}
Convert4sToHoldNotes();
2003-11-17 04:01:21 +00:00
m_AttackMap = Original.GetAttackMap();
}
void NoteData::PadTapNotes(int rows)
{
2003-02-01 05:27:49 +00:00
int needed = rows - m_TapNotes[0].size() + 1;
if(needed < 0)
return;
needed += 100; /* optimization: give it a little more than it needs */
2002-11-03 01:33:33 +00:00
for(int track = 0; track < m_iNumTracks; ++track)
2002-11-03 21:37:08 +00:00
m_TapNotes[track].insert(m_TapNotes[track].end(), needed, TAP_EMPTY);
}
2002-11-02 21:04:00 +00:00
void NoteData::MoveTapNoteTrack(int dest, int src)
{
if(dest == src) return;
m_TapNotes[dest] = m_TapNotes[src];
m_TapNotes[src].clear();
}
void NoteData::SetTapNote(int track, int row, TapNote t)
{
if(row < 0) return;
2002-12-13 01:23:26 +00:00
PadTapNotes(row);
m_TapNotes[track][row]=t;
}
2003-09-21 23:16:44 +00:00
2003-12-11 04:52:23 +00:00
void NoteData::ReserveRows( int row )
{
for(int track = 0; track < m_iNumTracks; ++track)
m_TapNotes[track].reserve( row );
}
2003-09-21 23:16:44 +00:00
void NoteData::EliminateAllButOneTap(int row)
{
if(row < 0) return;
PadTapNotes(row);
int track;
2003-11-02 17:07:09 +00:00
for(track = 0; track < m_iNumTracks; ++track)
2003-09-21 23:16:44 +00:00
{
if( m_TapNotes[track][row] == TAP_TAP )
break;
}
track++;
for( ; track < m_iNumTracks; ++track)
{
if( m_TapNotes[track][row] == TAP_TAP )
m_TapNotes[track][row] = TAP_EMPTY;
}
}
2003-11-07 05:17:41 +00:00
2003-11-07 09:27:28 +00:00
void NoteData::GetTracksHeldAtRow( int row, vector<int>& viTracksOut )
2003-11-07 05:17:41 +00:00
{
for( unsigned i=0; i<m_HoldNotes.size(); i++ )
{
const HoldNote& hn = m_HoldNotes[i];
2003-11-07 09:27:28 +00:00
2003-12-16 04:00:39 +00:00
if( hn.RowIsInRange(row) )
2003-11-07 09:27:28 +00:00
viTracksOut.push_back( hn.iTrack );
2003-11-07 05:17:41 +00:00
}
2003-11-07 09:27:28 +00:00
}
int NoteData::GetNumTracksHeldAtRow( int row )
{
static vector<int> viTracks;
viTracks.clear();
GetTracksHeldAtRow( row, viTracks );
return viTracks.size();
2003-11-10 01:34:55 +00:00
}