Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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) 
		  {    // Do something with your touch input handle.
                      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(&amp;rect);
							                                          
	        }
		if(RecordState==true)
	       {	
		 RecordNo++;
		 PreviousTime=Current;
		 GetSystemTime(&amp;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()
  {
   }
//remaning code

}

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))
			{
				 
				//m_HasCapture=false;
				
				CRect rect;
				if(TouchDown[i]==true)
				{
										m_Keys[TouchInputDownm_CurrKeys[i]]->NoteOn(m_NoteOnColor,rect);
				      InvalidateRect(rect);
					
					NotifyNoteOn(TouchInputDownm_LowNote[i]);
		
					 //findchords1(TouchInputDownm_LowNote[i]);
				    //InvalidateRect(&rect);			 
					//TDw++;
				  }
						
			}
			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);			 
								
					//TDu++;
				}
				
			}
			else
			{
				/* Do nothingg*/
		
			}

				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..
Posted
Updated 24-Oct-13 2:37am
v2
Comments
Sergey Alexandrovich Kryukov 24-Oct-13 9:02am    
Pretty interesting question, voted 5...

I'm just curious, what multi-touch device do you use? It's quite easy to make a multi-touch piano (others are not really so useful) based on the keyboard, but a multi-touch panel needs a lot of room. Besides, it would be good to have some 10 touch points, to really play. Is it possible? Is it a multi-touch screen? But then playing would be inconvenient, unless you put it flat...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900