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"
|
2003-10-04 04:14:30 +00:00
|
|
|
#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-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-01-01 22:19:02 +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.
|
2004-01-01 22:19:02 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-24 00:17:15 +00:00
|
|
|
/* Clear [rowBegin,rowEnd]; that is, including rowEnd. */
|
2005-01-23 05:31:55 +00:00
|
|
|
void NoteData::ClearRangeForTrack( int rowBegin, int rowEnd, int iTrack )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2005-01-23 05:31:55 +00:00
|
|
|
/* Optimization: if the range encloses everything, just clear the whole maps. */
|
|
|
|
|
if( rowBegin == 0 && rowEnd == MAX_NOTE_ROW )
|
|
|
|
|
{
|
|
|
|
|
m_TapNotes[iTrack].clear();
|
|
|
|
|
|
|
|
|
|
for( int i = GetNumHoldNotes()-1; i >= 0; --i )
|
|
|
|
|
{
|
|
|
|
|
HoldNote hn = GetHoldNote(i);
|
|
|
|
|
if( hn.iTrack != iTrack )
|
|
|
|
|
continue;
|
|
|
|
|
this->RemoveHoldNote( i );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-23 04:57:43 +00:00
|
|
|
/* Crop or split hold notes overlapping the range. */
|
|
|
|
|
for( int i = GetNumHoldNotes()-1; i >= 0; --i ) // for each HoldNote
|
|
|
|
|
{
|
|
|
|
|
HoldNote hn = GetHoldNote(i);
|
2005-01-23 05:31:55 +00:00
|
|
|
if( hn.iTrack != iTrack )
|
|
|
|
|
continue;
|
|
|
|
|
|
2005-01-23 04:57:43 +00:00
|
|
|
if( !hn.RangeOverlaps(rowBegin, rowEnd) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
this->RemoveHoldNote( i );
|
|
|
|
|
|
|
|
|
|
/* If the range encloses the hold note completely, just delete it. */
|
|
|
|
|
if( hn.ContainedByRange(rowBegin, rowEnd) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if( hn.RangeInside(rowBegin, rowEnd) )
|
|
|
|
|
{
|
|
|
|
|
/* The hold note encloses the range, so we need to split the hold note. */
|
|
|
|
|
HoldNote hnLater(hn);
|
|
|
|
|
hn.iEndRow = rowBegin;
|
|
|
|
|
hnLater.iStartRow = rowEnd;
|
|
|
|
|
this->AddHoldNote( hn );
|
|
|
|
|
this->AddHoldNote( hnLater );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( hn.iStartRow < rowBegin )
|
|
|
|
|
hn.iEndRow = min( hn.iEndRow, rowBegin );
|
|
|
|
|
else
|
|
|
|
|
hn.iStartRow = max( hn.iStartRow, rowEnd );
|
|
|
|
|
this->AddHoldNote( hn );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clear other notes in the region. */
|
2005-01-23 05:31:55 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, iTrack, r, rowBegin, rowEnd )
|
|
|
|
|
SetTapNote( iTrack, r, TAP_EMPTY );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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.) */
|
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-23 04:57:43 +00:00
|
|
|
int rowToEnd = (rowFromEnd-rowFromBegin) + rowToBegin;
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2005-01-23 04:57:43 +00:00
|
|
|
/* Clear the region. */
|
|
|
|
|
ClearRange( rowToBegin, rowToEnd );
|
|
|
|
|
|
|
|
|
|
/* Copy everything except for hold notes. */
|
2004-09-29 06:43:57 +00:00
|
|
|
for( int t=0; t<GetNumTracks(); t++ )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2005-01-23 04:57:43 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( from, t, iFrom, rowFromBegin, rowFromEnd )
|
2003-11-17 03:38:24 +00:00
|
|
|
{
|
2005-01-23 04:57:43 +00:00
|
|
|
const TapNote &tn = from.GetTapNote( t, iFrom );
|
|
|
|
|
switch( tn.type )
|
|
|
|
|
{
|
|
|
|
|
case TapNote::empty:
|
|
|
|
|
case TapNote::hold_tail:
|
|
|
|
|
case TapNote::hold_head:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-24 10:20:24 +00:00
|
|
|
int iTo = rowToBegin + iFrom - rowFromBegin;
|
2005-01-23 04:57:43 +00:00
|
|
|
this->SetTapNote( t, iTo, tn );
|
2003-11-17 03:38:24 +00:00
|
|
|
}
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-23 04:57:43 +00:00
|
|
|
/* Copy hold notes. */
|
|
|
|
|
for( int i=0; i<from.GetNumHoldNotes(); i++ ) // for each HoldNote
|
|
|
|
|
{
|
|
|
|
|
HoldNote hn = from.GetHoldNote(i);
|
|
|
|
|
|
|
|
|
|
if( !hn.RangeOverlaps(rowFromBegin, rowFromEnd) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Move the hold note. */
|
|
|
|
|
int iMoveBy = rowToBegin-rowFromBegin;
|
|
|
|
|
hn.iStartRow += iMoveBy;
|
|
|
|
|
hn.iEndRow += iMoveBy;
|
|
|
|
|
|
|
|
|
|
/* Crop the hold note to the region. */
|
|
|
|
|
hn.iStartRow = max( hn.iStartRow, rowToBegin );
|
|
|
|
|
hn.iEndRow = min( hn.iEndRow, rowToEnd );
|
|
|
|
|
|
|
|
|
|
/* The beginning of the hold might match up to the end of an existing hold, the end
|
|
|
|
|
* may match with the beginning, or both. */
|
|
|
|
|
int iEarlierHoldNote = -1, iLaterHoldNote = -1;
|
|
|
|
|
for( int j=0; j<this->GetNumHoldNotes(); ++j ) // for each HoldNote
|
|
|
|
|
{
|
|
|
|
|
const HoldNote &hn2 = this->GetHoldNote(j);
|
|
|
|
|
if( hn2.iEndRow == hn.iStartRow )
|
|
|
|
|
iEarlierHoldNote = j;
|
|
|
|
|
if( hn2.iStartRow == hn.iEndRow )
|
|
|
|
|
iLaterHoldNote = j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( iEarlierHoldNote != -1 && iLaterHoldNote != -1 )
|
|
|
|
|
{
|
|
|
|
|
HoldNote &hnEarlier = this->GetHoldNote( iEarlierHoldNote );
|
|
|
|
|
const HoldNote &hnLater = this->GetHoldNote( iLaterHoldNote );
|
|
|
|
|
hnEarlier.iEndRow = hnLater.iEndRow;
|
|
|
|
|
|
|
|
|
|
this->RemoveHoldNote( iLaterHoldNote );
|
|
|
|
|
}
|
|
|
|
|
else if( iEarlierHoldNote == -1 && iLaterHoldNote == -1 )
|
|
|
|
|
AddHoldNote( hn );
|
|
|
|
|
else if( iEarlierHoldNote != -1 )
|
|
|
|
|
{
|
|
|
|
|
HoldNote &hn2 = this->GetHoldNote(iEarlierHoldNote);
|
|
|
|
|
hn2.iEndRow = hn.iEndRow;
|
|
|
|
|
}
|
|
|
|
|
else if( iLaterHoldNote != -1 )
|
|
|
|
|
{
|
|
|
|
|
HoldNote &hn2 = this->GetHoldNote(iLaterHoldNote);
|
|
|
|
|
hn2.iStartRow = hn.iStartRow;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
FAIL_M(ssprintf("%i,%i", iEarlierHoldNote, iLaterHoldNote));
|
|
|
|
|
}
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::Config( const NoteData& from )
|
2002-12-13 01:23:26 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
SetNumTracks( from.GetNumTracks() );
|
2002-12-13 01:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::CopyAll( const NoteData& from )
|
2002-12-13 01:23:26 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
Config(from);
|
2003-01-21 03:12:24 +00:00
|
|
|
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];
|
|
|
|
|
m_HoldNotes = from.m_HoldNotes;
|
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-02-25 08:40:03 +00:00
|
|
|
{
|
2004-09-25 07:59:56 +00:00
|
|
|
ASSERT( track < GetNumTracks() );
|
2004-02-25 08:40:03 +00:00
|
|
|
|
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 )
|
2004-02-25 08:40:03 +00:00
|
|
|
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 );
|
2004-09-12 05:56:24 +00:00
|
|
|
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 );
|
2004-09-12 05:56:24 +00:00
|
|
|
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 );
|
2004-09-12 05:56:24 +00:00
|
|
|
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 );
|
2004-09-12 05:56:24 +00:00
|
|
|
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-09-09 05:22:02 +00:00
|
|
|
|
2002-04-16 17:31:00 +00:00
|
|
|
// look for other hold notes that overlap and merge them
|
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);
|
2003-02-16 20:27:53 +00:00
|
|
|
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
|
2003-09-15 05:41:11 +00:00
|
|
|
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-08-13 23:26:46 +00:00
|
|
|
|
2004-05-24 04:17:19 +00:00
|
|
|
// delete TapNotes under this HoldNote
|
2004-09-29 06:43:57 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, add.iTrack, i, iAddStartIndex+1, iAddEndIndex )
|
2004-09-12 05:56:24 +00:00
|
|
|
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
|
2004-09-12 05:56:24 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2002-08-13 23:26:46 +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-08-13 23:26:46 +00:00
|
|
|
|
2002-11-02 22:53:04 +00:00
|
|
|
HoldNote& hn = GetHoldNote(iHoldIndex);
|
2002-08-13 23:26:46 +00:00
|
|
|
|
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
|
2003-02-16 20:27:53 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2005-01-22 20:22:12 +00:00
|
|
|
/* Return true if a hold note lies on the given spot. Must be in 2sAnd3s. */
|
|
|
|
|
bool NoteData::IsHoldNoteAtBeat( int iTrack, int iRow ) const
|
2003-12-18 02:34:59 +00:00
|
|
|
{
|
2005-01-22 20:22:12 +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. */
|
2005-01-23 03:48:22 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE_REVERSE( *this, iTrack, r, 0, iRow )
|
2003-12-18 02:34:59 +00:00
|
|
|
{
|
2005-01-22 20:22:12 +00:00
|
|
|
const TapNote &tn = GetTapNote( iTrack, r );
|
|
|
|
|
switch( tn.type )
|
|
|
|
|
{
|
|
|
|
|
case TapNote::hold_head:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case TapNote::tap:
|
|
|
|
|
case TapNote::mine:
|
|
|
|
|
case TapNote::attack:
|
|
|
|
|
case TapNote::hold_tail:
|
|
|
|
|
return false;
|
|
|
|
|
case TapNote::empty:
|
|
|
|
|
case TapNote::autoKeysound:
|
|
|
|
|
/* ignore */
|
|
|
|
|
continue;
|
|
|
|
|
case TapNote::hold:
|
|
|
|
|
/* Don't call this function when in 4s mode! */
|
|
|
|
|
FAIL_M("hold");
|
|
|
|
|
default:
|
|
|
|
|
FAIL_M( ssprintf("%i", tn.type) );
|
|
|
|
|
}
|
2003-12-18 02:34:59 +00:00
|
|
|
}
|
2005-01-22 20:22:12 +00:00
|
|
|
|
|
|
|
|
return false;
|
2003-12-18 02:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-14 20:27:52 +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-10-02 05:08:59 +00:00
|
|
|
for( int t=0; t < GetNumTracks(); t++ )
|
2002-07-11 19:02:26 +00:00
|
|
|
{
|
2004-10-25 03:36:42 +00:00
|
|
|
int iRow = -1;
|
|
|
|
|
if( !GetNextTapNoteRowForTrack( t, iRow ) )
|
2004-09-29 06:43:57 +00:00
|
|
|
continue;
|
2004-10-25 03:36:42 +00:00
|
|
|
|
2004-09-29 06:43:57 +00:00
|
|
|
if( iEarliestRowFoundSoFar == -1 )
|
2004-10-25 03:36:42 +00:00
|
|
|
iEarliestRowFoundSoFar = iRow;
|
2004-09-29 06:43:57 +00:00
|
|
|
else
|
2004-10-25 03:36:42 +00:00
|
|
|
iEarliestRowFoundSoFar = min( iEarliestRowFoundSoFar, iRow );
|
2002-07-11 19:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2002-08-13 23:26:46 +00:00
|
|
|
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;
|
2004-10-25 03:36:42 +00:00
|
|
|
if( !GetPrevTapNoteRowForTrack( t, iRow ) )
|
2004-09-29 06:43:57 +00:00
|
|
|
continue;
|
2004-10-25 03:36:42 +00:00
|
|
|
iOldestRowFoundSoFar = max( iOldestRowFoundSoFar, iRow );
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +00:00
|
|
|
int NoteData::GetNumTapNotes( int iStartIndex, int iEndIndex ) const
|
2002-12-14 20:34:38 +00:00
|
|
|
{
|
2004-09-29 06:43:57 +00:00
|
|
|
int iNumNotes = 0;
|
2004-09-28 02:14:56 +00:00
|
|
|
for( int t=0; t<GetNumTracks(); t++ )
|
2002-09-06 00:21:49 +00:00
|
|
|
{
|
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);
|
2004-09-12 05:56:24 +00:00
|
|
|
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-09-06 00:21:49 +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
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +00:00
|
|
|
int NoteData::GetNumRowsWithTap( int iStartIndex, int iEndIndex ) const
|
2003-03-16 18:57:34 +00:00
|
|
|
{
|
|
|
|
|
int iNumNotes = 0;
|
2004-10-24 10:20:24 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_ALL_TRACKS_RANGE( *this, r, iStartIndex, iEndIndex )
|
|
|
|
|
if( IsThereATapAtRow(r) )
|
2003-03-16 18:57:34 +00:00
|
|
|
iNumNotes++;
|
|
|
|
|
|
|
|
|
|
return iNumNotes;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +00:00
|
|
|
int NoteData::GetNumMines( int iStartIndex, int iEndIndex ) const
|
2003-11-26 04:21:59 +00:00
|
|
|
{
|
2004-09-29 06:43:57 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2004-10-25 03:16:40 +00:00
|
|
|
const TapNote &tn = GetTapNote(t, row);
|
2004-09-12 05:56:24 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +00:00
|
|
|
int NoteData::GetNumHands( 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
|
|
|
{
|
2004-10-24 10:20:24 +00:00
|
|
|
if( !RowNeedsHands(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-01-22 17:34:10 +00:00
|
|
|
int NoteData::GetNumN( 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);
|
2004-09-12 05:56:24 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2005-01-22 17:34:10 +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;
|
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.
|
2002-10-20 21:39:13 +00:00
|
|
|
// Plus, allowing tap notes in the middle of a hold doesn't make sense!
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2004-09-29 06:43:57 +00:00
|
|
|
for( int t=0; t<GetNumTracks(); t++ ) // foreach column
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2004-10-24 10:20:24 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK( *this, t, r )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2005-01-23 17:17:24 +00:00
|
|
|
TapNote head = GetTapNote(t,r);
|
|
|
|
|
if( head.type != TapNote::hold_head )
|
2004-09-29 06:43:57 +00:00
|
|
|
continue; // skip
|
2002-09-06 00:21:49 +00:00
|
|
|
|
2004-10-24 10:20:24 +00:00
|
|
|
SetTapNote(t, r, TAP_EMPTY); // clear the hold head marker
|
2004-09-29 06:43:57 +00:00
|
|
|
|
|
|
|
|
// search for end of HoldNote
|
2005-01-22 19:18:42 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *this, t, j, r+1, MAX_NOTE_ROW )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2004-09-12 05:56:24 +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.
|
2004-09-29 06:43:57 +00:00
|
|
|
if( GetTapNote(t, j).type == TapNote::empty )
|
2002-09-06 00:21:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
2004-09-29 06:43:57 +00:00
|
|
|
SetTapNote(t, j, TAP_EMPTY);
|
2002-09-06 05:24:59 +00:00
|
|
|
|
2005-01-23 17:17:24 +00:00
|
|
|
HoldNote hold(t, r, j);
|
|
|
|
|
hold.result = head.HoldResult;
|
|
|
|
|
AddHoldNote( hold );
|
2004-09-12 05:56:24 +00:00
|
|
|
break; // done searching for the end of this hold
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-04 03:02:26 +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);
|
2002-10-12 21:40:55 +00:00
|
|
|
|
|
|
|
|
/* If they're the same, then they got clamped together, so just ignore it. */
|
2005-01-23 17:17:24 +00:00
|
|
|
if( hn.iStartRow == hn.iEndRow )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
TapNote head = TAP_ORIGINAL_HOLD_HEAD;
|
|
|
|
|
head.HoldResult = hn.result;
|
|
|
|
|
SetTapNote( hn.iTrack, hn.iStartRow, 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:02:26 +00:00
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::To2sAnd3s( const NoteData& from )
|
2003-10-04 03:02:26 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
CopyAll( from );
|
2003-10-04 03:12:45 +00:00
|
|
|
ConvertHoldNotesTo2sAnd3s();
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::From2sAnd3s( const NoteData& from )
|
2003-10-04 03:12:45 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
CopyAll( from );
|
2003-10-04 03:12:45 +00:00
|
|
|
Convert2sAnd3sToHoldNotes();
|
2003-10-04 03:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::To4s( const NoteData& from )
|
2003-10-04 04:05:29 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
CopyAll( from );
|
2003-10-04 04:05:29 +00:00
|
|
|
ConvertHoldNotesTo4s();
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-23 17:43:49 +00:00
|
|
|
void NoteData::From4s( const NoteData& from )
|
2003-10-04 04:05:29 +00:00
|
|
|
{
|
2004-10-23 17:43:49 +00:00
|
|
|
CopyAll( from );
|
2003-10-04 04:05:29 +00:00
|
|
|
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()
|
|
|
|
|
{
|
2004-09-29 06:43:57 +00:00
|
|
|
for( int t=0; t<GetNumTracks(); t++ ) // foreach column
|
2002-08-25 05:00:23 +00:00
|
|
|
{
|
2004-10-24 10:20:24 +00:00
|
|
|
FOREACH_NONEMPTY_ROW_IN_TRACK( *this, t, r )
|
2002-08-25 05:00:23 +00:00
|
|
|
{
|
2004-10-24 10:20:24 +00:00
|
|
|
if( GetTapNote(t, r).type == TapNote::hold ) // this is a HoldNote body
|
2004-09-12 05:56:24 +00:00
|
|
|
{
|
2004-10-24 10:20:24 +00:00
|
|
|
HoldNote hn( t, r, 0 );
|
2004-09-12 05:56:24 +00:00
|
|
|
// search for end of HoldNote
|
|
|
|
|
do {
|
2004-10-24 10:20:24 +00:00
|
|
|
SetTapNote( t, r, TAP_EMPTY );
|
|
|
|
|
r++;
|
|
|
|
|
} while( GetTapNote(t, r).type == TapNote::hold );
|
|
|
|
|
SetTapNote( t, r, TAP_EMPTY );
|
2002-08-25 05:00:23 +00:00
|
|
|
|
2004-10-24 10:20:24 +00:00
|
|
|
hn.iEndRow = r;
|
2004-09-12 05:56:24 +00:00
|
|
|
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)
|
2004-09-12 05:56:24 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2002-08-25 19:00:12 +00:00
|
|
|
// -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
|
|
|
{
|
2002-08-25 19:00:12 +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
|
|
|
{
|
2002-08-25 19:00:12 +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
|
|
|
|
2002-08-25 19:00:12 +00:00
|
|
|
if( iOriginalTrack == -1 )
|
|
|
|
|
continue;
|
2005-01-22 20:22:12 +00:00
|
|
|
m_TapNotes[t] = in.m_TapNotes[iOriginalTrack];
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-22 20:22:12 +00:00
|
|
|
// copy holds
|
2005-01-23 05:15:18 +00:00
|
|
|
int iInverseMapping[MAX_NOTE_TRACKS];
|
|
|
|
|
for( int i = 0; i < iNewNumTracks; ++i )
|
|
|
|
|
{
|
|
|
|
|
int iFrom = iOriginalTrackToTakeFrom[i];
|
|
|
|
|
iInverseMapping[iFrom] = i;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 20:22:12 +00:00
|
|
|
for( int i=0; i<in.GetNumHoldNotes(); i++ ) // for each HoldNote
|
|
|
|
|
{
|
2005-01-23 05:15:18 +00:00
|
|
|
HoldNote hn = in.GetHoldNote(i);
|
|
|
|
|
hn.iTrack = iInverseMapping[hn.iTrack];
|
2005-01-22 20:22:12 +00:00
|
|
|
this->AddHoldNote( hn );
|
|
|
|
|
}
|
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 )
|
2002-10-25 23:32:50 +00:00
|
|
|
{
|
2004-09-25 07:59:56 +00:00
|
|
|
DEBUG_ASSERT( track>=0 && track<GetNumTracks() );
|
|
|
|
|
|
2004-09-29 06:43:57 +00:00
|
|
|
if( row < 0 )
|
|
|
|
|
return;
|
2002-12-13 01:23:26 +00:00
|
|
|
|
2004-09-29 06:43:57 +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 );
|
2004-09-29 06:43:57 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_TapNotes[track][row] = t;
|
|
|
|
|
}
|
2002-10-25 23:32:50 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2004-09-29 06:43:57 +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
|
2004-09-29 06:43:57 +00:00
|
|
|
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() )
|
2004-09-29 06:43:57 +00:00
|
|
|
return false;
|
2004-10-24 23:49:33 +00:00
|
|
|
|
|
|
|
|
ASSERT( iter->first > rowInOut );
|
|
|
|
|
rowInOut = iter->first;
|
|
|
|
|
return true;
|
2004-09-29 06:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
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-22 03:11:29 +00:00
|
|
|
/* Return an iterator range. This can be used to 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 O(1)), 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::const_iterator &begin, TrackMap::const_iterator &end ) const
|
|
|
|
|
{
|
|
|
|
|
ASSERT_M( iTrack < GetNumTracks(), ssprintf("%i,%i", iTrack, GetNumTracks()) );
|
|
|
|
|
ASSERT_M( iStartRow <= iEndRow, ssprintf("%i > %i", iStartRow, iEndRow) );
|
|
|
|
|
|
|
|
|
|
const TrackMap &mapTrack = m_TapNotes[iTrack];
|
|
|
|
|
begin = mapTrack.lower_bound( iStartRow );
|
|
|
|
|
end = mapTrack.upper_bound( iEndRow );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-29 06:43:57 +00:00
|
|
|
bool NoteData::GetNextTapNoteRowForAllTracks( int &rowInOut ) const
|
|
|
|
|
{
|
2005-01-22 19:18:42 +00:00
|
|
|
int iClosestNextRow = MAX_NOTE_ROW;
|
2004-09-29 06:43:57 +00:00
|
|
|
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 );
|
2004-09-29 06:43:57 +00:00
|
|
|
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.
|
|
|
|
|
*/
|