Tag: #midi

  • MIDI Mustard

    For my gig at Thee Sunday Sonics this weekend I decided to make a new USB controller. I was previously using one with many more buttons and knobs than I actually needed. For this project I used the Teensy LC. A low cost version of the Teensy (around £10). It has less memory and computation power than the 3.2, but more than enough to make a simple USB MIDI controller. I used a mustard tin to house it all in. It’s suspended inside using these. It worked a treat in practise but for some reason on the night of the gig (typically), in soundcheck it stopped working and seemed to be interfering with my other controllers. Luckily I bought my previous controller as a spare. Still not entirely sure what the issue was (it works fine again now). My best guess is that there was some form of power issue. I’m hoping to be able to recreate in an environment that not on-stage so I can actually resolve it.

     

     

    Once I’d reverted to my spare everything was fine, and the gig went well. Thanks to Thee Sunday Sonics for inviting me, it was lots of fun.

     

    [EDIT] I’m fairly confident I’ve solved the problem. The software wasn’t consuming and discard MIDI messages it received, only sending its own messages. Updated code on GitHub

  • MIDI pedal complete!

    After some soldering and drilling I’ve finished the final version of my MIDI pedal. I’m really pleased with how it’s turned out. I’ve used it live now, and it was really handy having LEDs to show which pedals I had active, and I can now control Ableton’s looper more accurately. I’m less convinced by the usefulness of the MIDI clock LED flash, it’s in equal amounts useful and distracting. Never mind, it’s easy to disable in code if I choose.

    I tried to make the layout of my breadboard prototype as close as possible to the layout I was going to use on the Veroboard. Soldering this together was pretty straightforward, and although it looks a little untidy it worked first time (ok, second time, I had to solder suck some of the solder from one of the joints as it was connecting 2 rails together).

    The build went reasonably smoothly. I used InkScape to create a drilling schematic. The only problem was I didn’t factor in the size of the components (only the size of the drill holes), meaning it was only by chance that the bodies of the potentiometers didn’t overlap the USB port – phew! I then marked each centre point with an awl, before drilling a small pilot hole, and then cutting the desired hole size with the hole cutter. This may well be the de-facto drilling technique, not sure, but it worked for me.

     

    Pre-drilling
    Pre-drilling
    guts
    Guts!
    finished
    Finished article

     

    The code is now slightly more complex. LEDs can be paired together allowing the activation of one to toggle the state of another (called a sister pedal in the code). This is because 2 of my pedals control the activation of the ‘Record Arm’ on 2 audio tracks that output to the same channel on my Audio Interface (basically 2 different guitar amps, which can play simultaneously but only one can be receiving audio). Activating one ‘Record Arm’ disables the other.

    Code available on GitHub https://github.com/cutlasses/MidiPedal

  • MIDI pedal prototype complete

    The prototype of my USB MIDI pedal is now complete. What you see below is prototyped on breadboard using the TEENSY development board, running software which I wrote in C/C++. It has 4 fully programmable pedal switches (either toggle or momentary), and an LED which flashes in time with the midi clock. This clock LED is to enable me to record loops without the need for headphones (I have not actually tried doing this). The next stage will be to solder it up on veroboard and build the housing. The enclosure has arrived, just need to do some drilling!

     

    Once this is finished I’ll have more control over my live performance. My previous MIDI pedal was not programmable, and therefore I was somewhat restricted. With this I’ll be able to have more control over my live looping.

     

    breadboard
    Prototype on breadboard
    Enclosure
    Painted aluminium enclosure

     

     

    Here’s the source code for those interested.

    #include 
    
    #define MIDI_CHANNEL        1
    #define MIDI_CLOCK          248
    #define MIDI_START          250
    #define MIDI_CONTINUE       251
    #define MIDI_STOP           252
    #define PULSES_PER_QUARTER  24
    
    #define NUM_PEDAL_SWITCHES  4
    
    #define MIDI_CLOCK_LED      4     
    
    #define BOUNCE_TIME         10
    
    int midi_counter(0);
    
    struct PEDAL_SWITCH
    {
      int                   m_pedal_pin;
      int                   m_led_pin;
      int                   m_midi_cc;
      bool                  m_is_toggle;
      bool                  m_active;
    
      Bounce                m_bounce;
    
      PEDAL_SWITCH( int pedal_pin, int led_pin, int midi_cc, bool is_toggle ) :
        m_pedal_pin( pedal_pin ),
        m_led_pin( led_pin ),
        m_midi_cc( midi_cc ),
        m_is_toggle( is_toggle ),
        m_active( false ),
        m_bounce( pedal_pin, BOUNCE_TIME )
      {
      }
    };
    
    PEDAL_SWITCH pedals[ NUM_PEDAL_SWITCHES ] = { PEDAL_SWITCH( 0, 5, 16, true ),
                                                  PEDAL_SWITCH( 1, 6, 17, true ),
                                                  PEDAL_SWITCH( 2, 7, 18, true ),
                                                  PEDAL_SWITCH( 3, 8, 19, false ) };
    
    void setup()
    {
      pinMode( MIDI_CLOCK_LED, OUTPUT );
      
      for( int i = 0; i < NUM_PEDAL_SWITCHES; ++i )
      {
        const PEDAL_SWITCH& pedal = pedals[i];
        
        pinMode( pedal.m_pedal_pin, INPUT_PULLUP );
        pinMode( pedal.m_led_pin, OUTPUT );
      }
      
      usbMIDI.setHandleRealTimeSystem( midi_real_time_event );
    
      midi_counter = 0;
    }
    
    void midi_real_time_event( byte data )
    {
      switch( data )
      {
        case MIDI_CLOCK:
        {
          ++midi_counter; 
      
          if( midi_counter == PULSES_PER_QUARTER )
          {
            midi_counter = 0;
            digitalWrite( MIDI_CLOCK_LED, HIGH );
          }
          else if( midi_counter == PULSES_PER_QUARTER / 2 )
          {
            digitalWrite( MIDI_CLOCK_LED, LOW );
          }
    
          break;
        }
        case MIDI_START:
        case MIDI_CONTINUE:
        {
          midi_counter = 0;
          
          digitalWrite( MIDI_CLOCK_LED, HIGH );
    
          break;
        }
        case MIDI_STOP:
        {
          digitalWrite( MIDI_CLOCK_LED, LOW );
          
          break;
        }
      }
    }
    
    void loop()
    {
      usbMIDI.read();
    
      for( int i = 0; i < NUM_PEDAL_SWITCHES; ++i )
      {
        PEDAL_SWITCH& pedal = pedals[i];
    
        pedal.m_bounce.update();
    
        if( pedal.m_bounce.fallingEdge() )
        {
           /*Serial.print("pedal down ");
           Serial.print(i);
           Serial.print("n");*/
    
           if( pedal.m_is_toggle )
           {
            pedal.m_active = !pedal.m_active;
           }
           else
           {
             pedal.m_active = true;
           }
    
           usbMIDI.sendControlChange( pedal.m_midi_cc, 127, MIDI_CHANNEL );
        }
        else if( pedal.m_bounce.risingEdge() )
        {
          /*Serial.print("pedal up ");
          Serial.print(i);
          Serial.print("n");*/
    
          if( !pedal.m_is_toggle )
          {
            pedal.m_active = false;
    
            usbMIDI.sendControlChange( pedal.m_midi_cc, 0, MIDI_CHANNEL );
          }
        }
    
        if( pedal.m_active )
        {
          digitalWrite( pedal.m_led_pin, HIGH );
        }
        else
        {
          digitalWrite( pedal.m_led_pin, LOW );
        }
      }
    }