Skip to content

Commit

Permalink
Merge pull request #23 from kamtoeddy/add_midi_control_change
Browse files Browse the repository at this point in the history
Implement MIDI Control Change
  • Loading branch information
abbysmal authored Apr 2, 2023
2 parents 55819c1 + e9527c6 commit 5bb018c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/midi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ let bend_pitch ~bend ~timestamp ~channel =
let data2 = char_of_int (bend lsr 7) in
Event.create ~status ~data1 ~data2 ~timestamp

let control_change ~cc ~value ~timestamp =
if cc > 119 then invalid_arg "Sorry, [cc] must be <= 119"
else
let data1 = char_of_int (cc land 0b1111111) in
let data2 = char_of_int (value land 0b1111111) in
Event.create ~status:'\176' ~data1 ~data2 ~timestamp

(* Best function ever!! <3 *)
let handle_error = function Ok _ -> () | Error _ -> ()

Expand Down
6 changes: 6 additions & 0 deletions bin/midi.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ val message_off :
note:char -> timestamp:int32 -> volume:char -> channel:int -> unit -> Event.t

val bend_pitch : bend:int -> timestamp:int32 -> channel:int -> Event.t

val control_change : cc:int -> value:int -> timestamp:int32 -> Event.t
(** This helps to send MIDI Control Change messages
@raise Invalid_argument if [cc] is greater than 119 *)

val write_output : Device.t -> Portmidi.Portmidi_event.t list -> unit

module Scale : sig
Expand Down

0 comments on commit 5bb018c

Please sign in to comment.