Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Last active August 29, 2015 14:16
Show Gist options
  • Save DanielFGray/056ef296ecf91c50ba9e to your computer and use it in GitHub Desktop.
Save DanielFGray/056ef296ecf91c50ba9e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
declare -a output
declare -A values
usage() {
echo "$0 INITIALSPEED ENDSPEED INCREMENT [files]"
}
if (( $# < 3 )); then
usage
exit 1
fi
for lbl in 'initialspeed' 'endspeed' 'increment'; do
re='^[0-9]+$'
if ! [[ "$1" =~ $re ]] ; then
echo >&2 "error: ${lbl^^} not a number"
usage
exit 1
fi
values["$lbl"]="$1"
shift
done
add_tempo() {
mapfile -t input < <(sed '/^[0-9]+$/d' <<< "$1")
for ((i="${values['initialspeed']}"; i<="${values['endspeed']}"; i+="${values['increment']}")); do
output+=( "$i" "${input[@]}" )
done
}
if (( $# > 0 )); then
add_tempo <(cat "$@")
else
add_tempo /dev/stdin
fi
printf '%s\n' "${output[@]}"
# aoss "$HOME/src/jdkdrum/jdkdrum" < <(printf '%s\n' "${output[@]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment