Skip to content

Commit

Permalink
uncomment optimized connectnotes, oops
Browse files Browse the repository at this point in the history
  • Loading branch information
khang06 committed Mar 16, 2020
1 parent c3e9274 commit f3ea74b
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions PianoFromAbove/MIDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ void MIDI::PostProcess( vector< MIDIEvent* > *vEvents )
midi_map_times_pos = 0;
}

/*
void MIDI::ConnectNotes()
{
//const int StackSize = 10;
Expand Down Expand Up @@ -527,61 +526,6 @@ void MIDI::ConnectNotes()

delete[] pStacks;
}
*/
void MIDI::ConnectNotes()
{
const int StackSize = 10;
int pSize[16][128];
MIDIChannelEvent* pStacks[16][128][StackSize];

for (vector< MIDITrack* >::iterator itTrack = m_vTracks.begin(); itTrack != m_vTracks.end(); ++itTrack)
{
memset(pSize, 0, sizeof(pSize));
vector< MIDIEvent* >& vEvents = (*itTrack)->m_vEvents;
int iEvents = (int)vEvents.size();
for (int i = 0; i < iEvents; i++)
if (vEvents[i]->GetEventType() == MIDIEvent::ChannelEvent)
{
MIDIChannelEvent* pEvent = reinterpret_cast<MIDIChannelEvent*>(vEvents[i]);
MIDIChannelEvent::ChannelEventType eEventType = pEvent->GetChannelEventType();
int iChannel = pEvent->GetChannel();
int iNote = pEvent->GetParam1();
int iVelocity = pEvent->GetParam2();

if (eEventType == MIDIChannelEvent::NoteOn && iVelocity > 0)
{
int& iSize = pSize[iChannel][iNote];
if (iSize < StackSize) pStacks[iChannel][iNote][iSize] = pEvent;
iSize++;
}
else if (eEventType == MIDIChannelEvent::NoteOff || eEventType == MIDIChannelEvent::NoteOn)
{
int& iSize = pSize[iChannel][iNote];
if (iSize > 0)
{
if (iSize <= StackSize) pStacks[iChannel][iNote][iSize - 1]->SetSister(pEvent);
else // Should never get here
{
int j = i - 1;
while (j >= 0 && !pEvent->GetSister())
{
if (vEvents[j]->GetEventType() == MIDIEvent::ChannelEvent)
{
MIDIChannelEvent* pSister = reinterpret_cast<MIDIChannelEvent*>(vEvents[j]);
if (!pSister->GetSister() &&
pSister->GetChannelEventType() == MIDIChannelEvent::NoteOn &&
pSister->GetParam1() == iNote && pSister->GetParam2() > 0)
pEvent->SetSister(pSister);
}
j--;
}
}
iSize--;
}
}
}
}
}


//-----------------------------------------------------------------------------
Expand Down

0 comments on commit f3ea74b

Please sign in to comment.