#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/audio-timer # # The purpose of this program is to repeatedly produce a sound # after a certain amount of time, to help the user do # work-out/shadowbox/stretch/relaxation/yoga/etc exercises. # Do it every day and start feeling better, instantly :) # # There is one "start/change" sound, one pause sound, and one # sound when it is all done. # # The program accepts four arguments, with: # # - init, the time from invocation to the first # round, in seconds # # - interval, round length, in seconds # # - pause, the length of every pause, in seconds # # - total, the total number of minutes it will all # last timer-play-sound () { local snd=$1 mpv --no-terminal --vo=null --volume=30 $snd } timer-now () { date +%s } timer () { local init=${1:-0} # sec local interval=${2:-60} # sec local pause=${3:-0} # sec local total=${4:-60} # min local sound_dir=~/prog/timer local interval_sound=${sound_dir}/interval.mp3 local pause_sound=${sound_dir}/pause.mp3 local end_sound=${sound_dir}/end.mp3 (( $init > 0 )) && echo " init: $init sec" echo "round time: $interval sec" (( $pause > 0 )) && echo "pause time: $pause sec" echo " total: $total min" local total_secs=$(( $total * 60 )) local now=$(timer-now) local stop_time=$(( $now + $total_secs )) if (( $init > 0 )); then printf "\n(get ready in ${init} s)\n" sleep $init fi local so_far=1 printf "\nround: " echo -n "$so_far " while (( $now < $stop_time )); do timer-play-sound $interval_sound sleep $interval so_far=$(( $so_far + 1 )) echo -n "$so_far " if (( $pause > 0 )); then timer-play-sound $pause_sound sleep $pause fi now=$(timer-now) done timer-play-sound $end_sound printf "\n\ndone\n" } thai () { local rnds=5 local rnd_s=$(( 3 * 60 )) local pse_s=$(( 2 * 60 )) local rnds_t=$(( $rnds * $rnd_s )) local pses_t=$(( ($rnds - 1) * $pse_s )) local t=$(( ($rnds_t + $pses_t) / 60 )) timer 0 $rnd_s $pse_s $t }