Files
itgmania212121/stepmania/src/NoteData.cpp
T

857 lines
21 KiB
C++
Raw Normal View History

2002-04-16 17:31:00 +00:00
/*
2004-05-31 22:42:12 +00:00
* NoteData is organized by:
* track - corresponds to different columns of notes on the screen
* row/index - corresponds to subdivisions of beats
*/
2002-04-16 17:31:00 +00:00
2004-05-31 22:42:12 +00:00
#include "global.h"
2002-04-16 17:31:00 +00:00
#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
{
Init();
}
void NoteData::Init()
2002-04-16 17:31:00 +00:00
{
2003-02-09 19:16:25 +00:00
ClearAll();
2004-09-25 07:59:56 +00:00
m_TapNotes.clear();
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
{
2004-09-25 07:59:56 +00:00
return m_TapNotes.size();
2003-02-01 05:16:38 +00:00
}
void NoteData::SetNumTracks( int iNewNumTracks )
{
2004-09-25 07:59:56 +00:00
ASSERT( iNewNumTracks > 0 );
2003-02-01 05:27:49 +00:00
2004-09-25 07:59:56 +00:00
m_TapNotes.resize( iNewNumTracks );
2003-02-01 05:27:49 +00:00
2004-09-25 07:59:56 +00:00
// Enforce that all track vectors have the same length.
unsigned uNumRows = m_TapNotes[0].size();
for( unsigned t=0; t<m_TapNotes.size(); t++ )
2003-02-01 05:27:49 +00:00
{
2004-09-25 07:59:56 +00:00
m_TapNotes[t].resize( uNumRows, TAP_EMPTY );
2003-02-01 05:27:49 +00:00
}
/* Remove all hold notes that are out of bounds. */
2004-09-25 07:59:56 +00:00
// Iterate backwards so that we can delete.
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();
2004-09-25 07:59:56 +00:00
for( unsigned t=0; t<m_TapNotes.size(); t++ )
2002-04-16 17:31:00 +00:00
{
2002-12-18 07:35:21 +00:00
for( int i=iNoteIndexBegin; i <= iNoteIndexEnd; i++ )
2004-09-25 07:59:56 +00:00
SetTapNote(t, 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()
{
2004-09-25 07:59:56 +00:00
for( unsigned t=0; t<m_TapNotes.size(); t++ )
2004-05-24 04:26:54 +00:00
m_TapNotes[t].clear();
2002-12-14 20:30:49 +00:00
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
{
2004-09-25 07:59:56 +00:00
ASSERT( pFrom->GetNumTracks() == GetNumTracks() );
2002-04-16 17:31:00 +00:00
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
2004-05-24 04:17:19 +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
{
2004-09-28 02:14:56 +00:00
for( int c=0; c<GetNumTracks(); c++ )
2003-11-17 03:38:24 +00:00
{
TapNote tn = From.GetTapNote( c, f );
if( tn.type == TapNote::attack )
2003-11-17 03:38:24 +00:00
{
Attack attack = From.GetAttackAt( c, f );
2003-11-17 03:38:24 +00:00
To.SetTapAttackNote( c, t, attack );
}
else
{
To.SetTapNote( c, t, tn );
2003-11-17 03:38:24 +00:00
}
}
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 )
{
2004-09-25 07:59:56 +00:00
SetNumTracks( From.GetNumTracks() );
2002-12-13 01:23:26 +00:00
}
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
2004-09-28 02:14:56 +00:00
for( int c=0; c<GetNumTracks(); c++ )
2004-05-24 04:26:54 +00:00
m_TapNotes[c] = pFrom->m_TapNotes[c];
2003-10-04 02:30:06 +00:00
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. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return true;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX(t, index).type != TapNote::empty )
2003-12-11 04:52:23 +00:00
return false;
return true;
}
bool NoteData::IsRangeEmpty( int track, int iIndexBegin, int iIndexEnd ) const
{
2004-09-25 07:59:56 +00:00
ASSERT( track < GetNumTracks() );
2004-09-11 03:50:37 +00:00
CLAMP( iIndexBegin, 0, GetNumRows()-1 );
CLAMP( iIndexEnd, 0, GetNumRows()-1 );
for( int i=iIndexBegin; i<=iIndexEnd; i++ )
if( GetTapNoteX(track,i).type != TapNote::empty )
return false;
return true;
}
2003-12-11 04:52:23 +00:00
int NoteData::GetNumTapNonEmptyTracks( int index ) const
{
int iNum = 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNote(t, index).type != TapNote::empty )
2003-12-11 04:52:23 +00:00
iNum++;
return iNum;
}
2004-05-15 03:00:43 +00:00
void NoteData::GetTapNonEmptyTracks( int index, set<int>& addTo ) const
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNote(t, index).type != TapNote::empty )
2004-05-15 03:00:43 +00:00
addTo.insert(t);
}
2003-12-11 04:52:23 +00:00
int NoteData::GetFirstNonEmptyTrack( int index ) const
{
/* If this is out of range, we don't have any notes there, so all tracks are empty. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
if( GetTapNoteX( t, index ).type != TapNote::empty )
2003-12-11 04:52:23 +00:00
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. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return 0;
int iNum = 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap )
2003-12-11 04:52:23 +00:00
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. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return 0;
int iNum = 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
2003-12-11 04:52:23 +00:00
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. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return -1;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap )
2003-12-11 04:52:23 +00:00
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. */
2004-09-11 03:50:37 +00:00
if( index < 0 || index >= GetNumRows() )
2003-12-11 04:52:23 +00:00
return -1;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
TapNote tn = GetTapNoteX( t, index );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
2003-12-11 04:52:23 +00:00
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
// 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.
2004-09-21 07:53:39 +00:00
for( int 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;
2004-05-24 04:17:19 +00:00
// delete TapNotes under this HoldNote
2004-09-21 07:53:39 +00:00
for( int 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_ORIGINAL_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
2004-09-12 06:40:42 +00:00
for( unsigned i=0; i<MAX_NUM_ATTACKS; i++ )
2003-11-15 23:19:13 +00:00
{
if( m_AttackMap.find(i) == m_AttackMap.end() ) // this index is free to use
{
m_AttackMap[i] = attack;
TapNote tn;
tn.Set( TapNote::attack, TapNote::original, i );
SetTapNote( track, row, tn );
return;
}
2003-11-15 23:19:13 +00:00
}
// TODO: need to increase MAX_NUM_ATTACKS or handle "no more room" case
2003-11-15 23:19:13 +00:00
ASSERT(0);
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
{
// Add all used AttackNote index values to a map.
set<unsigned> setUsedIndices;
2003-11-15 08:51:47 +00:00
2004-09-11 03:50:37 +00:00
int num_rows = GetNumRows();
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-11-15 08:51:47 +00:00
{
2004-09-11 03:50:37 +00:00
for( int r=0; r<num_rows; r++ )
2003-11-15 08:51:47 +00:00
{
2003-11-15 23:19:13 +00:00
TapNote tn = GetTapNote(t, r);
if( tn.type == TapNote::attack )
setUsedIndices.insert( tn.attackIndex );
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
2004-05-24 04:17:19 +00:00
// TapNotes in use.
for( unsigned i=0; i<MAX_NUM_ATTACKS; i++ )
2003-11-15 23:19:13 +00:00
{
bool bInAttackMap = m_AttackMap.find(i) != m_AttackMap.end();
bool bActuallyUsed = setUsedIndices.find(i) != setUsedIndices.end();
2003-11-15 23:19:13 +00:00
if( bActuallyUsed && !bInAttackMap )
ASSERT(0); // something earlier than us didn't enforce consistency
2003-11-15 23:19:13 +00:00
if( bInAttackMap && !bActuallyUsed )
m_AttackMap.erase( i );
2003-11-15 23:19:13 +00:00
}
}
const Attack& NoteData::GetAttackAt( int track, int row )
{
TapNote tn = GetTapNote(track, row);
ASSERT( tn.type == TapNote::attack ); // don't call this if the TapNote here isn't an attack
map<unsigned,Attack>::iterator iter = m_AttackMap.find( tn.attackIndex );
ASSERT( iter != m_AttackMap.end() );
return iter->second;
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
2004-09-21 07:53:39 +00:00
for( int 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;
}
}
2004-09-21 07:53:39 +00:00
for( int 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
2004-09-21 07:53:39 +00:00
for( int 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
}
}
2004-09-21 07:53:39 +00:00
for( int 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
}
2004-05-24 04:26:54 +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 )
2004-09-11 03:50:37 +00:00
fEndBeat = GetNumBeats();
2003-12-11 04:52:23 +00:00
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 );
2004-09-11 03:50:37 +00:00
iEndIndex = min( iEndIndex, GetNumRows()-1 );
2003-01-02 09:44:09 +00:00
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); 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.type != TapNote::empty && tn.type != TapNote::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;
2004-09-11 03:50:37 +00:00
if(fEndBeat == -1) fEndBeat = GetNumBeats();
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 )
2004-09-11 03:50:37 +00:00
fEndBeat = GetNumBeats();
2003-12-11 04:52:23 +00:00
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 );
2004-09-11 03:50:37 +00:00
iEndIndex = min( iEndIndex, GetNumRows()-1 );
2003-11-26 04:21:59 +00:00
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-11-26 04:21:59 +00:00
{
for( int i=iStartIndex; i<=iEndIndex; i++ )
if( GetTapNoteX(t, i).type == TapNote::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;
2004-09-11 03:50:37 +00:00
if(fEndBeat == -1) fEndBeat = GetNumBeats();
2003-11-10 01:24:46 +00:00
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;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-16 07:58:37 +00:00
{
TapNote tn = GetTapNoteX(t, row);
switch( tn.type )
{
case TapNote::mine:
case TapNote::empty:
case TapNote::hold_tail:
continue; // skip these types - they don't count
}
2003-12-16 07:58:37 +00:00
++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 )
2004-09-11 03:50:37 +00:00
fEndBeat = GetNumBeats();
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 );
2004-09-11 03:50:37 +00:00
iEndIndex = min( iEndIndex, GetNumRows()-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 )
2004-09-11 03:50:37 +00:00
fEndBeat = GetNumBeats();
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 );
2004-09-11 03:50:37 +00:00
iEndIndex = min( iEndIndex, GetNumRows()-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;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2002-05-19 01:59:48 +00:00
{
2003-12-11 04:52:23 +00:00
TapNote tn = GetTapNoteX(t, i);
if( tn.type != TapNote::mine && tn.type != TapNote::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 )
2004-09-11 03:50:37 +00:00
fEndBeat = GetNumBeats();
2003-12-16 04:00:39 +00:00
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();
2004-09-25 07:59:56 +00:00
for( int col=0; col<GetNumTracks(); col++ ) // foreach column
2002-04-16 17:31:00 +00:00
{
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
{
if( GetTapNote(col,i).type != TapNote::hold_head ) // this is a HoldNote begin marker
continue;
SetTapNote(col, i, TAP_EMPTY); // clear the hold head marker
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. This should be a hold_tail if the
// data is in a consistent state, but doesn't have to be.
if( GetTapNote(col, j).type == TapNote::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; // done searching for the end of this hold
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_ORIGINAL_HOLD_HEAD );
SetTapNote( hn.iTrack, hn.iEndRow, TAP_ORIGINAL_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();
2004-09-25 07:59:56 +00:00
for( int col=0; col<GetNumTracks(); col++ ) // foreach column
2002-08-25 05:00:23 +00:00
{
for( int i=0; i<=rows; i++ ) // foreach TapNote element
2002-08-25 05:00:23 +00:00
{
if( GetTapNote(col, i).type == TapNote::hold ) // this is a HoldNote body
{
HoldNote hn( col, i, 0 );
// search for end of HoldNote
do {
SetTapNote(col, i, TAP_EMPTY);
i++;
} while( GetTapNote(col, i).type == TapNote::hold );
2002-10-25 04:59:12 +00:00
SetTapNote(col, i, TAP_EMPTY);
2002-08-25 05:00:23 +00:00
hn.iEndRow = i;
AddHoldNote( hn );
}
2002-08-25 05:00:23 +00:00
}
}
}
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_ORIGINAL_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 );
2004-09-25 07:59:56 +00:00
SetNumTracks( iNewNumTracks );
2002-04-16 17:31:00 +00:00
// copy tracks
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2002-04-16 17:31:00 +00:00
{
const int iOriginalTrack = iOriginalTrackToTakeFrom[t];
2004-09-25 07:59:56 +00:00
ASSERT_M( iOriginalTrack < Original.GetNumTracks(), ssprintf("from %i >= %i (to %i)",
iOriginalTrack, Original.GetNumTracks(), iOriginalTrackToTakeFrom[t]));
2002-12-28 16:07:19 +00:00
if( iOriginalTrack == -1 )
continue;
2004-05-24 04:26:54 +00:00
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
2004-05-24 04:26:54 +00:00
void NoteData::PadTapNotes(int rows)
{
2004-05-24 04:26:54 +00:00
int needed = rows - m_TapNotes[0].size() + 1;
2003-02-01 05:27:49 +00:00
if(needed < 0)
return;
needed += 100; /* optimization: give it a little more than it needs */
2004-09-25 07:59:56 +00:00
for(int track = 0; track < GetNumTracks(); ++track)
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;
2004-05-24 04:26:54 +00:00
m_TapNotes[dest] = m_TapNotes[src];
m_TapNotes[src].clear();
2002-11-02 21:04:00 +00:00
}
void NoteData::SetTapNote(int track, int row, TapNote t)
{
2004-09-25 07:59:56 +00:00
DEBUG_ASSERT( track>=0 && track<GetNumTracks() );
if(row < 0) return;
2002-12-13 01:23:26 +00:00
2004-05-24 04:26:54 +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 )
{
2004-09-25 07:59:56 +00:00
for(int track = 0; track < GetNumTracks(); ++track)
2004-05-24 04:26:54 +00:00
m_TapNotes[track].reserve( row );
2003-12-11 04:52:23 +00:00
}
2003-09-21 23:16:44 +00:00
void NoteData::EliminateAllButOneTap(int row)
{
if(row < 0) return;
2004-05-24 04:26:54 +00:00
PadTapNotes(row);
2003-09-21 23:16:44 +00:00
int track;
2004-09-25 07:59:56 +00:00
for(track = 0; track < GetNumTracks(); ++track)
2003-09-21 23:16:44 +00:00
{
if( m_TapNotes[track][row].type == TapNote::tap )
2003-09-21 23:16:44 +00:00
break;
}
track++;
2004-09-25 07:59:56 +00:00
for( ; track < GetNumTracks(); ++track)
2003-09-21 23:16:44 +00:00
{
if( m_TapNotes[track][row].type == TapNote::tap )
2004-05-24 04:26:54 +00:00
m_TapNotes[track][row] = TAP_EMPTY;
2003-09-21 23:16:44 +00:00
}
}
2003-11-07 05:17:41 +00:00
2004-05-15 03:00:43 +00:00
void NoteData::GetTracksHeldAtRow( int row, set<int>& addTo )
2003-11-07 05:17:41 +00:00
{
for( unsigned i=0; i<m_HoldNotes.size(); i++ )
{
const HoldNote& hn = m_HoldNotes[i];
2003-12-16 04:00:39 +00:00
if( hn.RowIsInRange(row) )
2004-05-15 03:00:43 +00:00
addTo.insert( hn.iTrack );
2003-11-07 05:17:41 +00:00
}
2003-11-07 09:27:28 +00:00
}
int NoteData::GetNumTracksHeldAtRow( int row )
{
2004-05-15 03:00:43 +00:00
static set<int> viTracks;
2003-11-07 09:27:28 +00:00
viTracks.clear();
GetTracksHeldAtRow( row, viTracks );
return viTracks.size();
2003-11-10 01:34:55 +00:00
}
2004-05-31 22:42:12 +00:00
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/