midi controller for ableton help writing code

Status
Not open for further replies.
i'd like to be able to connect multiple audio/midi sources to ableton, and each source have it's own separate footswitch control of record on/off, play/mute on/off (with each clip being synced in terms of tempo). essentially so multiple instruments can be added to the loop, with each instrument having separate controls as to when to record and when the loop plays. all that is fine, i've used tutorials to get everything together, and the switches/buttons are working fine and showing up in ableton etc etc.

but i'd also like to have each footswitch have an LED, so you know if you are recording (red), if the clip is playing (green), etc. i can't find any good instructionals online for how to get the teensy to read info from ableton. i'm a little surprised this project hasn't been uploaded by someone else because it seems pretty obvious (footswitch controller with an LED notification light).

can anyone point me to some code that will pull info from ableton, specifically when a track looper is recording, etc? if it doesn't exist, i'd be willing to pay someone to write the code for me.
 
You would only be able to do this if ableton sends notes to the Teensy, you could probably try to write your own midi device config such as the Novation Launchpad. This way ableton knows what to send to your controllers and you use that to turn an led on or off, I feel like there may be an easier way but I can’t remember right now.
 
i've seen a bunch of blogs mention the PrintIncoming command. Actually referring to File > Examples > Teensy > USB_MIDI > PrintIncoming, but for whatever reason i dont have that example in my version of teensy
 
Yes you can use that to see what midi commands are being sent to the Teensy, but unless Ableton is actually sending something to it nothing will show up. Most DAWs aren’t normally configured to send midi back to a generic midi device unless it has a file telling it that it should send and what to send. You should be able to look at one of the other midi device files and get an idea of how to write your own for the teensy, at least from what I remember, I only briefly looked in to it at the time.
 
that makes sense. as an alternative i could just program the teensy to light up the LED instead of trying to get that signal from the PC.

as someone who has little to no knowledge of programming, can someone point me in the right direction to a tutorial for have an LED light up on a button press?
 
well just to keep it simple:

Code:
if ( digitalRead(buttonPin) == 0 ) digitalWrite(13,HIGH);
else digitalWrite(13,LOW);

this would turn the led on when your button is pressed, and turn it off when released
 
ok, fair enough.

any chance you'd want to do some coding for a fee? i've tried getting into programming a couple of times and it just doesn't stick for me.
 
... referring to File > Examples > Teensy > USB_MIDI > PrintIncoming, but for whatever reason i dont have that example in my version of teensy

In Arduino, click Help > About to check which version you have. Or on Mac, it's Arduino > About.

The USB MIDI stuff was updated with version 1.41. If you have an older version, all you need to do is get 1.41 or the latest beta. You can run the new installer on your copy of Arduino that already has the old version.

MIDI got so many improvements going from 1.40 to 1.41 that you really owe it to yourself to update. The new stuff is greatly improved, even with virtual cables.
 
Yeah but you got more experience than I do :p I only started like 4 years ago with a mega blinking a led lol
 
@OP

How many switches?
Do they all latch?
Just CC with off and on values?

If the answers are: 'fewer than pins', 'yes' and 'yes' then it should not be difficult to whip up some code.

A 'state' array variable that stores the current setting can also double as the LED state, which simplifies coding and opens possibilities for running LED code at a much diminished refresh rate and to use a multiplexer or shift register to control the display LEDs with fewer pins than the number of switches.

If all switches latch then you only need one edge (falling) from the bounce objects when debouncing. This simplifies coding as you just toggle the state and send off/on (0/127).

So a 'CCnumber' array for D1 and a 'state' array for D2 and you send.

usbMIDI.sendControlChange(CCnumber, state, channel);

For i < NUM_SWITCHES

A pins array can map your pins to your switches or you can use an index variable if the pins are sequential.
 
Ah... I see I may have mis-read the LED part. I thought you wanted an ON indicator for each latching footswitch.

Hopefully I'm not too off base on the rest

Here's some untested code... it's based on my 'many knobs and buttons' example code (with the analog parts stripped out) and on previous experience with latching so it might just work as is... It did compile and since it's just switches I can test a with a bare Teensy but I just don't have one handy ATM.

Code:
/* latching buttons

based on many pots and buttons example code
*/


//************LIBRARIES USED**************
// include the Bounce library for 'de-bouncing' switches -- removing electrical chatter as contacts settle
#include <Bounce.h> 
//usbMIDI.h library is added automatically when code is compiled as a MIDI device

// ******CONSTANT VALUES******** 
// customize code behaviour here!
const int channel = 1; // MIDI channel
const int D_PINS = 6; // number of Digital PINS

// define the pins and CC numbers for digital events
const int DIGITAL_PINS[D_PINS] = {0,1,2,3,4,5}; // these don't need to be sequential
const int CCnumber[D_PINS] = {20,31,22,23,24,25}; // D1 - CC number
const int BOUNCE_TIME = 7; // 5 ms is usually sufficient


//******VARIABLES***********
int state[D_PINS] ; // off and on values toggled in code before sending CC message

//************INITIALIZE LIBRARY OBJECTS**************


// initialize the bounce objects 
Bounce digital[] =   {
  Bounce(DIGITAL_PINS[0],BOUNCE_TIME), 
  Bounce(DIGITAL_PINS[1], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[2], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[3], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[4], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[5], BOUNCE_TIME)/*,
  Bounce(DIGITAL_PINS[6], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[7], BOUNCE_TIME),*/
}; 

//************SETUP**************
void setup() {
// loop to configure input pins and internal pullup resisters for digital section
  for (int i=0;i<D_PINS;i++){
    pinMode(DIGITAL_PINS[i], INPUT_PULLUP);
  }
}

//************LOOP**************
void loop() {
  getDigitalData();
  // add an update routine for LEDs 
  while (usbMIDI.read()) {
     // controllers must call .read() to keep the queue clear even if they are not responding to MIDI
  }
}


//************DIGITAL SECTION**************
void getDigitalData(){
  for (int i=0;i<D_PINS;i++){
  digital[i].update();
    if (digital[i].fallingEdge()) {
      if (state[i]) {
        state[i] = 0;
      }else{
        state[i] = 127;
      }
      usbMIDI.sendControlChange(CCnumber[i], state[i], channel);  
    }
  }
}
 
Last edited:
I don't have the switches assembled yet so I was going to test it with 3 switches on a bread board. Do I need a led driver or any other components?
 
Status
Not open for further replies.
Back
Top