I have made a multitouch piano in which i have a class CMIDIKeyboard which consist of following function ie OnKeyUp, OnKeyDown, OnLbuttonUp, OnLButtonDown, OnLButtonMove and OnTouchMessage
In OnTouchMessage i am handling 3 events ie TOUCHEVENTIF_DOWN, TOUCHEVENTIF_UP and TOUCHEVENTID_MOVE.
Under TOUCHEVENTIF_UP i am handling message as follows
for (unsigned int i = 0; i < cInputs; i++)
{
if (pInputs[i].dwFlags && TOUCHEVENTF_DOWN)
{
if(m_IsInitialized )
{
CRect rect;
TOUCHINPUT ti = pInputs [i];
if (ti.dwID != 0)
{
ptInput.x = TOUCH_COORD_TO_PIXEL (ti.x);
ptInput.y = TOUCH_COORD_TO_PIXEL (ti.y);
ScreenToClient ( &ptInput);
points [ti.dwID] [0] = ptInput.x;
points [ti.dwID] [1] = ptInput.y;
CPoint point1=CPoint(points[ti.dwID][0],points[ti.dwID][1]);
m_CurrKey=CPianoCtrl::FindKey(point1);
m_Keys[m_CurrKey]->NoteOn(m_NoteOnColor,rect);
NoteUporDwn='d';
NoteIdPiano=m_LowNote+m_CurrKey;
NotifyNoteOn(m_LowNote+m_CurrKey);
findchords(m_LowNote+m_CurrKey);
((CDemoDlg*)GetParent())->displaychords(CPianoCtrl::dischords);
InvalidateRect(&rect);
}
if(RecordState==true)
{
RecordNo++;
PreviousTime=Current;
GetSystemTime(&Current);
DWORD el= (Current.wMilliseconds+Current.wSecond*1000+Current.wMinute*60000+Current.wHour*3600000)-
(PreviousTime.wMilliseconds+PreviousTime.wSecond*1000+PreviousTime.wMinute*60000+PreviousTime.wHour*3600000);
ElapsedTime.push_back(el);
CString temp;
temp.Format("%ds.",el);
WriteString+=temp;
Event.push_back(5);
TouchInputDownm_CurrKeys.push_back(m_CurrKey);
TouchInputDownm_LowNote.push_back(m_LowNote+m_CurrKey);
TouchInputDownCInput.push_back(cInputs);
TouchDown.push_back(true);
if(CPianoCtrl::m_IsInitialized)
{
cout(CPianoCtrl::NoteUporDwn);
NI=CPianoCtrl::NoteIdPiano;
CString temp;
temp.Format("%dd.",NI);
WriteString+=temp;
}
}
CWnd::OnTouchMessage(wParam,lParam);
}
}
else if()
{
}
else if()
{
}
}
and recording is played as follows-
void CMIDIKeyboard::PlayRecording()
{
int KDownI=0;
int KUpI=0;
int MDwnI=0;
int MUpI=0;
int MmoveI=0;
int TDw=0;
int TDu=0;
int nTotalRecords=ElapsedTime.size();
for(int i=0;(i<=nTotalRecords)&&(((CDemoDlg*)GetParent())->SongPlayrec==true);i++)
{
if(i==nTotalRecords)
{
return;
}
if(i>0)
XSleep(ElapsedTime[i]);
if((Event[i]==0)&&(((CDemoDlg*)GetParent())->SongPlayrec==true))
{
if(KeyDown[KDownI]==true)
{
OnKeyDown(m_KeysRecordDwnChar[KDownI],m_KeysRecordDwnRepCnt[KDownI],m_KeysRecordDwnFlags[KDownI]);
KDownI++;
}
}
if((Event[i]==1);(((CDemoDlg*)GetParent())->SongPlayrec==true))
{
if(KeyUp[KUpI]==true)
{
OnKeyUp(m_KeysRecordUpnChar[KUpI],m_KeysRecordUpnRepCnt[KUpI],m_KeysRecordUpnFlags[KUpI]);
KUpI++;
}
}
if((Event[i]==2);(((CDemoDlg*)GetParent())->SongPlayrec==true)&& (! TOUCHEVENTF_DOWN))
{
if(MouseLDown[MDwnI]==true)
{
OnLButtonDown(MouseRecordLDwnFlags[MDwnI],MouseRecordLDwnPoint[MDwnI]);
MDwnI++;
}
}
if((Event[i]==3)&&(((CDemoDlg*)GetParent())->SongPlayrec==true)&&(!TOUCHEVENTF_UP))
{
if(MouseLUp[MUpI]==true)
{
OnLButtonUp(MouseRecordLUpFlags[MUpI],MouseRecordLUpPoint[MUpI]);
MUpI++;
}
}
if((Event[i]==4);(((CDemoDlg*)GetParent())->SongPlayrec==true))
{
if(MouseDrgMove[MmoveI]==true)
{
OnMouseMove(MouseRecordMoveFlags[MmoveI],MouseRecordMovePoint[MmoveI]);
MmoveI++;
}
}
if((Event[i]==5);(((CDemoDlg*)GetParent())->SongPlayrec==true))
{
CRect rect;
if(TouchDown[i]==true)
{
m_Keys[TouchInputDownm_CurrKeys[i]]->NoteOn(m_NoteOnColor,rect);
InvalidateRect(rect);
NotifyNoteOn(TouchInputDownm_LowNote[i]);
}
}
if((Event[i]==6)&&(((CDemoDlg*)GetParent())->SongPlayrec==true))
{
CRect rect;
if(TouchUp[i]==true)
{
m_Keys[TouchInputUpm_CurrKey[i]]->NoteOff(rect);
InvalidateRect(&rect);
NotifyNoteOff(TouchInputUpm_LowNote[i]);
findchords1(TouchInputUpm_LowNote[i]);
InvalidateRect(&rect);
}
}
else
{
}
cout(i);
}cout("end of for loop");
}
Can anybody please guide me and correct me for event==5 and event==6 condition handling, as per current output for single touch code is correct. If the multitouch and number of touch increases more than 1 the application hangs.Help please..