Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching between CCButton and CCLatched #1093

Open
diegogauffin opened this issue Nov 14, 2024 · 2 comments
Open

Switching between CCButton and CCLatched #1093

diegogauffin opened this issue Nov 14, 2024 · 2 comments

Comments

@diegogauffin
Copy link

Hey Pieter! How are you? Hope fine!
I was thinking it would be really usefulll to get a way to change between CCButton (momentary) and CC Latched in the run. Do you think is that posible ? I mean doing it without changing the code, upload and so on.

@Wallirec
Copy link

Wallirec commented Dec 2, 2024

I don't know how to get a new function without changing the code.
But here is an example of code with a button (connected to pin 2) which, when pressed briefly, transmits CC 20 Latched, and when pressed long, CC20 momentary

#include <Control_Surface.h>

USBMIDI_Interface midi;
unsigned char btn_flg = 0;

// Ignore the name “increment” button, it's simply a button
// class that can detect long and short presses.
IncrementButton btn { 2 }; // pin number of button

void setup() {
  Control_Surface.begin();
  btn.begin();
}

void loop() {
  Control_Surface.loop();
  switch (btn.update()) {
    case IncrementButton::ReleasedShort: // If button is released after short press
      Control_Surface.sendCC(20, btn_flg * 127);
      btn_flg = !btn_flg;
      break;
    case IncrementButton::IncrementLong: // If button is still pressed after some time
      Control_Surface.sendCC(20, 127);
      delay(35);
      Control_Surface.sendCC(20, 0);
      break;
  }
}

@gwilherm
Copy link

gwilherm commented Dec 2, 2024

You can use pointer to MIDIOutputElement and delete/create instance of CCButton or CCButtonLatched.
If you need to use getAddress() or setAddressUnsafe() there is no common interface for this but Pieter came with a workaround that helped me a lot: #971 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants