From ec812521b31471ce9ac3d9bdf1288b1569defbc8 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 23 Dec 2020 19:11:31 +0100 Subject: Add svg output --- elements/dune | 7 +++++++ elements/input.ml | 20 ++++++++++++++++++++ elements/timer.ml | 41 +++++++++++++++++++++++++++++++++++++++++ elements/timer.mli | 11 +++++++++++ 4 files changed, 79 insertions(+) create mode 100755 elements/dune create mode 100755 elements/input.ml create mode 100755 elements/timer.ml create mode 100755 elements/timer.mli (limited to 'elements') diff --git a/elements/dune b/elements/dune new file mode 100755 index 0000000..755bd05 --- /dev/null +++ b/elements/dune @@ -0,0 +1,7 @@ +(library + (name elements) + (libraries + brr + brr.note + ) +) diff --git a/elements/input.ml b/elements/input.ml new file mode 100755 index 0000000..790b15d --- /dev/null +++ b/elements/input.ml @@ -0,0 +1,20 @@ +open Brr +open Brr_note +open Note + +(** Create a slider element, and a signal with the value *) +let slider ~at = + let slider = + El.input ~at () in + + let event = + Evr.on_el + Ev.input (fun _ -> + let raw_value = El.prop El.Prop.value slider in + Jstr.to_int raw_value) + slider + |> S.hold (Jstr.to_int (El.prop El.Prop.value slider)) + in + slider, event + + diff --git a/elements/timer.ml b/elements/timer.ml new file mode 100755 index 0000000..0a75e12 --- /dev/null +++ b/elements/timer.ml @@ -0,0 +1,41 @@ +open Brr_note_kit + +type t = + { mutable id : Brr.G.timer_id + ; send : float Note.E.send + ; mutable counter : Time.counter + } + +let create + : unit -> (t * Brr_note_kit.Time.span Note.E.t) + = fun () -> + let event, send = Note.E.create () + and counter = (Time.counter ()) in + {id = (-1); send; counter}, event + +let stop + : t -> unit + = fun {id; _} -> + Brr.G.stop_timer id + +let start + : t -> float -> unit + = fun t d -> + let {id; send; _} = t in + t.counter <- Time.counter (); + + + Brr.G.stop_timer id; + let timer_id = Brr.G.set_interval + ~ms:(int_of_float @@ d *. 1000.) + (fun () -> + + let span = Time.counter_value t.counter in + t.counter <- Time.counter (); + send span) in + ignore @@ Brr.G.set_timeout ~ms:0 (fun () -> send 0.); + t.id <- timer_id + + +let delay : t -> float + = fun t -> Time.counter_value t.counter diff --git a/elements/timer.mli b/elements/timer.mli new file mode 100755 index 0000000..0509ad0 --- /dev/null +++ b/elements/timer.mli @@ -0,0 +1,11 @@ +open Brr_note_kit + +type t + +val create : unit -> t * Time.span Note.E.t + +val start: t -> float -> unit + +val stop: t -> unit + +val delay : t -> float -- cgit v1.2.3