Using panel as keyboard advise....



  • I have this code on the init callback, it's a panel divided into zones where the different zones trigger NoteOn and NoteOff values, they also trigger some GUI stuff and what I want is to separate the GUI stuff from the mouseCallback events which are the most important and need to be as fast as they could be.
    As I understand it, I'm not able to use the audio thread for the mouseCallback so how would you do to separate them and set the NoteOns and Offs to highest priority?

    Here's an excerpt from the code:

    function NoteOn(n,v)
    {
        if(n>=0 && n<playBack.length)
        {
            id = Synth.addNoteOn(1, playBack[n], v, 0);
            Message.makeArtificial();
            cxList[n] = cx;
            idList[n] = id;
            KeyArr[n].set("itemColour2", col2);
            KeyNameArr[n].set("enabled", true);
        }
        
    }
    
    function NoteOff(n)
    {
        if(n>=0 && n<playBack.length)
        {
            Synth.noteOffByEventId(idList[n]);
            KeyArr[n].set("itemColour2", col1);
            KeyNameArr[n].set("enabled", false);
            cxList[n] = "";
            idList[n] = "";
        }
        
    }
    KeybPanel.setMouseCallback(function(event)
    {
        x = event.dragX;
        c = event.mouseDownX;
        cx = Math.floor(((c + x) * playBack.length) / KeybPanel.get("width"));
        //p = (c + x) - parseInt(borderList[cx]);
        
    	if(event.clicked == 1 && idList[cx] == "")
        {
            v = 127 - Math.floor((event.mouseDownY + event.dragY) / KeybPanel.get("height")* 126);
            NoteOn(cx,v);
            
            //Synth.setVoicePitchValue(playBack[cx], p);
            //Console.print("c "+c);
            //Console.print("cx "+cx);
        }
        
        if(event.drag == 1)
        {
            //Console.print("p "+p);
            if(cxList[cx] == "" || typeof cxList[cx] === "undefined")
            {
                v = 127 - Math.floor((event.mouseDownY + event.dragY) / KeybPanel.get("height")* 126);
                NoteOn(cx,v);
            
                if((c+x) > borderList[cx])
                {
                    NoteOff(cx+1);
                }
                else if((c+x) < borderList[cx])
                {
                    NoteOff(cx-1);
                }
            }
            //Synth.addPitchFade(idList[cx], 100, 0, p*0.2);
        }
        if(event.mouseUp)
        {
            var evX = Math.floor((event.x * playBack.length) / KeybPanel.get("width"));
            NoteOff(evX);
            //Console.print("evX "+evX);
        }
    

Log in to reply
 

11
Online

553
Users

2.1k
Topics

16.5k
Posts