Arduino MIDI Library v4.0 beta

I’m starting the beta of the Arduino MIDI Library version 4.0.

It includes the following changes:

  • Support for SoftwareSerial
  • Multiple instances (a merger demo has been added to the examples)
  • Refined build options
  • Support for other targets than Arduino

If you’re interested, you can clone the release/4.0 branch of the GitHub repository, or download the latest snapshot. If you find any issue, please report them to beta@fortyseveneffects.com.

  • Tyler Darlington

    Hey there,

    I know this might be a simple question but is this a way to make the Arduino act a midi interface? Is there to email someone about some other midi code help?

  • Victor

    Hi, i’m working with your library but i have one problem. (Midi Library 3.2 and 4.0)
    The thing is that my arduino send the midi message but doesn’t send the channel.

    http://pastebin.com/YDumPxcR
    Thats my code.

    For example, when a push one button the hexadecimal code that i receive is: “46 7F”
    46= is the note, 7F=Velocity…..but where is the channel?

    • Francois

      Hi Victor,

      You’re sending Control Changes, not NoteOn, but the reason why you don’t receive the status message is because Running Status is activated. It means that when you send two successive messages with the same status (same type and on the same channel), which is your case (only CCs on channel 1), the status byte will be sent once, then only the data bytes will be sent. It goes on until you send another message type or on another channel, which requires sending the status message again.

      This behaviour is part of MIDI specification, and is the reason why some synths send a NoteOn with null velocity as note off, to make the most of the Running Status feature (therefore sending only Note and Velocity bytes, until something else needs to be sent). This saves one third of the bandwidth, which is interesting for performance since the MIDI baudrate is quite low.

      If this messes with your code, you can disable it in the MIDI.h header (version < 4.0) or in midi_Settings.h (version 4.0). Just set USE_RUNNING_STATUS to 0 and all status messages will always be sent. Hope this helps.

  • Victor

    Thanks so much, now it works!!!
    If i try with NoteOn (and running status 1) is gonna have a better performance?

    • Francois

      NoteOn and ControlChange messages are both 3 bytes long, and using running status will cut it to two. Therefore it will not yield any performance improvement to change from CCs to notes, you can keep your code as is.

      However, if your reading code supports running status for notes (which seems unlikely since it does not support it for CCs), you could gain performance by doing what you said.

  • Sjaak

    Hi,

    Does version 4 support the Arduino DUE?

    SJaak

    • Francois

      I’ll have to check, but if Due supports the HardwareSerial interface just like any other Arduino, then yes it should work like a charm :)

  • http://deseipel.blogspot.com Dan Seipel

    HI, does the MIDI library support opening of MIDI files?

  • http://fishparts.com Warren Gill

    V3.2 works out of the box with no changes on MSP430’s. I did a little
    “MIDI translator” using Energia on the Launchpad, with RobG’s MIDI Booster Pack Kit. https://www.tindie.com/products/RobG/midi-booster-pack-kit/
    Can’t wait to play with 4.0!

    • Roger

      Warren,
      How did you get it to work?
      I have been trying to get my MIDI Booster Pack to work with Energia with no luck.
      I have tried using straight Serial.read procedures, and the MIDI 3.2 and 4.0 Libraries.
      Great work in in this effort!

  • http://fishparts.com Warren Gill

    Question on the V4. merge example: What happens when MIDI stream A is sending in Running Status mode, and MIDI stream B comes in on a different MIDI channel?

    • Francois

      Well both objects are independent, so running status should not be a problem. It will send back what comes in :)

  • dan

    Does this support software serial yet?

  • kolasni

    Hi,
    first of all I want to thank you for this excellent library. Really good job!!!
    I am using the 3.2 version and everything I try to do is really easy, but I need two distinct midi outputs on my arduino Mega 2560…
    I already changed the #define USE_SERIAL_PORT Serial
    to Serial1 (TX1 instead of default TX0) and all is OK. So is there any way to have two MIDI.h included in my sketch? If so, what changes should I make to the second MIDI.h (probably called MIDI1.h)? If not, do you have any suggestions for a hardware based solution (probably an IC relay)?

    • Francois

      Hi,

      In version 4 you will find the macro MIDI_CREATE_INSTANCE which will do what you want.
      You can see a demo with two MIDI ports, one using a hardware UART and one using a SoftwareSerial interface, in the DualMerger example available here:
      https://github.com/FortySevenEffects/arduino_midi_library/blob/release/4.0/res/Examples/MIDI_DualMerger/MIDI_DualMerger.ino

      • kolasni

        GREAT!!!!!!
        I just checked it for 4 hardware ports:
        //SoftwareSerial softSerial(2,3);// (RX, TX)
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiB);
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midiC);
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, midiD);
        etc
        I do not have the hardware to test it at the moment, but
        the compiler likes it!!!!
        If only there was an easy way to keep version3.2 too…Anyway, I will keep on swapping between versions until I find a more elegant solution (rewrite old sketches maybe?lol)
        Great job and many many thanks!!!

        • Francois

          Moving to 4.0 should be easy, the only sketch change required is to add the midi namespace (midi::) in front of enum values (NoteOn, ControlChange etc..)

  • Ajay

    Hi,
    Thanks a lot for the library.
    I am having some troubles in using it with Due. I am trying to listen to midi data on “Hairless MIDI”.
    The sketch compiles with this warning:
    MIDI_Basic_IO.cpp.o: In function midi::MidiInterface::begin(unsigned char)’:
    …Documents\Arduino\libraries\MIDI/MIDI.hpp:64: warning: undefined reference to `HardwareSerial::begin(unsigned long)’ **
    And Hairless MIDI gets stuck at opening port.

    Can you please suggest me a solution?
    Thanks

    • Francois

      Hi,

      Thanks for the feedback! I looked into it and it seems the Due works a bit differently than other boards regarding the serial ports available.

      I’ll try a fix and keep you up to date.

      • http://mubase1.tumblr.com/ mubase

        cant use the midi library with uino Due.
        In function midi::MidiInterface::begin(unsigned char)’:
        …Documents\Arduino\libraries\MIDI/MIDI.hpp:64: warning: undefined reference to `HardwareSerial::begin(unsigned long)’

        I removed all midi messages out of the sketch with only MIDI.begin(); in the setup. so i realised it is a Due hardware serial problem. i tried a number of options but with no joy – i have a deadline in 10days using midi to send sensor data to a synth in Processing.

        • Francois

          The examples compile fine on Arduino 1.5.6-r2 for Due (both Serial and USB options). Can you try updating to the latest Arduino IDE and check again?
          Thanks !

  • laurent

    Hi,

    I wrote a sketch using v4 and MIDI CREATE INSTANCE
    I started with Serial (Rx0 and Tx0)
    Everything’s work fine

    Then I decided to use Serial2 , and I just replaced Serial with Serial2 in the MIDI CREATE INSTANCE

    Midi out works fine but Midi in doesn’t work anymore

    Did I miss something?

    • Francois

      Hi Laurent,

      That’s strange, have you checked your connections? What board are you using?

      Thanks.

      • laurent

        I use an arduino mega 2560
        My connection seems good
        I tried also with Serial3 but same problem
        TX Ok, RX NOK

        • Francois

          Ok, can I have a look at your sketch to try and reproduce it on my end?
          Thanks !

  • Moritz

    Thanks Francois for putting this up, works great so far and you implemented a lot of stuff I missed in the 3.2 release!! Thumbs up!!
    What I couldnt find out: is there a way to receive midi note “on”s with “0” velocity and interprete them as a note off? A lot of controllers do this .. I can of course do it manually but would like to automate it? Any hints?

  • Chris

    Hi,

    may someone explain me how to switch from serial_0 to serial_1 for an MIDI_input?

    Arduino MEGA 2560.

    Thanks!

    Greetz Chris

    • Francois

      Hi Chris,

      You can change the default MIDI port in midi_Settings.h, line 54.

  • Laurent

    Hi / Salut !
    I’m trying to use the soft serial ability of your library, but I can’t even get the example to work (bench.ino). I’m using the raw example, didn’t modified a line, plugged my midi in on pin 2. I get the “Arduino Ready” message but nothing happens when I press my keyboard’s keys. When I upload midicallbacks.ino and plug midi in on Tx0, it is working very well though.
    What am I doing wrong ?

    • Francois

      Hi Laurent,

      I fixed the examples recently, some of them (including bench) were not working at all.
      Can you please check out the dev branch on GitHub and see if it works better?
      Thanks!

      • Laurent

        Hi François,

        It works perfectly with the dev branch files !
        Thank you for this awesome library !