multitouch algorithm for making some digital music instrument

52 views
Skip to first unread message

Yoseph Wijaya

unread,
Aug 9, 2013, 2:22:59 PM8/9/13
to android-musi...@googlegroups.com
i have an algorithm for making digital music instruments.
and my algorithmn doesnt go well..
it is like this,
this code is on onTouchEvent, i have 4 button just for testing purpose, and this algorihtm doesnt response well on multitouch.
because every i lift other finger, it cant response my other finger which is still action_down on the view, and the result is whenever 1 of my finger trigger action_up , all things just go action_up...
 
int action= event.getAction();
            boolean[] newButtonStates =new boolean[4];
            boolean isDownAction = action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_DOWN;
           
         
                for (int touchindex = 0 ; touchindex<event.getPointerCount(); touchindex++){
                    int x = (int) event.getX(touchindex);
                    int y = (int) event.getY(touchindex);
                    for (int buttonIndex = 0; buttonIndex < buttonzz.size(); buttonIndex++){
                        Rect rect = new Rect(buttonzz.get(buttonIndex).left, buttonzz.get(buttonIndex).top, buttonzz.get(buttonIndex).right, buttonzz.get(buttonIndex).bottom);
                            if (rect.contains(x, y))
                            {
                                newButtonStates[buttonIndex] = isDownAction;
                             
                            }
                        }
                       
                    }
                for (int i = 0; i < buttonStates.length; i++)
                {
                    if (buttonStates[i] != newButtonStates[i])
                    {
                    buttonStates[i] = newButtonStates[i];
                    toggleButtonSound(i, newButtonStates[i]);
                    }
                }

maybe somebody have better algorithm than this.. thx

Alex

unread,
Aug 9, 2013, 2:48:57 PM8/9/13
to android-musi...@googlegroups.com
Hi Yoseph,

In the second loop, you compare all of the entries in newButtonStates against buttonStates, but unless there is some code missing, most of those states have not actually been set!  Why not do away with the newButtonStates array and move the toggleButtonSound call into the if(rect.contains) block?  You will also find that you will need to detect when an ACTION_MOVE moves a finger out of, as well as into, a key area.  MotionEvent maintains a history buffer which may be useful for this.

Hope this helps!

Alex

Michael Helland

unread,
Aug 9, 2013, 3:00:49 PM8/9/13
to android-musi...@googlegroups.com

Also keep in mind Android 2.x couldnt do multitouch across different views.

That may or may not be relevant

--
You received this message because you are subscribed to the Google Groups "Android Music Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-music-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yoseph Wijaya

unread,
Aug 9, 2013, 3:54:01 PM8/9/13
to android-musi...@googlegroups.com
oh okay thx, btw theres some code missing...
public mySurfaceView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
            surfaceholder = getHolder();
            Rect rect = new Rect(30, 480, 70, 520);
            buttonzz = new ArrayList<Rect>();
            buttonzz.add(rect);
            rect = new Rect(180, 480, 220, 520);
            buttonzz.add(rect);
            rect = new Rect(330, 480, 370, 520);
            buttonzz.add(rect);
            rect = new Rect(480, 480, 520, 520);
            buttonzz.add(rect);
            buttonStates = new boolean[buttonzz.size()];
            soundPlayer = new AudioTrackSoundPlayer(context);
        }

that is the buttonStates array from, and oh my button is from drawing not real button..
and the problem still the same whenever i action_up, all things just goes action_up...
i dont know whether my algorithm is wrong or just need to add some code to check....
Reply all
Reply to author
Forward
0 new messages