aboutsummaryrefslogtreecommitdiff
path: root/events/timer.ml
diff options
context:
space:
mode:
Diffstat (limited to 'events/timer.ml')
-rwxr-xr-xevents/timer.ml39
1 files changed, 28 insertions, 11 deletions
diff --git a/events/timer.ml b/events/timer.ml
index def9a81..0a75e12 100755
--- a/events/timer.ml
+++ b/events/timer.ml
@@ -1,24 +1,41 @@
-type t = Brr.G.timer_id ref * unit Note.E.send
+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 * unit Note.E.t)
+ : unit -> (t * Brr_note_kit.Time.span Note.E.t)
= fun () ->
- let event, send = Note.E.create () in
- (ref (-1), send), event
+ 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
+ = fun {id; _} ->
+ Brr.G.stop_timer id
let start
: t -> float -> unit
- = fun (id, send) d ->
+ = fun t d ->
+ let {id; send; _} = t in
+ t.counter <- Time.counter ();
+
- Brr.G.stop_timer !id;
+ Brr.G.stop_timer id;
let timer_id = Brr.G.set_interval
~ms:(int_of_float @@ d *. 1000.)
- (fun () -> send ()) in
- ignore @@ Brr.G.set_timeout ~ms:0 send;
- id:= timer_id;
+ (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