...
 
Commits (2)
......@@ -34,7 +34,7 @@ Ubuntu/Debian.
On Nix, this may look like:
nix-shell -p pkg-config -p hidapi -p libjack2 --run 'dune build @install src/test/relay.exe'
nix-shell -p pkg-config -p libjack2 --run 'dune build @install src/test/relay.exe'
Tests
-----
......
profile=compact
......@@ -23,7 +23,6 @@
(* OTHER DEALINGS IN THE SOFTWARE. *)
(******************************************************************************)
(**
OCaml types and functions providing high level access to a jack midi
......@@ -33,10 +32,12 @@
*)
module Sequencer = struct
(** The sequencer object *)
type t
external make :
name:string -> input_ports:string array -> output_ports:string array -> t
= "ml_jackseq_make"
(**
The sequencer constructor
should be called as {[
......@@ -47,24 +48,18 @@ module Sequencer = struct
in
]}
*)
external make:
name: string -> input_ports: string array -> output_ports: string array -> t
= "ml_jackseq_make"
external close : t -> unit = "ml_jackseq_close"
(** Close the sequencer ({i ie} jack client) *)
external close:
t -> unit
= "ml_jackseq_close"
(** Put an event in the output buffer, it will be really output at next
jack frame (which means quasi immediately) *)
external output_event:
external output_event :
t -> port:int -> stat:int -> chan:int -> dat1:int -> dat2:int -> unit
= "ml_jackseq_output_event_bytecode" "ml_jackseq_output_event"
(** Put an event in the output buffer, it will be really output at next
jack frame (which means quasi immediately) *)
(** Get all events in input buffer and clear it *)
external get_input:
t -> (int*int*int*int*int) array
external get_input :
t -> (int * int * int * int * int) array
= "ml_jackseq_get_input"
(** Get all events in input buffer and clear it *)
end
open Printf
module Array = ArrayLabels
let prf fmt = ksprintf (printf "%s%!") fmt
let line fmt = ksprintf (prf "%s\n%!") fmt
let test_jack_seq () =
let test_jack_seq () =
let open Misuja in
let seq =
let input_ports =
Array.init 10 ~f:(sprintf "in%d") in
let output_ports =
Array.init 10 ~f:(sprintf "out%d") in
Sequencer.make
~name:"JackSeqTest" ~input_ports ~output_ports
let input_ports = Array.init 10 ~f:(sprintf "in%d") in
let output_ports = Array.init 10 ~f:(sprintf "out%d") in
Sequencer.make ~name:"JackSeqTest" ~input_ports ~output_ports
in
for i = 0 to 25000000 do
Thread.delay 0.02;
Thread.delay 0.02 ;
let input = Sequencer.get_input seq in
Array.iter input ~f:begin fun (port, stat, chan, dat1, dat2) ->
Printf.printf "[%d] port:%d stat:%x chan:%d dat1:%d dat2:%d\n%!" i
port stat chan dat1 dat2;
let high_level =
match stat with
| rs when ((0x80<= rs) && (rs <= 0x8F)) -> `Note_off (rs, dat1 , dat2)
| rs when ((0x90<= rs) && (rs <= 0x9F)) ->
if dat2 = 0 (* If velocity = 0 -> note off ! *)
then `Note_off (rs, dat1 , dat2)
else `Note_on (rs, dat1 , dat2)
| _other -> `None
in
begin match high_level with
| `None ->
Sequencer.output_event seq ~port ~stat ~chan ~dat1 ~dat2
| `Note_on (_, dat1, dat2)
| `Note_off (_, dat1, dat2) ->
Sequencer.output_event seq ~port ~stat ~chan ~dat1 ~dat2;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 7) ~dat2;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 12) ~dat2;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 19) ~dat2;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 24) ~dat2;
end;
end;
done;
Sequencer.close seq;
Unix.sleep 3;
Array.iter input ~f:(fun (port, stat, chan, dat1, dat2) ->
Printf.printf "[%d] port:%d stat:%x chan:%d dat1:%d dat2:%d\n%!" i port
stat chan dat1 dat2 ;
let high_level =
match stat with
| rs when 0x80 <= rs && rs <= 0x8F -> `Note_off (rs, dat1, dat2)
| rs when 0x90 <= rs && rs <= 0x9F ->
if dat2 = 0 (* If velocity = 0 -> note off ! *) then
`Note_off (rs, dat1, dat2)
else `Note_on (rs, dat1, dat2)
| _other -> `None
in
match high_level with
| `None -> Sequencer.output_event seq ~port ~stat ~chan ~dat1 ~dat2
| `Note_on (_, dat1, dat2) | `Note_off (_, dat1, dat2) ->
Sequencer.output_event seq ~port ~stat ~chan ~dat1 ~dat2 ;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 7) ~dat2 ;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 12)
~dat2 ;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 19)
~dat2 ;
Sequencer.output_event seq ~port ~stat ~chan ~dat1:(dat1 + 24)
~dat2 )
done ;
Sequencer.close seq ;
Unix.sleep 3 ;
()
let () = test_jack_seq ()
\ No newline at end of file
let () = test_jack_seq ()