Простой Метроном Баша
Использование
metronome.sh [beats per minute] [beats per measure]
Информация
Он воспроизводит со скоростью 120bpm в 4/4 раза по умолчанию Максимум 600bpm и 16/16 раз Первый удар акцентирован. Вы можете заменить звуковые файлы, если хотите. Я просто выбрал те, которые звучали хорошо из звукового банка Ubuntu 14.04. В моей системе точность составляет около 1,5 мс за такт, что не заметно. Например
metronome.sh
metronome.sh 75 # 75 BPM
metronome.sh 120 3 # 120 BPM, 3 beats per measure
Сценарий
#!/bin/bash
# metronome.sh
# Is a metronome.
# Accentuated and unaccentuated sounds, respectively.
tick='/usr/share/sounds/ubuntu/stereo/dialog-information.ogg'
tock='/usr/share/sounds/ubuntu/stereo/button-toggle-on.ogg'
# Default BPM and beats per measure.
bpm=120
msr=4
echo_error(){
# Error handler
local basename="${0##*/}"
local msg="$@"
echo "$basename: $msg" 1>&2
}
# BPM argument
if [[ $1 ]]; then
bpm_min=1
bpm_max=600
# Check that argument is a number within a range.
if ! [[ $1 =~ ^[0-9]+$ ]] ||
[[ $1 -lt $bpm_min ]] ||
[[ $1 -gt $bpm_max ]]
then
echo_error "Beats per minute not in range [$bpm_min, $bpm_max]."
exit 1
fi
bpm="$1"
fi
# Beats per measure argument
if [[ $2 ]]; then
msr_min=1
msr_max=16
# Check that argument is a number within a range.
if ! [[ $2 =~ ^[0-9]+$ ]] ||
[[ $2 -lt $msr_min ]] ||
[[ $2 -gt $msr_max ]]
then
echo_error "Beats per measure not in range [$msr_min, $msr_max]."
exit 1
fi
measure="$2"
fi
# Get seconds per beat using bc.
# "-0.004" accounts for approximate execution time.
rest_duration="$(bc -l <<< "scale=5; 60/$bpm-0.004")"
echo "Metronome playing $bpm BPM, $msr beats per measure"
echo -n "Press Ctrl+C to cancel."
while true; do
# Accentuated beat.
for i in 1; do
canberra-gtk-play --file="$tick" &
sleep "$rest_duration"
done
# Unaccentuated beat(s).
for i in $(seq 2 "$msr"); do
canberra-gtk-play --file="$tock" &
sleep "$rest_duration"
done
done
задан Jorge Castro
26 November 2011 в 07:35
поделиться