aboutsummaryrefslogtreecommitdiff
path: root/ztunekey
diff options
context:
space:
mode:
Diffstat (limited to 'ztunekey')
-rwxr-xr-xztunekey52
1 files changed, 45 insertions, 7 deletions
diff --git a/ztunekey b/ztunekey
index da69d56..3a3a7a9 100755
--- a/ztunekey
+++ b/ztunekey
@@ -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.$$