- Notifications
You must be signed in to change notification settings - Fork12
Elixir bindings to the portmidi library
License
NotificationsYou must be signed in to change notification settings
lucidstack/ex-portmidi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Need to catch up? Have a look at thechangelog! 🚀
ex-portmidi is a wrapper for thePortMidi C library,that provides some nice abstractions to (write to|listen on) MIDI devices.
Add portmidi to your list of dependencies inmix.exs
, and ensurethatportmidi
is started before your application:
def deps do [{:portmidi, "~> 5.0"}]enddef application do [applications: [:portmidi]]end
If needed, the input buffer size can be set, in yourconfig.exs
:
config :portmidi, buffer_size: 1024
By default, this value is 256.
To send MIDI events to a MIDI device:
iex(1)> {:ok, output} = PortMidi.open(:output, "Launchpad Mini"){:ok, #PID<0.172.0>}iex(2)> PortMidi.write(output, {176, 0, 127}):okiex(3)> PortMidi.write(output, {{176, 0, 127}, 123}) # with timestamp:okiex(4)> PortMidi.write(output, [iex(5)> {{176, 0, 127}, 123},iex(6)> {{178, 0, 127}, 128}iex(7)> ]) # as a sequence of events (more efficient):okiex(8)> PortMidi.close(:output, output):ok
To listen for MIDI events from a MIDI device:
iex(1)> {:ok, input} = PortMidi.open(:input, "Launchpad Mini"){:ok, #PID<0.103.0>}ex(2)> PortMidi.listen(input, self):okiex(3)> receive do...(3)> {^input, event} -> IO.inspect(event)...(3)> end{144, 112, 127}iex(4)> PortMidi.close(:input, input):ok
To list all connected devices:
ex(1)> PortMidi.devices%{input: [%PortMidi.Device{input: 1, interf: "CoreMIDI", name: "Launchpad Mini", opened: 0, output: 0}], output: [%PortMidi.Device{input: 0, interf: "CoreMIDI", name: "Launchpad Mini", opened: 0, output: 1}]}
For more details,check out the Hexdocs.
About
Elixir bindings to the portmidi library
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published