diff --git a/dune-project b/dune-project index a17e9ab8ab3c1b41e4aa26158e5db911fd4f45d6..e32dad3b63fc8fcdbfd6c1ce0e4e8ddbd8d9ef9f 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,2 @@ -(lang dune 1.0) +(lang dune 3.7) (name misuja) diff --git a/src/lib/.ocamlformat b/src/lib/.ocamlformat index 6bafbd1c4e234b3b34aa76c3ce359274d0069922..b825f826ff96e0c4ec9d407427fb6cdb7675a8ee 100644 --- a/src/lib/.ocamlformat +++ b/src/lib/.ocamlformat @@ -1 +1,5 @@ -profile=compact +version=0.24.1 +profile=default +exp-grouping=preserve +parse-docstrings +sequence-blank-line=compact diff --git a/src/lib/config/discover.ml b/src/lib/config/discover.ml index 02f6c73c1240b6eee951545769bc63a1f6c9c543..1afc797a590ae294a2d8a3643f2358ff06e539d9 100644 --- a/src/lib/config/discover.ml +++ b/src/lib/config/discover.ml @@ -3,18 +3,15 @@ module C = Configurator.V1 let () = C.main ~name:"jack" (fun c -> let default : C.Pkg_config.package_conf = - {libs= ["-ljack"]; cflags= ["-I/usr/include/jack"]} + { libs = [ "-ljack" ]; cflags = [ "-I/usr/include/jack" ] } in let conf = match C.Pkg_config.get c with - | None -> - default + | None -> default | Some pc -> ( - match C.Pkg_config.query pc ~package:"jack" with - | None -> - default - | Some a -> - a ) + match C.Pkg_config.query pc ~package:"jack" with + | None -> default + | Some a -> a) in - C.Flags.write_sexp "c_flags.sexp" conf.cflags ; - C.Flags.write_sexp "c_library_flags.sexp" conf.libs ) + C.Flags.write_sexp "c_flags.sexp" (conf.cflags @ [ "-fPIC" ]); + C.Flags.write_sexp "c_library_flags.sexp" conf.libs) diff --git a/src/lib/dune b/src/lib/dune index ccd7697487b3bfc3cdf8295ae6cabd8a00ed7c5d..93351ce829bc7b4bafbe3a589817d76eac9b76ff 100644 --- a/src/lib/dune +++ b/src/lib/dune @@ -2,9 +2,11 @@ (name misuja) (public_name misuja) (libraries unix) - (c_names misuja_jack_seq) - (c_flags - (:include c_flags.sexp)) + (foreign_stubs + (language c) + (names misuja_jack_seq) + (flags + (:include c_flags.sexp))) (c_library_flags (:include c_library_flags.sexp))) diff --git a/src/lib/misuja.ml b/src/lib/misuja.ml index 3a5d52c7c6069fac4b65242aa9378ec7844075f4..58dd1f9d1a4dff7c25ea3b2eb0d74f80e4edcdef 100644 --- a/src/lib/misuja.ml +++ b/src/lib/misuja.ml @@ -23,31 +23,26 @@ (* OTHER DEALINGS IN THE SOFTWARE. *) (******************************************************************************) -(** - - OCaml types and functions providing high level access to a jack midi - sequencer. +(** OCaml types and functions providing high level access to a jack midi + sequencer. - @author S. Mondet - -*) + @author S. Mondet *) module Sequencer = struct - (** The sequencer object *) type t + (** The sequencer object *) external make : name:string -> input_ports:string array -> output_ports:string array -> t = "ml_jackseq_make" - (** - The sequencer constructor - should be called as {[ - let my_seq = - Sequencer.make "client_name" - [| "input_port_A" ; "input_port_B" |] - [| "out1" ; "out2" ; "outN" |] - in - ]} - *) + (** The sequencer constructor should be called as + + {[ + let my_seq = + Sequencer.make "client_name" + [| "input_port_A" ; "input_port_B" |] + [| "out1" ; "out2" ; "outN" |] + in + ]} *) external close : t -> unit = "ml_jackseq_close" (** Close the sequencer ({i ie} jack client) *) @@ -55,11 +50,10 @@ module Sequencer = struct 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) *) + (** Put an event in the output buffer, it will be really output at next jack + frame (which means quasi immediately) *) - 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 diff --git a/src/lib/misuja_jack_seq.c b/src/lib/misuja_jack_seq.c index bef122d4b383611400690e1a653b0454860e0d62..f9fe3384249ac2303331a97d8160f7cd7a660a1d 100644 --- a/src/lib/misuja_jack_seq.c +++ b/src/lib/misuja_jack_seq.c @@ -250,7 +250,7 @@ ml_jackseq_make(value app_name, value in_names_array, value ou_names_array) { memset(js , 0 , sizeof(jack_seq_t)); /* try to become a client of the JACK server */ - js->js_client = jack_client_new ( String_val(app_name)); + js->js_client = jack_client_open ( String_val(app_name), JackNoStartServer, NULL); js_exn_assert(js->js_client != NULL, "Couldn't create a client, is jackd running ?"); @@ -275,10 +275,10 @@ ml_jackseq_make(value app_name, value in_names_array, value ou_names_array) { } /* The two ring buffers */ - js->js_i_rbuf = jack_ringbuffer_create (2048); /* */ + js->js_i_rbuf = jack_ringbuffer_create (1024*sizeof(jack_midi_event_t)); js_exn_assert(js->js_i_rbuf != NULL, "Error creating the ring buffer"); memset(js->js_i_rbuf->buf, 0, js->js_i_rbuf->size); - js->js_o_rbuf = jack_ringbuffer_create (2048); /* */ + js->js_o_rbuf = jack_ringbuffer_create (1024*sizeof(jack_midi_event_t)); js_exn_assert(js->js_o_rbuf != NULL, "Error creating the ring buffer"); memset(js->js_o_rbuf->buf, 0, js->js_o_rbuf->size); @@ -290,7 +290,7 @@ ml_jackseq_make(value app_name, value in_names_array, value ou_names_array) { /* Return an abstract value: */ - the_sequencer = alloc_custom( + the_sequencer = caml_alloc_custom( &sequencer_custom_ops, sizeof(jack_seq_t *), 0, 1); *((jack_seq_t **)Data_custom_val(the_sequencer)) = js; CAMLreturn (the_sequencer) ; @@ -333,6 +333,13 @@ ml_jackseq_output_event(value ml_seq, value ml_port, value ml_stat, ret = jack_ringbuffer_write(js->js_o_rbuf, (char *)&stack_event, sizeof(jack_seq_midi_event_t)); + if (ret != sizeof(jack_seq_midi_event_t)) { + fprintf(stderr, "[C-jack]DBG: %d %ld, for read: %ld, for write: %ld\n", + ret, sizeof(jack_seq_midi_event_t), + jack_ringbuffer_read_space(js->js_o_rbuf), + jack_ringbuffer_write_space(js->js_o_rbuf) + ); + } js_exn_assert(ret == sizeof(jack_seq_midi_event_t), "Couldn't write in the ring buffer"); @@ -367,10 +374,15 @@ ml_jackseq_get_input(value ml_seq){ for (i = 0; i < to_read; i++) { ret = jack_ringbuffer_read(js->js_i_rbuf, - (void *)&stack_event, sizeof(jack_seq_midi_event_t)); + (void *)&stack_event, sizeof(jack_seq_midi_event_t)); + if (ret != sizeof(jack_seq_midi_event_t)) { + fprintf(stderr, "[C-jack]DBG-read: %d %ld, for read: %ld, for write: %ld\n", + ret, sizeof(jack_seq_midi_event_t), + jack_ringbuffer_read_space(js->js_o_rbuf), + jack_ringbuffer_write_space(js->js_o_rbuf)); + } js_exn_assert(ret == sizeof(jack_seq_midi_event_t), - "Couldn't read in the ring buffer"); - + "Couldn't read in the ring buffer"); one_ml_event = caml_alloc(5, 0); Store_field(one_ml_event, 0, Val_int(stack_event.me_port)); Store_field(one_ml_event, 1, Val_int(stack_event.me_stat & 0xFF)); diff --git a/src/test/.ocamlformat b/src/test/.ocamlformat index 6bafbd1c4e234b3b34aa76c3ce359274d0069922..b825f826ff96e0c4ec9d407427fb6cdb7675a8ee 100644 --- a/src/test/.ocamlformat +++ b/src/test/.ocamlformat @@ -1 +1,5 @@ -profile=compact +version=0.24.1 +profile=default +exp-grouping=preserve +parse-docstrings +sequence-blank-line=compact diff --git a/src/test/dune b/src/test/dune index 29c39cf06fd4f14b623ace255a70918d24d59cc1..5c3f0b07d782df4e38cbafdca5c06e0575e89ba4 100644 --- a/src/test/dune +++ b/src/test/dune @@ -1,4 +1,3 @@ (executable (name relay) - (libraries threads.posix misuja) -) \ No newline at end of file + (libraries threads.posix misuja)) diff --git a/src/test/relay.ml b/src/test/relay.ml index d038ece88745dcdb8a72672b146c85f23faf1d05..3c00008668af33966151b87c10405602c635074e 100644 --- a/src/test/relay.ml +++ b/src/test/relay.ml @@ -1,22 +1,19 @@ 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 ~jack_name () = 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 + Sequencer.make ~name:jack_name ~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:(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 ; + stat chan dat1 dat2; let high_level = match stat with | rs when 0x80 <= rs && rs <= 0x8F -> `Note_off (rs, dat1, dat2) @@ -29,17 +26,17 @@ let test_jack_seq () = 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 ; + 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 () +let () = + match Sys.argv |> Array.to_list with + | [ _; jack_name ] -> test_jack_seq ~jack_name () + | _ -> Format.kasprintf failwith "usage: %s " Sys.argv.(0)