annotate makeWebAudio.sh @ 994:e68163aea188

Correct number of initial pages before frontmatter.
author Jim Hague <jim.hague@acm.org>
date Sat, 10 Aug 2019 00:42:15 +0100
parents d6e2a281cceb
children e4d31e094d24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
1 #!/bin/bash
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
2 #
223
0ef955669a9a Make transposed tunes use the original audio.
Jim Hague <jim.hague@acm.org>
parents: 197
diff changeset
3 # Make audio required for the website but not for the book.
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
4 # They go into web/<book>.
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
5 #
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
6
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
7 if [ $# != 1 ]; then
223
0ef955669a9a Make transposed tunes use the original audio.
Jim Hague <jim.hague@acm.org>
parents: 197
diff changeset
8 echo "Usage: makeWebAudio.sh <book dir name>"
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
9 exit 1
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
10 fi
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
11
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
12 dir=`pwd`
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
13
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
14 booke=$dir/$1
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
15 basewebdir=$dir/web
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
16 basetunedir=$basewebdir/tunes
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
17
400
f1c4abe4fc75 First go at adding the tune learner page.
Jim Hague <jim.hague@acm.org>
parents: 399
diff changeset
18 # Make MP3 and OGG files for the input .abc. Since we're listening to
f1c4abe4fc75 First go at adding the tune learner page.
Jim Hague <jim.hague@acm.org>
parents: 399
diff changeset
19 # a doorbell playing the tunes, go for lowest quality (and hence smallest)
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
20 # MP3 and OGG. $1 is the input filename, $2 is the output directory,
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
21 # $3 is optional args for timidity.
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
22 makeaudiofiles()
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
23 {
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
24 name=`basename $1 .abc`
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
25 tunedir="$2"
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
26
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
27 abc2midi $1 -o $tunedir/${name}.tmp.mid
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
28 mv $tunedir/${name}.tmp.mid $tunedir/${name}.mid
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
29 timidity -OwM $3 -o $tunedir/${name}.wav $tunedir/${name}.mid
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
30 lame -m m -V 9 --quiet $tunedir/${name}.wav $tunedir/${name}.tmp.mp3
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
31 mv $tunedir/${name}.tmp.mp3 $tunedir/${name}.mp3
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
32 # Timidity can generate OGG directly. But we need to generate WAV
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
33 # for lame, and oggenc produces smaller output. OGG is needed for
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
34 # Firefox's audio tag. FF doesn't support MP3, some others support
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
35 # MP3 but not OGG.
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
36 oggenc -Q -q 0 -o $tunedir/${name}.tmp.ogg $tunedir/${name}.wav
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
37 mv $tunedir/${name}.tmp.ogg $tunedir/${name}.ogg
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
38
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
39 rm $tunedir/${name}.wav
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
40 }
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
41
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
42 # Make audio for a new tempo for the abc file $1, giving the output
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
43 # files the same name with a prefix $3 in output directory $2. The new
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
44 # tempo is the original tempo (120 used if not specified), multiplied
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
45 # by $4 and divided by $5. These audio files are for Learner use;
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
46 # I've found that having the chords thumping away can make it hard to
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
47 # distinguish the melody, so arrange for timidity to mute everything
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
48 # except the melody track.
399
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
49 makeaudiofortempo()
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
50 {
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
51 name=`basename $1 .abc`
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
52 tunedir="$2"
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
53 newspeedfilename="$3-${name}.abc"
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
54 mkdir -p $tunedir
399
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
55
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
56 # Prepare new speed audio files.
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
57 # The tempo is either a plain number, or <notelen>=<number>.
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
58 tempo=`$dir/abcfield.py --field Q $1`
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
59 if [ -z $tempo ]; then
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
60 echo "Warning: $1 has no tempo. Using 120."
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
61 tempo="120"
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
62 fi
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
63 pos=`expr index $tempo '='`
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
64 numtempo=${tempo:pos}
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
65 notelenprefix=${tempo:0:pos}
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
66 # Calculate new tempo.
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
67 newtempo=$(( ( $numtempo * $4 ) / $5 ))
399
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
68 # Insert new tempo and delete old. Old may not exist,
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
69 # so do this rather than overwrite.
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
70 sed -e "/^Q:/d" -e "/^K:/aQ: ${notelenprefix}${newtempo}" $1 > $tunedir/$newspeedfilename
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
71 makeaudiofiles $tunedir/$newspeedfilename $tunedir --mute=0,-1
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
72 rm $tunedir/$newspeedfilename
399
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
73 }
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
74
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
75 # Generate audio files and slow speed (currently half speed) audio files.
753
b83b49f2a0a0 Correct Mac-ism. find -maxdepth n, not find -depth n.
Jim Hague <jim.hague@acm.org>
parents: 748
diff changeset
76 find $booke -maxdepth 1 -name "*.abc" | sort |
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
77 while read filename
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
78 do
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
79 name=`basename $filename .abc`
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
80 tunedir=$basetunedir/$name
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
81 mkdir -p $tunedir
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
82
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
83 makeaudiofiles $filename $tunedir
394
ae9c05d2aafd Make slow speed web audio files.
Jim Hague <jim.hague@acm.org>
parents: 393
diff changeset
84
399
aeef7b1ca0ad Make 1/4, 1/2 and 3/4 speed audio for tunes.
Jim Hague <jim.hague@acm.org>
parents: 394
diff changeset
85 # Now make 1/4, 1/2 and 3/4 speed audio.
943
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
86 makeaudiofortempo $filename $tunedir "veryslow" 1 4
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
87 makeaudiofortempo $filename $tunedir "slow" 2 4
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
88 makeaudiofortempo $filename $tunedir "littleslow" 3 4
d6e2a281cceb Change web page layout.
Jim Hague <jim.hague@acm.org>
parents: 753
diff changeset
89 makeaudiofortempo $filename $tunedir "normal" 4 4
43
d92717f8130c First go at producing a very simple website.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
90 done