cs-midi-docs/docs/examples/04-banks/01-bank-cc-values.md

1.1 KiB

Bank with CC Values

Bank switching with bankable input elements. Bank switching changes the CC address listened to.

Original: Bank.ino (adapted)

#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include <cs_midi.h>

using namespace cs;

BluetoothMIDI_Interface midi;

// 4 banks, 2 tracks per bank
Bank<4> bank(2);

// Selector: two buttons to increment/decrement the active bank
IncrementDecrementSelector<4> selector {
    bank,
    {2, 3},
    Wrap::Wrap,
};

// Bankable CC value readers — bank switching changes the CC address.
// Bank 1: reads CC 16, CC 17
// Bank 2: reads CC 18, CC 19
// Bank 3: reads CC 20, CC 21
// Bank 4: reads CC 22, CC 23
Bankable::CCValue<4> ccVal1 {
    {bank, BankType::ChangeAddress},
    {16, Channel_1},
};
Bankable::CCValue<4> ccVal2 {
    {bank, BankType::ChangeAddress},
    {17, Channel_1},
};

int main() {
    stdio_init_all();
    if (cyw43_arch_init()) return 1;
    Control_Surface.begin();
    while (true) {
        Control_Surface.loop();
        uint8_t v1 = ccVal1.getValue();
        uint8_t v2 = ccVal2.getValue();
        (void)v1;
        (void)v2;
        sleep_ms(1);
    }
}