diff options
Diffstat (limited to 'ztunekey')
| -rwxr-xr-x | ztunekey | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/ztunekey b/ztunekey new file mode 100755 index 0000000..61eb9e6 --- /dev/null +++ b/ztunekey @@ -0,0 +1,76 @@ +#!/bin/sh + +# icon from: +# https://vectorified.com/images/guitar-tuner-icon-28.jpg +# ...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" + +if [ "$file" = "" ]; then + file="$( audtool --current-song-filename )" + if [ "$file" = "" ]; then + 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:\\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.$$ + +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,' )" + +mkdir -p ~/retuned +cd ~/retuned +rubberband --pitch $P $tmpfile "$newfile" | zenity --progress --no-cancel $ZOPT --icon-name=ztunekey --text "Retuning $bn by $P semitones." --pulsate --auto-close +flacfile="$( basename "$newfile" .wav )".flac +flac -f --delete-input-file -o "$flacfile" "$newfile" | zenity --progress --no-cancel $ZOPT --icon-name=ztunekey --text "Encoding $flacfile" --pulsate --auto-close +id3cp "$file" "$flacfile" +id3 -2 -t "%|%t||%_f|? (Retuned $P)" "$flacfile" +audtool --playlist-addurl-to-new-playlist ~/retuned/"$flacfile" + |
