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

BANKS WITH MULTIPLE BUTTON FUNCTION #1046

Open
diegogauffin opened this issue May 29, 2024 Discussed in #1045 · 1 comment
Open

BANKS WITH MULTIPLE BUTTON FUNCTION #1046

diegogauffin opened this issue May 29, 2024 Discussed in #1045 · 1 comment

Comments

@diegogauffin
Copy link

Discussed in #1045

Originally posted by diegogauffin May 25, 2024
Hi there! I would like to have some banks for some CCButtons , and it would be really usefull that some of the banks were with CCButtons (Momentary Push) and others banks were CCLatched class. Would it be that posible ?

This is the code i am using:

#include <Control_Surface.h>

USBMIDI_Interface midi;

Bank<5> bank(3);
// │ └───── number of tracks per bank
// └───────────── number of banks

// Instantiate a Bank selector to control which one of the four Banks is active.
IncrementSelectorLEDs<5> selector {
bank, // Bank to manage
1,
{2,5,6,7,15} // push button pin
};

Bankable::CCButton<5> b1 = {
{bank, BankType::CHANGE_ADDRESS}, // bank configuration
0, // digital pin
{102, CHANNEL_11}, // address
};
Bankable::CCButton<5> b2 = {
{bank, BankType::CHANGE_ADDRESS}, // bank configuration
19, // digital pin
{103, CHANNEL_11}, // address
};
Bankable::CCButton<5> b3 = {
{bank, BankType::CHANGE_ADDRESS}, // bank configuration
20, // digital pin
{104, CHANNEL_11}, // address
};

Bankable::CCPotentiometer potentiometer1 {
{bank, BankType::ChangeChannel}, // bank configuration
A6, // analog pin PEDAL
{MIDI_CC::Expression_Controller_LSB , Channel_1}, // address
};

Bankable::CCPotentiometer potentiometer2 {
{bank, BankType::ChangeChannel}, // bank configuration
A3, // analog pin
{MIDI_CC::General_Purpose_Controller_1_LSB, Channel_1}, // address
};

// The maximum value that can be measured (usually 16383 = 2¹⁴-1)
constexpr analog_t maxRawValue = CCPotentiometer::getMaxRawValue();
// The filtered value read when potentiometer is at the 0% position
constexpr analog_t minimumValue = 11200;
// The filtered value read when potentiometer is at the 100% position
constexpr analog_t maximumValue = 14700;

// A mapping function to eliminate the dead zones of the potentiometer:
// Some potentiometers don't output a perfect zero signal when you move them to
// the zero position, they will still output a value of 1 or 2, and the same
// goes for the maximum position.
analog_t mappingFunction(analog_t raw) {
// make sure that the analog value is between the minimum and maximum
raw = constrain(raw, minimumValue, maximumValue);
// map the value from [minimumValue, maximumValue] to [0, maxRawValue]
return map(raw, minimumValue, maximumValue, 0, maxRawValue);
}

void setup() {
Control_Surface.begin();
potentiometer1.map(mappingFunction);
potentiometer2.map(mappingFunction);

}

void loop() {

Control_Surface.loop();

}

@tttapa
Copy link
Owner

tttapa commented May 29, 2024

This is not something that is supported out of the box, but you should be able to do it based on this example: https://tttapa.github.io/Control-Surface-doc/Doxygen/d4/d6b/Custom-MIDI-Output-Element-Bankable_8ino-example.html

You can use address.getActiveAddress() and address.getSelection() to get the banked address and the index of the selected bank respectively, and modify the behavior of the button accordingly.

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

No branches or pull requests

2 participants