diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-04 21:58:57 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-04 21:58:57 -0400 |
commit | d7a633380519e2f2d385597725308cdac62f4f37 (patch) | |
tree | d0aad44f4da008f8334687ed2e7ff107865647e1 /ztunekey | |
parent | 6061457e8a0bc90d961621e3dd716e747a0ee9f1 (diff) | |
download | misc-scripts-d7a633380519e2f2d385597725308cdac62f4f37.tar.gz |
ztunekey: optionally retune and transpose.
Diffstat (limited to 'ztunekey')
-rwxr-xr-x | ztunekey | 52 |
1 files changed, 45 insertions, 7 deletions
@@ -5,6 +5,25 @@ # ...installed via: # convert guitar-tuner-icon-28.jpg .local/share/icons/hicolor/256x256/apps/ztunekey.png +if [ "$1" = "--help" ]; then + cat <<EOF +ztunekey: show tuning and key of an audio file, using a zenity-based UI. + +Usage: ztunekey [file] + +[file] is an audio file, in any format supported by mplayer (since +mplayer is used to convert it to a .wav file for processing). + +With no [file], ztunekey queries audacious (using audtool) to get the +currently playing file. This will fail if audacious isn't running. + +The tuning (in cents relative to A440) and the detected key (and +relative key, e.g. G (Em) or A (F#m)) are shown in a window, after the +file is analyzed. +EOF + exit 0 +fi + ICON=ztunekey ZOPT='--width 300 --height 100 --title Tuning/Key' file="$1" @@ -12,22 +31,41 @@ file="$1" if [ "$file" = "" ]; then file="$( audtool --current-song-filename )" if [ "$file" = "" ]; then - zenity --error $ZOPT --text="No song is playing!" + zenity --error $ZOPT --text="Audacious is not running, or no song is playing." exit 1 fi fi if [ ! -e "$file" ]; then - zenity --error $ZOPT --text="No such file:
$file" + zenity --error $ZOPT --text="No such file:\\n$file" exit 1 fi bn="$( basename "$file" )" +tmpfile=/tmp/ztunekey.$$.wav + +keyfile=/tmp/key.$$ +tunefile=/tmp/tuning.$$ +( mplayer -really-quiet -benchmark -vo null -ao pcm:fast:file=$tmpfile "$file" + find_tuning -q "$tmpfile" > $tunefile & + find_key -q "$tmpfile" > $keyfile & + wait ) | zenity --progress --no-cancel $ZOPT --icon-name=ztunekey --text="$bn" --pulsate --auto-close + +TUNING="$( cat $tunefile )" +KEY="$( cat $keyfile )" +rm -f $keyfile $tunefile + +zenity --question $ZOPT --icon-name=ztunekey --text="$bn\\nTuning: $TUNING cents\\nKey: $KEY )\\n\\nRetune to standard?" +[ "$?" = 1 ] && exit 1 + +zenity --scale $ZOPT --icon-name=ztunekey --text="Semitones to transpose?\\n0 = original key." --min-value=-12 --max-value=12 --value=0 > /tmp/semi.$$ -( find_tuning -q "$file" > /tmp/tuning.$$ & - find_key -q "$file" > /tmp/key.$$ & - wait ) | zenity --progress $ZOPT --icon-name=ztunekey --text="$bn" --pulsate --auto-close +S="$( cat /tmp/semi.$$ )" +rm -f /tmp/semi.$$ +P="$( perl -MPOSIX=round -e "printf '%+2.2f', round(100 * ($S - $TUNING / 100)) / 100" )" +newfile="$( echo "$bn" | sed 's,\.[^.]*$,'$P'.wav,' )" -zenity --info $ZOPT --icon-name=ztunekey --text="$bn
Tuning: $( cat /tmp/tuning.$$ ) cents
Key: $( cat /tmp/key.$$ )" +mkdir -p ~/retuned +rubberband --pitch $P $tmpfile ~/retuned/"$newfile" | zenity --progress --no-cancel $ZOPT --icon-name=ztunekey --text "Retuning $bn by $P semitones." --pulsate --auto-close +audtool --playlist-addurl-to-new-playlist ~/retuned/"$newfile" -rm -f /tmp/tuning.$$ /tmp/key.$$ |