aboutsummaryrefslogtreecommitdiff
path: root/src/audio.ts
blob: 4147164332b269901eb8fbd47ffac1238b2e2ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import * as Config from 'config'
import * as State from 'state'

const start = new Audio('sound/start.mp3')
const stop = new Audio('sound/stop.mp3')
const endTabata = new Audio('sound/end-tabata.mp3')
const endTraining = new Audio('sound/end-training.mp3')

export function playFromStep(config: Config.Config, state: State.State) {
  if (state.step === State.Step.WarmUp && state.remaining === config.warmup) {
    start.play()
  } else if (state.step === State.Step.Work && state.remaining === config.work) {
    start.play()
  } else if (state.step === State.Step.Rest && state.remaining === config.rest) {
    stop.play()
  } else if (state.step === State.Step.Prepare && state.remaining === config.prepare && state.elapsed > 0) {
    endTabata.play()
  } else if (state.step === State.Step.End && state.elapsed === Config.getDuration(config)) {
    endTraining.play()
  }
}