aboutsummaryrefslogtreecommitdiff
path: root/elements
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2020-12-23 19:11:31 +0100
committerSébastien Dailly <sebastien@chimrod.com>2020-12-23 19:11:31 +0100
commitec812521b31471ce9ac3d9bdf1288b1569defbc8 (patch)
treed384c959b9e9bb2a04141ab56077026fe6e7c7f3 /elements
parent6354358caa1dfbf2fe1d481f6ac5fba3775938fc (diff)
Add svg output
Diffstat (limited to 'elements')
-rwxr-xr-xelements/dune7
-rwxr-xr-xelements/input.ml20
-rwxr-xr-xelements/timer.ml41
-rwxr-xr-xelements/timer.mli11
4 files changed, 79 insertions, 0 deletions
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