Simple MIDI input/output library (via GPIO pins)?

Is there a library for sending and receiving MIDI data via the GPIO pins?

I know there are Arduino equivalents such as themidibus - and I found this C++ MIDI library:

…but it seems somewhat excessive for the Spark Core.

Any suggestions for simple MIDI note handling (single-channel) would be greatly appreciated.

I also just stumbled on this:

It’s a MIDI library for the Leaf Labs Maple which also runs on an STM32F103

@sneakthief, the MapleMidi library appears quite easy to port to the Core. Let me know if you need help :smile:

1 Like

@peekay123 - thanks for the offer! Are you sure it’s as easy as you suggest?

Porting is always a bit of a rabbit hole - the following libraries are recursively referred to:

Initializing the gpio’s might be easier via this code courtesy Mutable Instruments.

This device is a MIDI to CV (control voltage) converter and is also based on the STM32F103:

The MIDI handler however is simply too complex:

…etc.

@sneakthief, all the libraries you refer to are also found in the core firmware in one form or another. The HardwareSerial port is dependent on whether you use Serial1 or Serial2 (USART based) or Serial (USB based). All GPIO management is done with pinMode/digitalWrite/digitalRead or some lower level STM32 macros. Really, I see nothing there to prevent a port. :smile:

I’m trying to make a spark core controlled midi device, I have all the hardware together, I’m not sure how to use the arduino midi library with my code, there is no library in the online IDE for midi. When I try to get the code from github it says its incompatible?

I’m not sure what porting is, is it something I could do with limited programming knowledge? Has anyone been successful in making a core-friendly midi library? I was looking into the Applemidi libraries on the web IDE also, I’m not sure what basic commands to use in my code though and I cant tell if I need to have an ethernet shield in order to use it or if it can be just over wifi. Would this Maplemidi be an easier route?

All of us that need a midi library really fall more on the artist/designer end of things--can any kind programmer please point us in the right direction for getting started with porting a midi library over? As I have project that I'm working that could benefit from having a working midi library--I like the Photon a lot and would rather use a Photon than an Arduino Yun--but my project is now leaning more towards the Arduino side of things because of some many readily available libraries.

To an artist/designer like me--porting a library seems like a daunting task--and I really would like to have my Photon to talk Midi--are there any pointers to porting an already established Midi library? What's the first step?

@ajmonkey, if you can identify a solid Arduino MIDI library that would fit the bill, I’ll look at porting it. :smile:

1 Like

Midi Library for Teensy
Is not for Arduino but expecially for Teensy and it works great!
Should you porting it in Photon?
:smile:

On first glance this doesn’t seem to require much porting.

If you just take that lib and replace the #include block in MIDI.h with this

#if defined(SPARK)
#include "application.h"
#else
#include <inttypes.h> 
#include <stdlib.h>
#include "Arduino.h"			// If using an old (pre-1.0) version of Arduino, use WConstants.h instead of Arduino.h
#include "HardwareSerial.h"
#endif

and also alter this in MIDI.h

//#if defined(CORE_TEENSY) // add Particle (formerly SPARK) support 
#if defined(CORE_TEENSY) || defined(SPARK)
#undef USE_SERIAL_PORT
#define USE_SERIAL_PORT         Serial1
#endif

and remove the includes (all but #include "MIDI.h") from the MIDI.cpp file, it at least builds.

I have no hardware to test it tho’.

You might experience some problems if you are running “cloud-bound” though too, so try SYSTEM_MODE(MANUAL) in the examples to start with.

If you could help us artists port over the Maple Midi library that would be super awesome :smile:

This looks fun! I have a few MIDI keyboards to test with, just need to find and splice some DIN cables.

The Photon is super nice for MIDI processing. I use it as a MIDI controller since quite a while for live gigs. It is very stable and has the processing power for all I need. That coupled with the WiFi for setup is really making a great solution. Initially I was using a Raspberry PI for that but that was not stable enough and I was just too worried what happens if it crashes and then it takes a while to reboot. The Photon is much better for that. I used it in many gigs and it never crashed and even if it would it would recover practically immediately. So I can only encourage people to use the Photon for that.

I considered the above libraries but ended up rolling my own because in the end that was just simpler. Now I am really happy about that because it is very flexible and I now have a Photon based controller box which implements a master keyboard controller, a MIDI converter, a sequencer, a looper, and some more things. It even allows switching the synth sounds without interruption. Add an OLED and a couple of buttons and you have something really flexible. And it has an HTTP server built-in which can be used for configuring things. That part is not very far though…

The one thing it is missing is USB host functionality. So I have to use good old MIDI, USB might be nicer…

2 Likes

Would you share your library if not already shared?

1 Like

I am certainly planning to do that at some point. At this point there is just too much stuff which is specific for my setup. I have to refactor that, so that it is useful beyond my needs. I could rip out the actual basic MIDI handling (it is really not that much), but I am not sure how useful that is.

+1 request for a ported MIDI library - unless there’s one available since this topic was started?