Control_surface library banks with non sequential values

Hi, I am making a 4 button foot controller, with two banks. I would like to:

  • assign a non linear list of note numbers to each bank
  • set the midi channel for those notes
  • assign a random velocity to each note

This code works, but I can't figure out how to assign the midi channel:

#include <Control_Surface.h> // Include the Control Surface library

USBMIDI_Interface midi;

const int NoteVals1 [] {
  55,
  51,
  49,
  47,
};

const int NoteVals2 [] {
  59,
  52,
  48,
  42,
};

// Instantiate 2 Banks
Bank<2> bank;
// Instantiate a Bank selector to control which one of the three Banks is active.
IncrementDecrementSelector<2> selector = {
    bank,       // Bank to manage
    {15, 14},     // push button pins (increment, decrement)
    Wrap::Clamp, // No Wrap 
};

Bankable::ManyAddresses::NoteButton<2> myMultiFunctionNoteButton1 = {
  bank,
  6, // input pin 
  {
    NoteVals1[0],    // Controller Nº to use when 1st bank is selected
    NoteVals2[0],   // Controller Nº to use when 2nd bank is selected
  },
};

Bankable::ManyAddresses::NoteButton<2> myMultiFunctionNoteButton2 = {
  bank,
  7, // input pin 
  {
    NoteVals1[1], 
    NoteVals2[1], 
  },
};
Bankable::ManyAddresses::NoteButton<2> myMultiFunctionNoteButton3 = {
  bank,
  8, // input pin 
  {
    NoteVals1[2],    
    NoteVals2[2], 
  },
};
Bankable::ManyAddresses::NoteButton<2> myMultiFunctionNoteButton4 = {
  bank,
  9, // input pin 
  {
    NoteVals1[3],      
    NoteVals2[3],     
  },
};

void setup() { 
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface
}

As far as assigning random velocities, I had this code working before I introduced ManyAddresses:

int rand1;

void setup() { 
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  
  for (int i = 0; i < 4; i++) {
    rand1 = random(80,115);
    footButtons[i].setVelocity(rand1);
  }
  
  Control_Surface.loop(); // Update the Control Surface
}

But I can't figure out the syntax for assigning setVelocity() to items when ManyAddresses is used. Any help is appreciated!

You can pass the full MIDI address to the NoteButton constructor, e.g. {55, Channel_1}. See https://tttapa.github.io/Control-Surface/Doxygen/d3/df7/midi-tutorial.html#midi_md-midi-addresses for details.

In older versions of Control Surface, you can use footButtons[i].sender.setVelocity(rand1). If you upgrade to 77ab308, you can leave out the .sender.

Thanks @PieterP

The full MIDI address isn't working for me for some reason.

This simple example works fine:

#include <Control_Surface.h> // Include the Control Surface library

USBMIDI_Interface midi;

// Instantiate 2 Banks
Bank<2> bank;
// Instantiate a Bank selector to control which one of the three Banks is active.
IncrementDecrementSelector<2> selector = {
  bank,       // Bank to manage
  {15, 14},     // push button pins (increment, decrement)
  Wrap::Clamp, // No Wrap 
};

Bankable::ManyAddresses::NoteButton<2> footButton1 = {
  bank, 6, {55, 59}
};

void setup() { 
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface
}

If I try passing the full MIDI address it errors:

Bankable::ManyAddresses::NoteButton<2> footButton1 = {
  bank, 6, {{55, Channel_15}, {59, Channel_15}}
};

the error I get is:

Compilation error: could not convert '{bank, 6, {{55, cs::Channel_15}, {59, cs::Channel_15}}}' from '' to 'cs::Bankable::ManyAddresses::NoteButton<2>'

You'll need another pair of braces:

Bankable::ManyAddresses::NoteButton<2> footButton1 {
  bank, 6, {{{55, Channel_15}, {59, Channel_15}}}
};

Thanks so much, @PieterP !

Also got setVelocity() working properly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.