Create readme.

This commit is contained in:
Pim Kunis 2020-10-12 21:00:31 +02:00
parent db2a5c0676
commit 4ca35fa411
2 changed files with 52 additions and 13 deletions

View file

@ -1,21 +1,57 @@
# MIDIPlayer # MIDIPlayer
**TODO: Add description** A MIDI player for Elixir.
## Installation ## Prerequisites
If [available in Hex](https://hex.pm/docs/publish), the package can be installed Install FluidSynth to play MIDI commands:
by adding `midi_player` to your list of dependencies in `mix.exs`:
```elixir On Linux:
def deps do
[ ```sh
{:midi_player, "~> 0.1.0"} sudo apt install libfluidsynth-dev
]
end
``` ```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) On OSX:
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/midi_player](https://hexdocs.pm/midi_player).
```sh
brew install fluidsynth
```
## Examples
First, let's create some events.
This plays a piano sound for the C note for 1 second:
```elixir
iex> piano = MIDIPlayer.Event.Note.new(0, 60, 0, 1000, 127)
```
We can change the instrument to a violin after one second like so:
```elixir
iex> change = MIDIPlayer.Event.ChangeProgram.new(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:
```elixir
iex> violin1 = MIDIPlayer.Event.Note.new(0, 67, 1000, 3000, 127)
iex> violin2 = MIDIPlayer.Event.Note.new(0, 64, 1000, 3000, 127)
```
Now we are ready to play these events.
First start the player like so:
```elixir
iex> MIDIPlayer.start_link()
```
Then load the events, and play them!
```elixir
iex> MIDIPlayer.generate_schedule([piano, change, violin1, violin2], 3000)
iex> MIDIPlayer.play()
```

View file

@ -5,6 +5,9 @@ defmodule MIDIPlayer do
A GenServer for playing a schedule of MIDI commands at predefined times. A GenServer for playing a schedule of MIDI commands at predefined times.
""" """
# TBD: I think cancelling the timer could introduce a race condition.
# Could maybe match timer's reference to saved one?
@type schedule :: [{non_neg_integer(), binary()}] @type schedule :: [{non_neg_integer(), binary()}]
# Client API # Client API