Skip to content

Commit

Permalink
Generalised batch parameters to support any metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Aug 10, 2021
1 parent 86f5184 commit c23a109
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/midimsg.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
%%%% The messages in this library were originally designed to interoperate with
%%%% a Golang MIDI server (https://github.com/geomyidia/midiserver/) via Erlang
%%%% Ports. The underlying MIDI library has messages defined here:
%%%% * https://gitlab.com/gomidi/midi/-/blob/master/writer/messages.go
%%%% and it was the function arguments defined there that shaped the messages
%%%% in this module, with some corrections on terminology (it's "pitch" not
%%%% "key").
%%%%
%%%% That being said, the message data produced by this module's functions
%%%% should be sufficient to work with any low-level MIDI library in any
%%%% language.
-module(midimsg).
-export([
batch/1,
Expand Down Expand Up @@ -56,15 +67,14 @@
]).

batch(Msgs) ->
batch(Msgs, uuid:get_v4_urandom()).
batch(Msgs, [{id, uuid:get_v4_urandom()}]).

%% Iterate through all the Msg (tuples with 'midi' as the first element),
%% drop the first element, add the second to a list, and put that list into
%% the payload.
batch(Msgs, Id) ->
batch(Msgs, Metadata) ->
Batch = [Payload || {midi, Payload} <- Msgs],
{midi, {batch, [{id, Id},
{messages, Batch}]}}.
{midi, {batch, lists:append(Metadata, [{messages, Batch}])}}.

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Meta Messages %%%%%
Expand Down

0 comments on commit c23a109

Please sign in to comment.