diff makeWebAudio.sh @ 943:d6e2a281cceb build-default-344

Change web page layout. Put tune contents under 'tunes/<name>' or 'tunes-<instrument>/<name>'. That way they won't move if the tune gets moved between Bookes. For now I have not attempted to redirect old URLs.
author Jim Hague <jim.hague@acm.org>
date Mon, 05 Aug 2019 23:25:28 +0100
parents b83b49f2a0a0
children e4d31e094d24
line wrap: on
line diff
--- a/makeWebAudio.sh	Mon Aug 05 23:22:04 2019 +0100
+++ b/makeWebAudio.sh	Mon Aug 05 23:25:28 2019 +0100
@@ -12,39 +12,46 @@
 dir=`pwd`
 
 booke=$dir/$1
-builddir=$dir/web/$1
-
-mkdir -p $builddir
+basewebdir=$dir/web
+basetunedir=$basewebdir/tunes
 
 # Make MP3 and OGG files for the input .abc. Since we're listening to
 # a doorbell playing the tunes, go for lowest quality (and hence smallest)
-# MP3 and OGG. $1 is the input filename, $2 is optional args for timidity.
+# MP3 and OGG. $1 is the input filename, $2 is the output directory,
+# $3 is optional args for timidity.
 makeaudiofiles()
 {
     name=`basename $1 .abc`
+    tunedir="$2"
 
-    abc2midi $1 -o $builddir/${name}.mid
-    timidity -OwM $2 -o $builddir/${name}.wav $builddir/${name}.mid
-    lame -m m -V 9 --quiet $builddir/${name}.wav $builddir/${name}.mp3
+    abc2midi $1 -o $tunedir/${name}.tmp.mid
+    mv $tunedir/${name}.tmp.mid $tunedir/${name}.mid
+    timidity -OwM $3 -o $tunedir/${name}.wav $tunedir/${name}.mid
+    lame -m m -V 9 --quiet $tunedir/${name}.wav $tunedir/${name}.tmp.mp3
+    mv $tunedir/${name}.tmp.mp3 $tunedir/${name}.mp3
     # Timidity can generate OGG directly. But we need to generate WAV
     # for lame, and oggenc produces smaller output. OGG is needed for
     # Firefox's audio tag. FF doesn't support MP3, some others support
     # MP3 but not OGG.
-    oggenc -Q -q 0 -o $builddir/${name}.ogg $builddir/${name}.wav
+    oggenc -Q -q 0 -o $tunedir/${name}.tmp.ogg $tunedir/${name}.wav
+    mv $tunedir/${name}.tmp.ogg $tunedir/${name}.ogg
 
-    rm $builddir/${name}.wav
+    rm $tunedir/${name}.wav
 }
 
-# Make audio for a new tempo for the abc file $1, giving the output files
-# the same name with a prefix $2. The new tempo is the original tempo
-# (120 used if not specified), multiplied by $3 and divided by $4.
-# These audio files are for Learner use; I've found that having the
-# chords thumping away can make it hard to distinguish the melody, so
-# arrange for timidity to mute everything except the melody track.
+# Make audio for a new tempo for the abc file $1, giving the output
+# files the same name with a prefix $3 in output directory $2. The new
+# tempo is the original tempo (120 used if not specified), multiplied
+# by $4 and divided by $5.  These audio files are for Learner use;
+# I've found that having the chords thumping away can make it hard to
+# distinguish the melody, so arrange for timidity to mute everything
+# except the melody track.
 makeaudiofortempo()
 {
-    name=`basename $filename .abc`
-    newspeedfilename="$2-${name}.abc"
+    name=`basename $1 .abc`
+    tunedir="$2"
+    newspeedfilename="$3-${name}.abc"
+    mkdir -p $tunedir
 
     # Prepare new speed audio files.
     # The tempo is either a plain number, or <notelen>=<number>.
@@ -57,23 +64,27 @@
     numtempo=${tempo:pos}
     notelenprefix=${tempo:0:pos}
     # Calculate new tempo.
-    newtempo=$(( ( $numtempo * $3 ) / $4 ))
+    newtempo=$(( ( $numtempo * $4 ) / $5 ))
     # Insert new tempo and delete old. Old may not exist,
     # so do this rather than overwrite.
-    sed -e "/^Q:/d" -e "/^K:/aQ: ${notelenprefix}${newtempo}" $1 > $builddir/$newspeedfilename
-    makeaudiofiles $builddir/$newspeedfilename --mute=0,-1
-    rm $builddir/$newspeedfilename
+    sed -e "/^Q:/d" -e "/^K:/aQ: ${notelenprefix}${newtempo}" $1 > $tunedir/$newspeedfilename
+    makeaudiofiles $tunedir/$newspeedfilename $tunedir --mute=0,-1
+    rm $tunedir/$newspeedfilename
 }
 
 # Generate audio files and slow speed (currently half speed) audio files.
 find $booke -maxdepth 1 -name "*.abc" | sort |
     while read filename
     do
-        makeaudiofiles $filename
+        name=`basename $filename .abc`
+        tunedir=$basetunedir/$name
+        mkdir -p $tunedir
+
+        makeaudiofiles $filename $tunedir
 
         # Now make 1/4, 1/2 and 3/4 speed audio.
-        makeaudiofortempo $filename "veryslow" 1 4
-        makeaudiofortempo $filename "slow" 2 4
-        makeaudiofortempo $filename "littleslow" 3 4
-        makeaudiofortempo $filename "normal" 4 4
+        makeaudiofortempo $filename $tunedir "veryslow" 1 4
+        makeaudiofortempo $filename $tunedir "slow" 2 4
+        makeaudiofortempo $filename $tunedir "littleslow" 3 4
+        makeaudiofortempo $filename $tunedir "normal" 4 4
     done