aboutsummaryrefslogtreecommitdiff
path: root/src/audio.ml
blob: 14464407a227d6a8eb24da8bb37b1a3e51fdbad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
type audio

external create : string -> audio = "Audio" [@@bs.new]

external play : audio -> unit = "play" [@@bs.send]

external currentTime : audio -> int = "currentTime" [@@bs.get]

external setCurrentTime : audio -> int -> unit = "currentTime" [@@bs.set]

let playOrReplay audio =
  let () = if currentTime audio > 0 then setCurrentTime audio 0 else () in
  play audio

(* Sounds *)

let c3 = create "sounds/c3.mp3"

let c4 = create "sounds/c4.mp3"

let c5 = create "sounds/c5.mp3"

(* Play from step *)

let playFromStep (config: Config.config) (step : Step.state) =
  match step.step with
  | Step.Prepare when step.remaining == config.prepare ->
      playOrReplay c3
  | Step.Work when step.remaining == config.work ->
      playOrReplay c5
  | Step.Rest when step.remaining == config.rest ->
      playOrReplay c3
  | Step.End -> playOrReplay c3
  | _ -> if step.remaining <= 3 then playOrReplay c4 else ()