Midi_synth: a software MIDI synthesizer

I’ve been playing around with libfluidsynth which is a software MIDI synthesizer. The nice part (for me at least) is that it can play notes without any additional hardware and the software setup is simple once you get libfluidsynth and a soundfont installed.

I’m finding that I don’t have time to do justice to a music library in Elixir and I don’t think that I have the musical background to do it anyway. It has been a lot of fun, though, so I packaged up the raw MIDI interface and posted it at https://hex.pm/packages/midi_synth.

The library doesn’t have a sequencer. You just give it MIDI commands and it immediately runs them. Thanks to Elixir’s binary syntax, this is actually not too bad to work with. There is some example code to get you started. Please read the README.md for getting libfluidsynth and a soundfont file.



I wrote a code that generate music of Takeuchi function.
Thank you for good library.


This is great! Thank you for posting.

You have motivated me to clean up and improve the source code for the library. I will publish updates soon.



I just released midi_synth v0.3.0 which is a substantial update to the library. Unfortunately, it is completely backwards incompatible with v0.2.0, but on the plus side, it fixes quite a few big mistakes I made a couple years ago.

The main module, MIDISynth, only handles low level MIDI commands now. I moved the helper functions for playing simple songs and for encoding MIDI commands to other modules. My hope is that other libraries can build upon the flexibility of being able to send nearly any MIDI command to midi_synth and not be constrained the library. See the docs for examples. I think that the changes that need to be made to existing code are self-explanatory since the API was pretty small anyway.

Besides the name changes and API functions moving around, you now need to start a software MIDI synth yourself. You can do that by calling MIDISynth.start_link/1 manually or by including it in one of your supervision trees.

Other improvements include:

  1. All configuration is passed to MIDISynth.start_link/1. I removed the one use of the application environment, so you can now start up multiple synthesizers with different sound fonts if you want.
  2. C code gets built under _build. This sounds small, but it prevents a number of issues especially if anyone ever starts cross-compiling midi_synth for Nerves.
  3. The build system automatically downloads a Creative Commons-licensed general MIDI soundfont. This step could be improved, but at the moment, it simplifies getting started and this soundfont file is probably sufficient for most people.

I’ve tested this on OSX and Linux, and it seems to work. Of course, it’s audio, so Linux friends, please help if there are settings that you need tweaked or need to be exposed as user-configurable.