Files
itgmania212121/stepmania/src/NoteData.cpp
T

862 lines
22 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();
2005-03-08 21:18:00 +00:00
m_TapNotes = vector<TrackMap>(); // ensure that the memory is freed
2002-04-16 17:31:00 +00:00
}
2002-05-19 01:59:48 +00:00
NoteData::~NoteData()
{
}
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:16:38 +00:00
}
2005-01-25 05:02:35 +00:00
/* Clear [rowBegin,rowEnd). */
void NoteData::ClearRangeForTrack( int rowBegin, int rowEnd, int iTrack )
2002-04-16 17:31:00 +00:00
{
/* Optimization: if the range encloses everything, just clear the whole maps. */
if( rowBegin == 0 && rowEnd == MAX_NOTE_ROW )
{
m_TapNotes[iTrack].clear();
2005-01-25 05:02:35 +00:00
return;
}
2005-01-25 05:02:35 +00:00
iterator begin, end;
GetTapNoteRangeInclusive( iTrack, rowBegin, rowEnd, begin, end );
if( begin != end && begin->first < rowBegin && begin->first + begin->second.iDuration > rowEnd )
{
2005-01-25 05:02:35 +00:00
/* A hold note overlaps the whole range. Truncate it, and add the remainder to
* the end. */
TapNote tn1 = begin->second;
TapNote tn2 = tn1;
2005-01-25 05:02:35 +00:00
int iEndRow = begin->first + tn1.iDuration;
int iRow = begin->first;
2005-01-25 05:02:35 +00:00
tn1.iDuration = rowBegin - iRow;
tn2.iDuration = iEndRow - rowEnd;
2005-01-25 05:02:35 +00:00
SetTapNote( iTrack, iRow, tn1 );
SetTapNote( iTrack, rowEnd, tn2 );
2005-01-25 05:02:35 +00:00
/* We may have invalidated our iterators. */
GetTapNoteRangeInclusive( iTrack, rowBegin, rowEnd, begin, end );
}
else if( begin != end && begin->first < rowBegin )
{
/* A hold note overlaps the beginning of the range. Truncate it. */
TapNote &tn1 = begin->second;
int iRow = begin->first;
tn1.iDuration = rowBegin - iRow;
++begin;
}
if( begin != end )
{
iterator prev = end;
--prev;
TapNote tn = begin->second;
int iRow = prev->first;
if( tn.type == TapNote::hold_head && iRow + tn.iDuration > rowEnd )
{
2005-01-25 05:02:35 +00:00
/* A hold note overlaps the end of the range. Separate it. */
SetTapNote( iTrack, iRow, TAP_EMPTY );
int iAdd = rowEnd - iRow;
tn.iDuration -= iAdd;
iRow += iAdd;
SetTapNote( iTrack, iRow, tn );
end = prev;
}
2005-01-25 05:02:35 +00:00
/* We may have invalidated our iterators. */
GetTapNoteRangeInclusive( iTrack, rowBegin, rowEnd, begin, end );
}
2005-01-25 05:02:35 +00:00
while( begin != end )
{
iterator next = begin;
++next;
RemoveTapNote( iTrack, begin );
begin = next;
}
}
void NoteData::ClearRange( int rowBegin, int rowEnd )
{
for( int t=0; t < GetNumTracks(); ++t )
ClearRangeForTrack( rowBegin, rowEnd, t );
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-10-02 05:08:59 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2004-05-24 04:26:54 +00:00
m_TapNotes[t].clear();
2002-12-14 20:30:49 +00:00
}
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.) */
2004-10-24 10:20:24 +00:00
void NoteData::CopyRange( const NoteData& from, int rowFromBegin, int rowFromEnd, int rowToBegin )
2002-04-16 17:31:00 +00:00
{
2004-10-23 17:43:49 +00:00
ASSERT( from.GetNumTracks() == GetNumTracks() );
2002-04-16 17:31:00 +00:00
2005-01-25 05:02:35 +00:00
if( rowFromBegin > rowFromEnd )
return; /* empty range */
const int rowToEnd = (rowFromEnd-rowFromBegin) + rowToBegin;
const int iMoveBy = rowToBegin-rowFromBegin;
2002-04-16 17:31:00 +00:00
/* Clear the region. */
ClearRange( rowToBegin, rowToEnd );
for( int t=0; t<GetNumTracks(); t++ )
2002-04-16 17:31:00 +00:00
{
2005-01-25 05:02:35 +00:00
const_iterator begin, end;
from.GetTapNoteRangeInclusive( t, rowFromBegin, rowFromEnd, begin, end );
for( ; begin != end; ++begin )
2003-11-17 03:38:24 +00:00
{
2005-01-25 05:02:35 +00:00
TapNote head = begin->second;
if( head.type == TapNote::empty )
continue;
2005-01-25 05:02:35 +00:00
if( head.type == TapNote::hold_head )
{
int iStartRow = begin->first + iMoveBy;
int iEndRow = iStartRow + head.iDuration;
2005-01-25 05:02:35 +00:00
iStartRow = clamp( iStartRow, rowToBegin, rowToEnd );
iEndRow = clamp( iEndRow, rowToBegin, rowToEnd );
2005-01-25 05:02:35 +00:00
this->AddHoldNote( t, iStartRow, iEndRow, head );
}
else
{
int iTo = begin->first + iMoveBy;
if( iTo >= rowToBegin && iTo <= rowToEnd )
this->SetTapNote( t, iTo, head );
}
}
}
2002-04-16 17:31:00 +00:00
}
2004-10-23 17:43:49 +00:00
void NoteData::CopyAll( const NoteData& from )
2002-12-13 01:23:26 +00:00
{
2005-01-25 05:02:35 +00:00
SetNumTracks( from.GetNumTracks() );
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-10-23 17:43:49 +00:00
m_TapNotes[c] = from.m_TapNotes[c];
2002-12-13 01:23:26 +00:00
}
2004-10-24 10:20:24 +00:00
bool NoteData::IsRowEmpty( int row ) const
2003-12-11 04:52:23 +00:00
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2004-10-25 03:16:40 +00:00
if( GetTapNote(t, row).type != TapNote::empty )
2003-12-11 04:52:23 +00:00
return false;
return true;
}
2004-10-24 10:20:24 +00:00
bool NoteData::IsRangeEmpty( int track, int rowBegin, int rowEnd ) const
{
2004-09-25 07:59:56 +00:00
ASSERT( track < GetNumTracks() );
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, track, r, rowBegin, rowEnd )
2004-10-25 03:16:40 +00:00
if( GetTapNote(track,r).type != TapNote::empty )
return false;
return true;
}
2004-10-24 10:20:24 +00:00
int NoteData::GetNumTapNonEmptyTracks( int row ) const
2003-12-11 04:52:23 +00:00
{
int iNum = 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2004-10-24 10:20:24 +00:00
if( GetTapNote(t, row).type != TapNote::empty )
2003-12-11 04:52:23 +00:00
iNum++;
return iNum;
}
2004-10-24 10:20:24 +00:00
void NoteData::GetTapNonEmptyTracks( int row, set<int>& addTo ) const
2004-05-15 03:00:43 +00:00
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2004-10-24 10:20:24 +00:00
if( GetTapNote(t, row).type != TapNote::empty )
2004-05-15 03:00:43 +00:00
addTo.insert(t);
}
2004-10-24 10:20:24 +00:00
bool NoteData::GetTapFirstNonEmptyTrack( int row, int &iNonEmptyTrackOut ) const
2003-12-11 04:52:23 +00:00
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2004-10-24 10:20:24 +00:00
{
2004-10-25 03:16:40 +00:00
if( GetTapNote( t, row ).type != TapNote::empty )
2004-10-24 10:20:24 +00:00
{
iNonEmptyTrackOut = t;
return true;
}
}
return false;
}
bool NoteData::GetTapFirstEmptyTrack( int row, int &iEmptyTrackOut ) const
{
for( int t=0; t<GetNumTracks(); t++ )
{
2004-10-25 03:16:40 +00:00
if( GetTapNote( t, row ).type == TapNote::empty )
2004-10-24 10:20:24 +00:00
{
iEmptyTrackOut = t;
return true;
}
}
return false;
}
bool NoteData::GetTapLastEmptyTrack( int row, int &iEmptyTrackOut ) const
{
for( int t=GetNumTracks()-1; t>=0; t-- )
{
2004-10-25 03:16:40 +00:00
if( GetTapNote( t, row ).type == TapNote::empty )
2004-10-24 10:20:24 +00:00
{
iEmptyTrackOut = t;
return true;
}
}
return false;
2003-12-11 04:52:23 +00:00
}
2004-10-24 10:20:24 +00:00
int NoteData::GetNumTracksWithTap( int row ) const
2003-12-11 04:52:23 +00:00
{
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
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote( t, row );
if( tn.type == TapNote::tap )
2003-12-11 04:52:23 +00:00
iNum++;
}
return iNum;
}
2004-10-24 10:20:24 +00:00
int NoteData::GetNumTracksWithTapOrHoldHead( int row ) const
2003-12-11 04:52:23 +00:00
{
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
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote( t, row );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
2003-12-11 04:52:23 +00:00
iNum++;
}
return iNum;
}
2004-10-24 10:20:24 +00:00
int NoteData::GetFirstTrackWithTap( int row ) const
2003-12-11 04:52:23 +00:00
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote( t, row );
if( tn.type == TapNote::tap )
2003-12-11 04:52:23 +00:00
return t;
}
return -1;
}
2004-10-24 10:20:24 +00:00
int NoteData::GetFirstTrackWithTapOrHoldHead( int row ) const
2003-12-11 04:52:23 +00:00
{
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
2003-12-11 04:52:23 +00:00
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote( t, row );
if( tn.type == TapNote::tap || tn.type == TapNote::hold_head )
2003-12-11 04:52:23 +00:00
return t;
}
return -1;
}
2005-01-25 05:02:35 +00:00
void NoteData::AddHoldNote( int iTrack, int iStartRow, int iEndRow, TapNote tn )
2002-04-16 17:31:00 +00:00
{
2005-01-25 05:02:35 +00:00
ASSERT( iStartRow>=0 && iEndRow>=0 );
ASSERT( iEndRow >= iStartRow );
/* Include adjacent (non-overlapping) hold notes, since we need to merge with them. */
iterator begin, end;
GetTapNoteRangeInclusive( iTrack, iStartRow, iEndRow, begin, end, true );
2005-01-25 05:02:35 +00:00
/* Look for other hold notes that overlap and merge them into add. */
for( iterator it = begin; it != end; ++it )
2002-04-16 17:31:00 +00:00
{
int iOtherRow = it->first;
const TapNote &tnOther = it->second;
if( tnOther.type == TapNote::hold_head )
2002-04-16 17:31:00 +00:00
{
iStartRow = min( iStartRow, iOtherRow );
iEndRow = max( iEndRow, iOtherRow + tnOther.iDuration );
2002-04-16 17:31:00 +00:00
}
}
tn.iDuration = iEndRow - iStartRow;
2005-01-25 05:02:35 +00:00
/* Remove everything in the range. */
while( begin != end )
{
iterator next = begin;
++next;
2005-01-25 05:02:35 +00:00
RemoveTapNote( iTrack, begin );
begin = next;
}
2002-04-16 17:31:00 +00:00
2005-01-25 05:02:35 +00:00
/* Additionally, if there's a tap note lying at the end of our range, remove it,
* too. */
SetTapNote( iTrack, iEndRow, TAP_EMPTY );
2002-06-14 22:25:22 +00:00
2005-01-25 05:02:35 +00:00
// add a tap note at the start of this hold
SetTapNote( iTrack, iStartRow, tn );
2002-04-16 17:31:00 +00:00
}
2005-01-25 05:02:35 +00:00
/* Return true if a hold note lies on or adjacent to the given spot. */
bool NoteData::IsHoldNoteAtBeat( int iTrack, int iRow, int *pHeadRow ) const
2003-12-18 02:34:59 +00:00
{
int iDummy;
if( pHeadRow == NULL )
pHeadRow = &iDummy;
bool bFoundHead = false;
2005-01-25 05:02:35 +00:00
/* Starting at iRow, search upwards. If we find a TapNote::hold_head, we're within
* a hold. If we find a tap, mine or attack, we're not--those never lie within hold
* notes. Ignore autoKeysound. */
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE_REVERSE( *this, iTrack, r, 0, iRow )
2003-12-18 02:34:59 +00:00
{
2005-01-25 05:02:35 +00:00
const TapNote &tn = GetTapNote( iTrack, r );
switch( tn.type )
2005-01-22 20:22:12 +00:00
{
2005-01-25 05:02:35 +00:00
case TapNote::hold_head:
// if( tn.iDuration + r <= iRow )
if( tn.iDuration + r < iRow )
return false;
2005-01-25 05:02:35 +00:00
*pHeadRow = r;
return true;
2005-01-25 05:02:35 +00:00
case TapNote::tap:
case TapNote::mine:
case TapNote::attack:
return false;
2005-01-25 05:02:35 +00:00
case TapNote::empty:
case TapNote::autoKeysound:
/* ignore */
continue;
default:
2005-02-07 19:27:49 +00:00
FAIL_M( ssprintf("%i", tn.type) );
}
2005-01-25 05:02:35 +00:00
if( bFoundHead )
break;
}
2005-01-25 05:02:35 +00:00
return bFoundHead;
2003-12-18 02:34:59 +00:00
}
bool NoteData::IsEmpty() const
{
for( int t=0; t < GetNumTracks(); t++ )
{
int iRow = -1;
if( !GetNextTapNoteRowForTrack( t, iRow ) )
continue;
return false;
}
return true;
}
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-10-02 05:08:59 +00:00
for( int t=0; t < GetNumTracks(); t++ )
2002-07-11 19:02:26 +00:00
{
int iRow = -1;
if( !GetNextTapNoteRowForTrack( t, iRow ) )
continue;
if( iEarliestRowFoundSoFar == -1 )
iEarliestRowFoundSoFar = iRow;
else
iEarliestRowFoundSoFar = min( iEarliestRowFoundSoFar, iRow );
2002-07-11 19:02:26 +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
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-10-02 05:08:59 +00:00
for( int t=0; t < GetNumTracks(); t++ )
2002-04-16 17:31:00 +00:00
{
2005-01-22 19:18:42 +00:00
int iRow = MAX_NOTE_ROW;
if( !GetPrevTapNoteRowForTrack( t, iRow ) )
continue;
2002-04-16 17:31:00 +00:00
2005-01-25 05:02:35 +00:00
/* XXX: We might have a hold note near the end with autoplay sounds
* after it. Do something else with autoplay sounds ... */
const TapNote &tn = GetTapNote( t, iRow );
if( tn.type == TapNote::hold_head )
iRow += tn.iDuration;
iOldestRowFoundSoFar = max( iOldestRowFoundSoFar, iRow );
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;
}
int NoteData::GetNumTapNotes( int iStartIndex, int iEndIndex ) const
2002-12-14 20:34:38 +00:00
{
int iNumNotes = 0;
2004-09-28 02:14:56 +00:00
for( int t=0; t<GetNumTracks(); t++ )
{
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, r, iStartIndex, iEndIndex )
2002-12-14 20:34:38 +00:00
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote(t, r);
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
}
int NoteData::GetNumRowsWithTap( int iStartIndex, int iEndIndex ) const
{
int iNumNotes = 0;
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, r, iStartIndex, iEndIndex )
if( IsThereATapAtRow(r) )
iNumNotes++;
return iNumNotes;
}
int NoteData::GetNumMines( int iStartIndex, int iEndIndex ) const
2003-11-26 04:21:59 +00:00
{
int iNumMines = 0;
2003-12-11 04:52:23 +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
{
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, r, iStartIndex, iEndIndex )
2004-10-25 03:16:40 +00:00
if( GetTapNote(t, r).type == TapNote::mine )
2003-11-26 04:21:59 +00:00
iNumMines++;
}
return iNumMines;
}
int NoteData::GetNumRowsWithTapOrHoldHead( int iStartIndex, int iEndIndex ) const
2003-11-10 01:24:46 +00:00
{
int iNumNotes = 0;
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, r, iStartIndex, iEndIndex )
if( IsThereATapOrHoldHeadAtRow(r) )
2003-11-10 01:24:46 +00:00
iNumNotes++;
return iNumNotes;
}
2005-03-20 20:15:41 +00:00
bool NoteData::RowNeedsAtLeastSimultaneousPresses( int iMinSimultaneousPresses, const int row ) const
2003-12-16 07:58:37 +00:00
{
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
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote(t, row);
switch( tn.type )
{
case TapNote::mine:
case TapNote::empty:
continue; // skip these types - they don't count
}
2003-12-16 07:58:37 +00:00
++iNumNotesThisIndex;
}
2005-03-23 10:37:36 +00:00
/* We must have at least one tap or hold head at this row to count it. */
2003-12-16 07:58:37 +00:00
if( !iNumNotesThisIndex )
return false;
2005-03-20 20:15:41 +00:00
if( iNumNotesThisIndex < iMinSimultaneousPresses )
2003-12-16 07:58:37 +00:00
{
2005-01-25 05:02:35 +00:00
/* We have at least one, but not enough. Count holds. Do count adjacent holds. */
for( int t=0; t<GetNumTracks(); ++t )
2003-12-16 07:58:37 +00:00
{
2005-01-25 05:02:35 +00:00
if( IsHoldNoteAtBeat(t, row) )
2003-12-16 07:58:37 +00:00
++iNumNotesThisIndex;
}
}
2005-03-20 20:15:41 +00:00
return iNumNotesThisIndex >= iMinSimultaneousPresses;
2003-12-16 07:58:37 +00:00
}
2005-03-20 20:15:41 +00:00
int NoteData::GetNumRowsWithSimultaneousPresses( int iMinSimultaneousPresses, int iStartIndex, int iEndIndex ) const
2003-11-26 04:31:29 +00:00
{
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
int iNum = 0;
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, r, iStartIndex, iEndIndex )
2003-11-26 04:31:29 +00:00
{
2005-03-20 20:15:41 +00:00
if( !RowNeedsAtLeastSimultaneousPresses(iMinSimultaneousPresses,r) )
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;
}
2005-03-20 20:15:41 +00:00
int NoteData::GetNumRowsWithSimultaneousTaps( int iMinTaps, int iStartIndex, int iEndIndex ) const
2002-05-19 01:59:48 +00:00
{
2003-11-26 04:21:59 +00:00
int iNum = 0;
2004-10-24 10:20:24 +00:00
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, r, iStartIndex, iEndIndex )
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
{
2004-10-25 03:16:40 +00:00
const TapNote &tn = GetTapNote(t, r);
if( tn.type != TapNote::mine && tn.type != TapNote::empty ) // mines don't count
2002-05-19 01:59:48 +00:00
iNumNotesThisIndex++;
}
2004-10-24 10:20:24 +00:00
if( iNumNotesThisIndex >= iMinTaps )
2003-11-26 04:21:59 +00:00
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
}
int NoteData::GetNumHoldNotes( int iStartIndex, int iEndIndex ) const
2002-05-19 01:59:48 +00:00
{
2003-12-16 04:00:39 +00:00
int iNumHolds = 0;
2005-01-25 05:02:35 +00:00
for( int t=0; t<GetNumTracks(); ++t )
2002-04-16 17:31:00 +00:00
{
2005-01-25 05:02:35 +00:00
const_iterator begin, end;
GetTapNoteRangeExclusive( t, iStartIndex, iEndIndex, begin, end );
for( ; begin != end; ++begin )
2002-04-16 17:31:00 +00:00
{
2005-05-09 06:15:59 +00:00
if( begin->second.type != TapNote::hold_head ||
begin->second.subType != TapNote::hold_head_hold )
2005-01-25 05:02:35 +00:00
continue;
iNumHolds++;
2002-04-16 17:31:00 +00:00
}
}
2005-01-25 05:02:35 +00:00
return iNumHolds;
}
2005-04-25 09:33:58 +00:00
int NoteData::GetNumRolls( int iStartIndex, int iEndIndex ) const
{
int iNumRolls = 0;
for( int t=0; t<GetNumTracks(); ++t )
{
const_iterator begin, end;
GetTapNoteRangeExclusive( t, iStartIndex, iEndIndex, begin, end );
for( ; begin != end; ++begin )
{
if( begin->second.type != TapNote::hold_head ||
begin->second.subType != TapNote::hold_head_roll )
continue;
iNumRolls++;
}
}
return iNumRolls;
}
// -1 for iOriginalTracksToTakeFrom means no track
2005-01-22 20:22:12 +00:00
void NoteData::LoadTransformed( const NoteData& in, 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
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];
2005-01-22 20:22:12 +00:00
ASSERT_M( iOriginalTrack < in.GetNumTracks(), ssprintf("from %i >= %i (to %i)",
iOriginalTrack, in.GetNumTracks(), iOriginalTrackToTakeFrom[t]));
2002-12-28 16:07:19 +00:00
if( iOriginalTrack == -1 )
continue;
2005-01-25 05:02:35 +00:00
m_TapNotes[t] = in.m_TapNotes[iOriginalTrack];
2005-01-23 05:15:18 +00:00
}
2002-04-16 17:31:00 +00:00
}
2002-06-24 22:04:31 +00:00
2004-10-24 10:20:24 +00:00
void NoteData::MoveTapNoteTrack( int dest, int src )
2002-11-02 21:04:00 +00:00
{
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
}
2004-10-24 10:20:24 +00:00
void NoteData::SetTapNote( int track, int row, const 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
// There's no point in inserting empty notes into the map.
// Any blank space in the map is defined to be empty.
// If we're trying to insert an empty at a spot where
// another note already exists, then we're really deleting
// from the map.
if( t == TAP_EMPTY )
{
TrackMap &trackMap = m_TapNotes[track];
// remove the element at this position (if any). This will return either 0 or 1.
2004-10-02 05:08:59 +00:00
trackMap.erase( row );
}
else
{
m_TapNotes[track][row] = t;
}
}
2003-09-21 23:16:44 +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
{
2005-01-25 05:02:35 +00:00
for( int t=0; t<GetNumTracks(); ++t )
if( IsHoldNoteAtBeat( t, row ) )
addTo.insert( t );
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
bool NoteData::GetNextTapNoteRowForTrack( int track, int &rowInOut ) const
{
const TrackMap &mapTrack = m_TapNotes[track];
// lower_bound and upper_bound have the same effect here because duplicate
// keys aren't allowed.
2004-10-24 23:49:33 +00:00
//
// lower_bound "finds the first element whose key is not less than k" (>=);
// upper_bound "finds the first element whose key greater than k". They don't
// have the same effect, but lower_bound(row+1) should equal upper_bound(row). -glenn
TrackMap::const_iterator iter = mapTrack.lower_bound( rowInOut+1 ); // "find the first note for which row+1 < key == false"
2004-10-24 23:49:33 +00:00
if( iter == mapTrack.end() )
return false;
2004-10-24 23:49:33 +00:00
ASSERT( iter->first > rowInOut );
rowInOut = iter->first;
return true;
}
2004-10-25 00:25:49 +00:00
bool NoteData::GetPrevTapNoteRowForTrack( int track, int &rowInOut ) const
{
const TrackMap &mapTrack = m_TapNotes[track];
/* Find the first note >= rowInOut. */
TrackMap::const_iterator iter = mapTrack.lower_bound( rowInOut );
/* If we're at the beginning, we can't move back any more. */
if( iter == mapTrack.begin() )
return false;
/* Move back by one. */
--iter;
ASSERT( iter->first < rowInOut );
rowInOut = iter->first;
return true;
}
2005-01-25 05:02:35 +00:00
/* Return an iterator range for [rowBegin,rowEnd). This can be used to efficiently
* iterate trackwise over a range of notes. It's like FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE,
* except it only requires two map searches (iterating is constant time), but the iterators will
* become invalid if the notes they represent disappear, so you need to pay attention to
* how you modify the data. */
void NoteData::GetTapNoteRange( int iTrack, int iStartRow, int iEndRow, TrackMap::iterator &begin, TrackMap::iterator &end )
2005-01-22 03:11:29 +00:00
{
ASSERT_M( iTrack < GetNumTracks(), ssprintf("%i,%i", iTrack, GetNumTracks()) );
2005-01-25 05:02:35 +00:00
TrackMap &mapTrack = m_TapNotes[iTrack];
if( iStartRow > iEndRow )
{
begin = end = mapTrack.end();
return;
}
2005-01-25 19:36:38 +00:00
if( iStartRow <= 0 )
2005-01-25 05:02:35 +00:00
begin = mapTrack.begin(); /* optimization */
2005-01-25 19:36:38 +00:00
else if( iStartRow >= MAX_NOTE_ROW )
2005-01-25 05:02:35 +00:00
begin = mapTrack.end(); /* optimization */
else
begin = mapTrack.lower_bound( iStartRow );
2005-01-22 03:11:29 +00:00
2005-01-25 19:36:38 +00:00
if( iEndRow <= 0 )
2005-01-25 05:02:35 +00:00
end = mapTrack.begin(); /* optimization */
2005-01-25 19:36:38 +00:00
else if( iEndRow >= MAX_NOTE_ROW )
2005-01-25 05:02:35 +00:00
end = mapTrack.end(); /* optimization */
else
end = mapTrack.lower_bound( iEndRow );
2005-01-22 03:11:29 +00:00
}
2005-01-25 05:02:35 +00:00
/* Include hold notes that overlap the edges. If a hold note completely surrounds the given
* range, included it, too. If bIncludeAdjacent is true, also include hold notes adjacent to,
* but not overlapping, the edge. */
void NoteData::GetTapNoteRangeInclusive( int iTrack, int iStartRow, int iEndRow, iterator &begin, iterator &end, bool bIncludeAdjacent )
{
GetTapNoteRange( iTrack, iStartRow, iEndRow, begin, end );
if( begin != this->begin(iTrack) )
{
iterator prev = Decrement(begin);
const TapNote &tn = prev->second;
if( tn.type == TapNote::hold_head )
{
int iHoldStartRow = prev->first;
int iHoldEndRow = iHoldStartRow + tn.iDuration;
2005-01-25 19:36:38 +00:00
if( bIncludeAdjacent )
++iHoldEndRow;
if( iHoldEndRow > iStartRow )
2005-01-25 05:02:35 +00:00
{
/* The previous note is a hold. */
begin = prev;
}
}
}
if( bIncludeAdjacent && end != this->end(iTrack) )
{
/* Include the next note if it's a hold and starts on iEndRow. */
const TapNote &tn = end->second;
int iHoldStartRow = end->first;
if( tn.type == TapNote::hold_head && iHoldStartRow == iEndRow )
++end;
}
}
void NoteData::GetTapNoteRangeExclusive( int iTrack, int iStartRow, int iEndRow, iterator &begin, iterator &end )
{
GetTapNoteRange( iTrack, iStartRow, iEndRow, begin, end );
/* If end-1 is a hold_head, and extends beyond iEndRow, exclude it. */
if( begin != end && end != this->begin(iTrack) )
{
iterator prev = end;
--prev;
if( prev->second.type == TapNote::hold_head )
{
int iStartRow = prev->first;
const TapNote &tn = prev->second;
if( iStartRow + tn.iDuration >= iEndRow )
end = prev;
}
}
}
void NoteData::GetTapNoteRange( int iTrack, int iStartRow, int iEndRow, TrackMap::const_iterator &begin, TrackMap::const_iterator &end ) const
{
TrackMap::iterator const_begin, const_end;
const_cast<NoteData *>(this)->GetTapNoteRange( iTrack, iStartRow, iEndRow, const_begin, const_end );
begin = const_begin;
end = const_end;
}
void NoteData::GetTapNoteRangeInclusive( int iTrack, int iStartRow, int iEndRow, TrackMap::const_iterator &begin, TrackMap::const_iterator &end, bool bIncludeAdjacent ) const
{
TrackMap::iterator const_begin, const_end;
const_cast<NoteData *>(this)->GetTapNoteRangeInclusive( iTrack, iStartRow, iEndRow, const_begin, const_end, bIncludeAdjacent );
begin = const_begin;
end = const_end;
}
void NoteData::GetTapNoteRangeExclusive( int iTrack, int iStartRow, int iEndRow, TrackMap::const_iterator &begin, TrackMap::const_iterator &end ) const
{
TrackMap::iterator const_begin, const_end;
const_cast<NoteData *>(this)->GetTapNoteRange( iTrack, iStartRow, iEndRow, const_begin, const_end );
begin = const_begin;
end = const_end;
}
bool NoteData::GetNextTapNoteRowForAllTracks( int &rowInOut ) const
{
2005-01-22 19:18:42 +00:00
int iClosestNextRow = MAX_NOTE_ROW;
bool bAnyHaveNextNote = false;
for( int t=0; t<GetNumTracks(); t++ )
{
int iNewRowThisTrack = rowInOut;
if( GetNextTapNoteRowForTrack( t, iNewRowThisTrack ) )
{
bAnyHaveNextNote = true;
2005-01-22 19:18:42 +00:00
ASSERT( iNewRowThisTrack < MAX_NOTE_ROW );
iClosestNextRow = min( iClosestNextRow, iNewRowThisTrack );
}
}
if( bAnyHaveNextNote )
{
rowInOut = iClosestNextRow;
return true;
}
else
{
return false;
}
}
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.
*/