No description
Find a file
Pim Kunis 2b38e95436 Spawn the player server using the given options
Pass start_link arguments to MIDISynth
Simplify event creation
2020-10-14 13:01:21 +02:00
lib Spawn the player server using the given options 2020-10-14 13:01:21 +02:00
test Spawn the player server using the given options 2020-10-14 13:01:21 +02:00
.formatter.exs Init repository. 2020-10-10 19:36:07 +02:00
.gitignore Change name from tools to player. 2020-10-12 16:17:36 +02:00
LICENSE Create LICENSE 2020-10-12 20:24:08 +00:00
mix.exs Spawn the player server using the given options 2020-10-14 13:01:21 +02:00
mix.lock Add documentation and type checking. 2020-10-11 13:40:12 +02:00
README.md Spawn the player server using the given options 2020-10-14 13:01:21 +02:00

MIDIPlayer

A MIDI player for Elixir.

Prerequisites

Install FluidSynth to play MIDI commands:

On Linux:

sudo apt install libfluidsynth-dev

On OSX:

brew install fluidsynth

Clone this repo or put the Hex dependency in your mix.exs:

{:midi_player, "~> 0.2.0"}

Examples

MIDIPlayer takes "events" which for example represent to play a note for a time span. It then converts these events to MIDI commands and schedules them.

First, let's create some events. This plays a piano sound for the C note for 1 second:

iex> piano = MIDIPlayer.Event.note(0, 60, 0, 1000, 127)

We can change the instrument to a violin after one second like so:

iex> change = MIDIPlayer.Event.change_program(0, 1000, 41)

(Note that it could be simpler to use another MIDI channel for another instrument.)

Finally, play two notes on the violin at the same time:

iex> violin1 = MIDIPlayer.Event.note(0, 67, 1000, 3000, 127)
iex> violin2 = MIDIPlayer.Event.note(0, 64, 1000, 3000, 127)

Now we are ready to play these events. First start the player like so:

iex> {:ok, player} = MIDIPlayer.start_link([])

Then load the events, and play them!

iex> MIDIPlayer.generate_schedule(player, [piano, change, violin1, violin2], 3000)
iex> MIDIPlayer.play(player)

Thanks

This project uses MIDISynth for generating MIDI commands and operating the FluidSynth synthesizer. It also uses Timex for timing related functionality. Inspiration from Beats.