基于多点触控钢琴对话的应用程序 [英] Multitouch Piano Dialog Based application

查看:98
本文介绍了基于多点触控钢琴对话的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Freinds,我已经制作了一个基于对话框的钢琴应用程序,我正在处理多点触控消息。我有两个类一个是CMIDIKeyboard,我在其中处理触摸消息如下

Hello Freinds, I have made a dialog based Piano application in which i am handling Multitouch messages . I have two classes One is CMIDIKeyboard in which i am handling touch down messages as follows

LRESULT CMIDIKeyboard::OnTouchMessage( WPARAM wParam, LPARAM lParam ){
    //Insert handler code here to do something with the message 
   //or uncomment the following line to test
  //-------------------saurabh code-----------------------------------
             // Number of actual per-contact messages
	     UINT  cInputs  = (int) wParam;    
            
            // Allocate the storage for the parameters of the per-contact messages
            TOUCHINPUT* pInputs = new TOUCHINPUT[cInputs]; 
            if (pInputs == NULL)
            {   
		  return 0;
            }
            // Unpack message parameters into the array of TOUCHINPUT structures, each
            // representing a message for one single contact.
            if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
            {
                // For each contact, dispatch the message to the appropriate message
                // handler.
                for (unsigned int i = 0; i < cInputs; i++)
                {
					 if (pInputs[i].dwFlags & TOUCHEVENTF_DOWN)
					 {
						 CPoint point;
						 CRect rect;
						 GetClientRect(&rect);
						 point=CPoint(pInputs[i].x-     rect.left,pInputs[i].y-rect.top);
						m_CurrKey= CPianoCtrl::FindKey(point); 
						m_Keys[m_CurrKey]-    >NoteOn(m_NoteOnColor,rect);
						NotifyNoteOn(m_LowNote+m_CurrKey);  
                                        	   findchords(m_LowNote+m_CurrKey);
	  

                                                InvalidateRect(&rect);
		                                CWnd::OnTouchMessage(wParam,lParam);
						 			
                                 					
                     }
                    else if (pInputs[i].dwFlags & TOUCHEVENTF_UP)
                    {
				     

		    //MessageBox("touchup!", "touchup!", MB_OK);
		 // g_pIManipProc->ProcessUp(pInputs[i].dwID, (FLOAT)pInputs[i].x, (FLOAT)pInputs[i].y);
                    } 

                     else if (pInputs[i].dwFlags & TOUCHEVENTF_MOVE)
                    {
		    //MessageBox("touchmove!", "touchmove!", MB_OK);
                        //g_pIManipProc->ProcessMove(pInputs[i].dwID, (FLOAT)pInputs[i].x, (FLOAT)pInputs[i].y);
                    }
					                    
                }
            }
            else
            {
                // error handling, presumably out of memory
                ASSERT(FALSE && L"Error: failed to execute GetTouchInputInfo");
                delete [] pInputs;
		return 0;
                //break;
            }
            if (!CloseTouchInputHandle((HTOUCHINPUT)lParam))
            {
                // error handling, presumably out of memory
                ASSERT(FALSE && L"Error: failed to execute CloseTouchInputHandle");
                delete [] pInputs;
		return 0;
                //break;
            }
            delete [] pInputs; 
  //--------------------------------------------------------saurabh code ends-----------------
	//MessageBox("touch!", "touch!", MB_OK);
    return 0;
  }





但是在弹奏钢琴键时,第一次触摸正在播放,但是在钢琴键上弹奏超过1次无论触摸位置如何,都可以启用右侧的最后一个键。



But on playing the piano keys first touch is playing proper ,but more than 1 touch is playing on piano keys enabling the last key on the right side irrespective of the touch position.

//                  ----------------------
//                  | | || | | | || || | |
//                  | |_||_| | |_||_||_| |
//                  |  |  |  |  |  |  |  |
//                  ----------------------
//                          ^           ^
                            |           |
                        one point    More than
                          touch      one touch





任何人都可以指导我或纠正我请。



Can anybody please guide me or correct me please.

推荐答案

这是我的建议:写一个更简单的程序,只记录触摸事件(或记录到这个)并试图找出什么是错的。



你的代码还有另外一件事是肯定的(但是你可以通过阅读文档来找到它: http://msdn.microsoft.com/en-us/library/windows/ desktop / dd317334%28v = vs.85%29.aspx [ ^ ]。

TOUCHEVENTF_MOVE和TOUCHEVENTF_UP可以合并,所以不要自己处理否则如果分支并假设一个event只包含一个标志,你应该期望它们都进入同一个事件。



一般情况下触摸界面需要准备的另一件事:一些触摸界面可能发送更多或两个向下事件,而不是它们之间。如果我没记错,android doc会说明这一点。如果您的逻辑依赖于此行为,那么很容易从代码中为此做好准备,并在两个连续的向下事件之间自行设置......
Here is what I recommend: Write a much simpler program that only logs out the touch events (or put logging into this one) and try to find out whats going wrong.

There is another thing in you code that is bug for sure (but you could find this out by reading the docs: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317334%28v=vs.85%29.aspx[^]).
TOUCHEVENTF_MOVE and TOUCHEVENTF_UP can be combined, so instead of handling the in their own else if branch and assuming that an event contains only one flag you should expect both of them coming in the same event.

Another thing to prepare for in case of touch interfaces in general: Some touch interfaces may send more or two down events without an up between them. If I remember right the android doc states this. Its very easy to prepare for this from code and put your own up between two consecutive down events if your logic relies on this behavior...


这篇关于基于多点触控钢琴对话的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆