haubie / midiex Goto Github PK
View Code? Open in Web Editor NEWCross platform Midi library in Elixir. Powered by midir, a Rust midi library and Rustler.
License: MIT License
Cross platform Midi library in Elixir. Powered by midir, a Rust midi library and Rustler.
License: MIT License
On Windows 11 using Elixir 1.17.2 and OTP 27.0.1 or Elixir 1.16.3 and OTP 26.2.5.2, I get this error when I run this script and it crashes the script.
Mix.install([{:midiex, "~> 0.6.1"}])
Midiex.ports()
Copying NIF from cache and extracting to _build/dev/lib/midiex/priv/native/midiex-v0.6.1-nif-2.15-x86_64-pc-windows-msvc.dll
Such an exciting project! Very keen to use Elixir to do some midi things.
I'm sure it's me doing something wrong, not Ableton, just not sure what... (First time generating midi with code)
When I run the following code, I can see that Ableton is receiving something (top right flashing icon while this code runs).
But I can't get Ableton to play (monitor) or record midi notes. I think I've done the necessary configuration, including selecting the appropriate midi "device" that has the expected name I gave to it. The midi track plays fine if I test with the computer keyboard.
Is there something obviously wrong with the code below? Intended to play middle-C for as long as the program runs (toggling every 250ms):
def testing_testing_123(device_name, nr_seconds \\ 5) do
IO.puts("Starting test, will run for #{nr_seconds} seconds...")
# List MIDI ports
Midiex.ports()
# Create a virtual output connection
piano = Midiex.create_virtual_output(device_name)
# Send to MIDI messages to a connection (Middle C, at full velocity)
# On channel "1" (bc. "91" and "81")
note_on = <<0x91, 60, 127>>
note_off = <<0x81, 60, 127>>
# Press and release C, twice a second.
for _n <- 1..(nr_seconds * 2) do
IO.puts("Middle C....")
Midiex.send_msg(piano, note_on)
:timer.sleep(250)
Midiex.send_msg(piano, note_off)
IO.puts("Middle C... again ...")
Midiex.send_msg(piano, note_on)
:timer.sleep(250)
Midiex.send_msg(piano, note_off)
end
IO.puts("Show's over!")
end
Not expecting support for Ableton, but maybe this gives a clue? Anything amiss here?
I'm so excited to find this library. Hoping to possibly add some contributions to documentation while testing. First thing I noticed was that you need to have the rust tools installed before you can run Mix.install(), once that dependency is handled, and a few other system packages have been installed it seems to work as prescribed. The errors are really nice from rustler.
In addition to running on a mac, I also want to run on a headless pi 4 but am hitting some issues when compiling.
iex -S mix
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]
==> midiex
Compiling 10 files (.ex)
Compiling crate midiex in release mode (native/midiex)
Compiling memchr v2.5.0
Compiling proc-macro2 v1.0.63
Compiling libc v0.2.138
Compiling quote v1.0.28
Compiling regex-syntax v0.6.28
Compiling unicode-ident v1.0.5
Compiling pkg-config v0.3.26
Compiling aho-corasick v0.7.20
Compiling alsa-sys v0.3.1
Compiling lib/midiex/backend.ex (it's taking more than 10s)
Compiling bitflags v1.3.2
Compiling void v1.0.2
Compiling cfg-if v1.0.0
Compiling syn v2.0.22
Compiling unreachable v1.0.0
Compiling heck v0.4.0
Compiling rustler v0.29.0
Compiling lazy_static v1.4.0
Compiling regex v1.7.0
Compiling nix v0.24.3
Compiling alsa v0.7.0
Compiling rustler_sys v2.3.0
Compiling midir v0.9.1
Compiling rustler_codegen v0.29.0
Compiling midiex v0.1.0 (/home/pi/test/deps/midiex/native/midiex)
error[E0433]: failed to resolve: use of undeclared crate or module `coremidi`
--> src/lib.rs:11:5
|
11 | use coremidi::Notification::{ObjectAdded, ObjectRemoved};
| ^^^^^^^^ use of undeclared crate or module `coremidi`
error[E0432]: unresolved import `coremidi`
--> src/lib.rs:10:5
|
10 | use coremidi::{Client, Notification, AddedRemovedInfo, ObjectType};
| ^^^^^^^^ use of undeclared crate or module `coremidi`
Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `midiex` (lib) due to 2 previous errors
== Compilation error in file lib/midiex/backend.ex ==
** (RuntimeError) Rust NIF compile error (rustc exit code 101)
(rustler 0.26.0) lib/rustler/compiler.ex:41: Rustler.Compiler.compile_crate/2
lib/midiex/backend.ex:6: (module)
could not compile dependency :midiex, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile midiex", update it with "mix deps.update midiex" or clean it with "mix deps.clean midiex"
I believe that I should be able to not compile coremidi on a non mac platform and compile some other resource, but am unsure how to make the change.
Thanks again! ๐น โค๏ธ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.