Last active
March 3, 2018 06:38
-
-
Save plugnburn/af0aabd434c10ad66e6d98f9e4e8f4a0 to your computer and use it in GitHub Desktop.
SoX harp - simplest cross-platform musical instrument in a few lines of Bash (depends on SoX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function idx() { | |
local t=${1%%$2*} | |
[[ "$1" == "$t" ]] && echo "-1" || echo ${#t} | |
} | |
oct=0 | |
while IFS= read -r -s -n1 i; do | |
[[ "$i" == "a" ]] && (( oct > -3 )) && oct=$((oct - 1)) && echo "Octave: $((oct + 3))" | |
[[ "$i" == "1" ]] && (( oct < 3 )) && oct=$((oct + 1)) && echo "Octave: $((oct + 3))" | |
noteIdx=$(idx 'zsxdcvgbhnjmq2w3er5t6y7ui9o0p[=]' "$i") | |
(( noteIdx > -1 )) && play -q -n synth 3 pluck %$(( noteIdx - 12 + 12 * oct )) & | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty dang cool!