RTMIDI庫的長生不老藥包裝紙。部分受Python-rtmidi的啟發。
警告:該庫被認為是實驗性/阿爾帕之前的,直到解決以下一些問題。
如果您想提供幫助,請考慮檢查“問題”選項卡。
該庫的工作原理,但我不是C ++程序員。歡迎任何貢獻,但在這些特定領域的幫助將有很長的路要走:
C ++
src/ex_rtmidi_{output,input}.cpp可以更好地利用OOP和模板來減少代碼重複src/ex_rtmidi_input.cpp中的input_callback和attach_listener需要一個好外觀。同樣,預先一個重構是可以選擇的detach_listener如果沒有聽眾長生不老藥
init方法比NIF的建議需要更長的時間。請參閱lib/ex_rtmidi/{output,input}.ex註釋openVirtualPortMix.Tasks.Compile.Rtmidi移出mix.exs 。請參閱mix.exs中的評論一般的
C ++是一種OO語言,而長生不老藥不是。我對是否在功能上表達更大的表達或與OO慣例一致。最後,選擇了一種更具功能的方法。
為了創建一個RTMIDI實例,使用實例標識符調用init方法。在C ++中,實例作為一個值存儲在標識符為密鑰的地圖中。未來對RTMIDI實例方法的調用需要傳遞標識符,以了解要定位的實例。
NIFS主要是Erlang構造,因此您會看到Elixir包裝紙對Charlist進行了很多匯聚。這是因為Erlang的字符串是Elixir中的Charlist,因此NIF字符串方法實際上採用並返回Charlists而不是String.t() 。
輸入端口上的聽眾將C ++作為PID傳遞。收到消息後,NIF解析並將消息傳遞到異步到指定的PID。
直到解決了一些更緊迫的C ++問題之前,我不想推廣此圖書館以供公眾使用。在此之前,您必須從Github獲得它:
def deps do
[
{ :ex_rtmidi , git: "https://github.com/kieraneglin/ex_rtmidi" }
]
end 當前,該庫採取比您預期的更簡單的處理消息方法。您可能會從小型包裝器中獲得價值,這些包裝器在發送和解析針對用例的量身定制的消息中獲得了價值。
我概述了一些基本用例,但是您應該看到lib/ex_rtmidi/{output,input}.ex 。
alias ExRtmidi.Output
{ :ok , instance } = Output . init ( :my_instance_name ) # Instance name can be whatever you want - it's unrelated to available MIDI devices
Output . get_port_count ( instance )
# iex> {:ok, 2}
Output . get_ports ( instance )
# iex> {:ok, ["IAC Midi", "Dummy MIDI"]}
Output . open_port ( instance , 0 ) # Or `Output.open_port(instance, "IAC Midi")`
# iex> :ok
Output . send_message ( instance , [ 0x90 , 60 , 100 ] )
# iex> :ok
Output . close_port ( instance )
# iex> :ok有一個用於MIDI消息的包裝器可以改善創建消息的體驗。這主要用於輸出,尚未移植以解構傳入消息(請參閱“需要的幫助”部分)。
有關消息的完整列表,請參見lib/ex_rtmidi/message/spec.ex 。
alias ExRtmidi.Output
alias ExRtmidi.Message
# Assume `init` has been run and a port has been opened as in the instance above
message = Message . compose ( :note_on , channel: 0 , note: 60 , velocity: 100 )
Output . send_message ( instance , message ) # In midi_input_server.ex
defmodule MidiInputServer do
use GenServer
def init ( state \ [ ] ) do
{ :ok , state }
end
def handle_info ( { :midi_input , midi_message } , state ) do
IO . inspect ( midi_message )
{ :noreply , state }
end
end
# In another file
alias ExRtmidi.Input
# Much of setup including init, listing ports, and opening a port is the same as in the Output example above.
# Setup will be omitted for brevity. Assume we have an instance at our disposal.
{ :ok , midi_listener_pid } = GenServer . start_link ( MidiInputServer , [ ] )
# You should attach the listener before opening the port to ensure no messages get missed
Input . attach_listener ( instance , midi_listener_pid )
# iex> :ok
Input . open_port ( instance )
# iex> :ok
# Messages will be handled from this point on
# When you're done, be sure to detatch the listener before closing the port
Input . detatch_listener ( instance )
# iex> :ok
Input . close_port ( instance )
# iex> :ok 版權2021
特此免費授予獲得此軟件副本和相關文檔文件副本(“軟件”)的任何人,以無限制處理該軟件,包括無限制的使用權,複製,複製,修改,合併,合併,發布,分發,分發,分發,訂婚,和/或允許軟件的副本,並允許對以下條件提供以下條件,以下是以下條件。
上述版權通知和此許可通知應包含在軟件的所有副本或大量部分中。
該軟件是“原樣”提供的,沒有任何形式的明示或暗示保證,包括但不限於適銷性,特定目的的適用性和非侵權的保證。在任何情況下,作者或版權持有人都不應對任何索賠,損害賠償或其他責任責任,無論是在合同,侵權的訴訟中還是其他責任,是由軟件,使用或與軟件中的使用或其他交易有關的。