Control-Surface icon indicating copy to clipboard operation
Control-Surface copied to clipboard

BANKS WITH MULTIPLE BUTTON FUNCTION

Open diegogauffin opened this issue 1 year ago • 1 comments
trafficstars

Discussed in https://github.com/tttapa/Control-Surface/discussions/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();

}

diegogauffin avatar May 29 '24 12:05 diegogauffin

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.

tttapa avatar May 29 '24 17:05 tttapa