ControlP5 button...do one thing when pressed and another when released...

edited December 2013 in Library Questions

Hi all & seasons greetings from London. I have a problem with ControlP5 button. I want to be able to send a midi note on message when the button is pressed and a note off when it is released but at the moment all i can do is send a note on when I have pressed it and the note on message is sent when I let go of the button. I am using controlP5 on Processing for android bu the principle is the same... I just press the button with my finger instead of the mouse. So like I say, when I put my finger on the button it only sends the note on message when I let go of the button. Could anyone help me get it so when I PRESS the button, the note on is sent & when I let go of the button the note off message is sent? I am puzzled. Thanks all. Steve.

Answers

  • Hi Steve,

    It would be more helpful if you posted your code in here. :)

  • Hi, you can use a callback, see example below:

    import controlP5.*;
    // uses processing 2.1 and controlp5 2.0.4
    ControlP5 cp5;
    
    void setup() {
      size(800, 400);
    
      cp5 = new ControlP5(this);
      cp5.addButton("my-button").setPosition(100,100).addCallback(  
      new CallbackListener() {
        public void controlEvent(CallbackEvent theEvent) {
          switch(theEvent.getAction()) {
            case(ControlP5.ACTION_PRESSED):
            println("send MIDI on press, note on.");
            break;
            case(ControlP5.ACTION_RELEASED):
            case(ControlP5.ACTION_RELEASEDOUTSIDE):
            println("send MIDI on release, note off.");
            break;
          }
        }
      }
      );
    
    }
    
    void draw() {
    }
    
Sign In or Register to comment.