Author Topic: External Midi Controller  (Read 526 times)

Ariesh

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: External Midi Controller
« Reply #30 on: May 14, 2023, 12:58:47 PM »
hi, so i just saw this now and i'm planning todo a whole thread on this - but i managed to code an arduino with 4 bankakble midi over usb footswitches, and up to 4 potentiometers
I'm using the control-surface library, and it works.
 this is my code:


Code: [Select]
#include <Control_Surface.h> // Include the Control Surface library
 
// Instantiate a MIDI over USB interface
USBMIDI_Interface midi;
 
// Instantiate four Banks, with eight tracks per bank.
Bank<4> bank(8);
//   │       └───── number of tracks per bank
//   └───────────── number of banks
 
// Instantiate a Bank selector to control which one of the four Banks is active.
IncrementDecrementSelector<4> selector = {
    bank,       // Bank to manage
    {2, 3},     // Push button pins (increment, decrement)
    Wrap::Wrap, // Wrap around
};

// Instantiate an array of latched push buttons that send MIDI CC messages
// when pressed.
Bankable::CCButtonLatched<4> buttons[] {
  { bank, 4, 0x10 },
  //  │   │    └──── Base MIDI CC controller number
  //  │   └───────── Button pin number
  //  └───────────── Bank that changes the controller number
  { bank, 5, 0x11 },
  { bank, 6, 0x12 },
  { bank, 7, 0x13 },
};

// The bank controls the offset of the controller number relative to the
// button's base address. The amount of offset depends on the "number of
// tracks per bank" argument used when creating the bank. In this case,
// it's 8 tracks per bank, so for every bank you go up, 8 is added to the
// controller number of each button:
//
//         │  Button 1  │  Button 2  │  Button 3  │  Button 4  │  Offset
// ────────┼────────────┼────────────┼────────────┼────────────┤
// Bank 1  │    0x10    │    0x11    │    0x12    │    0x13    │  08=0
// Bank 2  │    0x18    │    0x19    │    0x1A    │    0x1B    │  18=8
// Bank 3  │    0x20    │    0x21    │    0x22    │    0x23    │  28=16
// Bank 4  │    0x28    │    0x29    │    0x2A    │    0x2B    │  38=24

// The array of pin numbers for LEDs that display the states of the buttons.
const pin_t ledPins[] = { 10, 11, 12, 13 };

// Get the length of an array
template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }

static_assert(length(buttons) == length(ledPins),
              "Error: requires same number of buttons as LEDs");

CCPotentiometer knobsTop[] {
  {A0, MIDI_CC::General_Purpose_Controller_1},
  {A1, MIDI_CC::General_Purpose_Controller_2},
  {A2, MIDI_CC::General_Purpose_Controller_3},
  {A3, MIDI_CC::General_Purpose_Controller_4},
};

void setup() {
  Control_Surface.begin();  // Initialize the Control Surface
  for (auto pin : ledPins)  // Set the pinMode to output for all LEDs
      pinMode(pin, OUTPUT);
}

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

  // Loop over all buttons and LEDs
  for (size_t i = 0; i < length(buttons); ++i)
      // Update the LED states to reflect the toggled switch states
      digitalWrite(ledPins[i], buttons[i].getState() ? HIGH : LOW);
}

Randall (Admin)

  • Administrator
  • Full Member
  • *****
  • Posts: 211
    • View Profile
Re: External Midi Controller
« Reply #31 on: May 14, 2023, 01:27:59 PM »
Very cool.  Thanks for sharing.

What an awesome library to abstract away all the low level stuff.

Ariesh

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: External Midi Controller
« Reply #32 on: May 14, 2023, 01:31:21 PM »
i wnated something that would fit my pedalboard, so it has to be just the right size

with very easy modifications and a few multiplexers you can add virtually any number of buttons, and expression pedals as potentiometers

i forgot to mention this code also outputs the state of the button to an LED, and you can always wire and LED in line with any potntiometer if you want

Peetem

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: External Midi Controller
« Reply #33 on: June 13, 2023, 09:15:45 AM »
i wnated something that would fit my pedalboard, so it has to be just the right size

with very easy modifications and a few multiplexers you can add virtually any number of buttons, and expression pedals as potentiometers

i forgot to mention this code also outputs the state of the button to an LED, and you can always wire and LED in line with any potntiometer if you want

I bought a really large pedalboard and installed push buttons in the lower left corner.  Those are tied to my Teensy board and act as a midi controller.  In addition, because the Pi Stomp has stereo in/out, one channel has all my other foot pedals and electric guitar going through it and the other my acoustic.  So I essentially have two independent effect signal chains.