Skip to content

Instantly share code, notes, and snippets.

@jobbautista9
Created March 28, 2022 12:06
Show Gist options
  • Save jobbautista9/6e176023d834b3daf980be06dc6de24f to your computer and use it in GitHub Desktop.
Save jobbautista9/6e176023d834b3daf980be06dc6de24f to your computer and use it in GitHub Desktop.
The Fantastic Legend of Tohno (bash/SoX arrange)
#!/bin/bash
: '
Copyright (C) 2022 Job Bautista
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'
echo ' ___ ___ __ ___ __ ___ __ ___ __'
echo '|__ /\ |\ | | /\ /__` | | / ` | |__ / _` |__ |\ | | \'
echo '| /~~\ | \| | /~~\ .__/ | | \__, |___ |___ \__> |___ | \| |__/'
echo ' __ ___'
echo ' / \ |__'
echo ' \__/ |'
echo ' ___ __ __'
echo ' | / \ |__| |\ | / \'
echo ' | \__/ | | | \| \__/'
echo "The Fantastic Tales from Tōno"
echo "Composed by ZUN for Touhou Youyoumu: Perfect Cherry Blossom"
printf "Arranged by Job Bautista\n\n"
# unused notes and durations are commented
# notes
: '
declare -r c0=16
declare -r cs0=17
declare -r d0=18
declare -r ds0=19
declare -r e0=20
declare -r f0=21
declare -r fs0=23
declare -r g0=24
declare -r gs0=25
declare -r a0=27
declare -r as0=29
declare -r b0=30
declare -r c1=32
declare -r cs1=34
declare -r d1=36
declare -r ds1=38
declare -r e1=41
declare -r f1=43
declare -r fs1=48
declare -r gs1=51
declare -r a1=55
declare -r as1=58
declare -r b1=61
'
declare -r c2=65
declare -r cs2=69
declare -r d2=73
# declare -r ds2=77
declare -r e2=82
# declare -r f2=87
# declare -r fs2=92
declare -r g2=97
# declare -r gs2=103
declare -r a2=110
# declare -r as2=116
declare -r b2=123
declare -r c3=130
declare -r cs3=138
# declare -r d3=146
declare -r ds3=155
declare -r e3=164
# declare -r f3=174
declare -r fs3=184
# declare -r g3=195
declare -r gs3=207
# declare -r a3=220
# declare -r as3=233
declare -r b3=246
# declare -r c4=261
declare -r cs4=277
# declare -r d4=293
declare -r ds4=311
declare -r e4=329
# declare -r f4=349
declare -r fs4=369
declare -r g4=391
declare -r gs4=415
declare -r a4=440
declare -r as4=466
declare -r b4=493
declare -r c5=523
declare -r cs5=554
declare -r d5=587
declare -r ds5=622
declare -r e5=659
# declare -r f5=698
declare -r fs5=739
declare -r g5=783
declare -r gs5=830
# declare -r a5=880
# declare -r as5=932
declare -r b5=987
# declare -r c6=1046
# declare -r cs6=1108
# declare -r d6=1174
declare -r ds6=1244
: '
declare -r e6=1318
declare -r f6=1396
declare -r fs6=1479
declare -r g6=1567
declare -r gs6=1661
declare -r a6=1760
declare -r as6=1864
declare -r b6=1975
'
# durations
declare -r fu=0.75
declare -r ha=0.5
declare -r qu=0.25
declare -r ei=0.125
declare -r si=0.0625
function note { # $1 = duration, $2 = note
echo $1 $2; play -q -V0 -n synth $1 sin $2;
}
function fu { note $fu $1; };
function ha { note $ha $1; };
function qu { note $qu $1; };
function ei { note $ei $1; };
function si { note $si $1; };
function brrrr-text { sleep 0.085; echo $1; } # for the ugly hack
function intro {
function dananah {
ei $gs4
ei $e4
ei $cs4
ei $e4
ei $gs4
ei $cs5
ei $gs4
ei $e4
ha $ds5
}
dananah
fu $cs5
dananah
ha $e5
qu $ds5
ha $ds5
ei $cs5
ei $gs4
ei $e4
qu $cs4
ei $cs5
ei $cs5
ei $gs4
ei $gs4
declare -r mu=0.085
function brrrr-text-real {
brrrr-text "$mu $e4"
brrrr-text "$mu $gs4"
brrrr-text "$mu $cs5"
brrrr-text "$mu $ds5"
brrrr-text "$mu $e5"
brrrr-text "$mu $ds5"
brrrr-text "$mu $gs4"
brrrr-text "$mu $e4"
}
function brrrr-mus {
play -q -V0 \
"|sox -n -p synth $mu sin $e4" \
"|sox -n -p synth $mu sin $gs4" \
"|sox -n -p synth $mu sin $cs5" \
"|sox -n -p synth $mu sin $ds5" \
"|sox -n -p synth $mu sin $e5" \
"|sox -n -p synth $mu sin $ds5" \
"|sox -n -p synth $mu sin $gs4" \
"|sox -n -p synth $mu sin $e4"
}
brrrr-text-real & brrrr-mus;
dananah
ha $e5
qu $ds5
}
function loopstart {
ha $ds5
ha $cs5
qu $e5
ha $ds5
ha $cs5
qu $e5
# why are the durations here so weird
qu $ds5
qu $cs5
note 0.1875 $e5
qu $ds5
qu $cs5
note 0.1875 $e5
note 0.375 $cs5
note 0.375 $ds5
fu $e5
}
function interlude { # from triangle
declare -r tri=0.0859
function tri { note $tri $1; };
# what an ugly hack!
function brrrr-text-real {
brrrr-text "$tri $cs3"
brrrr-text "$tri $cs3"
brrrr-text "$ei $gs3"
brrrr-text "$ei $cs3"
brrrr-text "$tri $gs3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $e3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $gs3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $e3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $a2"
brrrr-text "$tri $a2"
brrrr-text "$tri $e3"
brrrr-text "$ei $cs3"
brrrr-text "$tri $a2"
brrrr-text "$tri $a2"
brrrr-text "$tri $cs3"
brrrr-text "$tri $cs3"
brrrr-text "$tri $a2"
brrrr-text "$tri $e3"
brrrr-text "$tri $a2"
brrrr-text "$tri $a2"
brrrr-text "$tri $cs3"
brrrr-text "$tri $e3"
brrrr-text "$tri $a2"
brrrr-text "$tri $b2"
brrrr-text "$tri $b2"
brrrr-text "$tri $fs3"
brrrr-text "$tri $b2"
brrrr-text "$tri $b2"
brrrr-text "$tri $ds3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $b2"
brrrr-text "$tri $b2"
brrrr-text "$tri $fs3"
brrrr-text "$tri $ds3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $b2"
brrrr-text "$tri $ds3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $b2"
brrrr-text "$tri $c3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $ds3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $c3"
brrrr-text "$tri $c3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $c3"
brrrr-text "$tri $c3"
brrrr-text "$tri $fs3"
brrrr-text "$tri $c3"
}
function brrrr-mus {
play -q -V0 \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $ei sin $gs3" \
"|sox -n -p synth $ei sin $cs3" \
"|sox -n -p synth $tri sin $gs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $e3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $gs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $e3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $e3" \
"|sox -n -p synth $ei sin $cs3" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $e3" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $a2" \
"|sox -n -p synth $tri sin $cs3" \
"|sox -n -p synth $tri sin $e3" \
"|sox -n -p synth $tri sin $a2" \
\
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $ds3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $ds3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $ds3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $b2" \
"|sox -n -p synth $tri sin $c3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $ds3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $c3" \
"|sox -n -p synth $tri sin $c3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $c3" \
"|sox -n -p synth $tri sin $c3" \
"|sox -n -p synth $tri sin $fs3" \
"|sox -n -p synth $tri sin $c3"
}
brrrr-text-real & brrrr-mus;
}
function part1 {
function dahdodah {
note 0.375 $e4
ei $ds4
note 0.375 $e4
ei $ds4
qu $e4
}
function first {
dahdodah
qu $gs4
qu $e4
qu $ds4
qu $cs4
ei $gs3
ei $e4
ei $ds4
ei $b3
ei $fs3
note 1.5 $gs3
}
function second {
dahdodah
qu $as4
qu $b4
qu $ds5
qu $cs5
ei $gs4
ei $e5
ei $ds5
ei $b4
ei $fs4
}
ei $gs3
ei $cs4
ei $ds4
ei $fs4
first
second
note 1.5 $gs4
first
second
fu $cs5
}
function part2 {
function start {
note 0.375 $e5
ei $d5
qu $e5
ei $e5
ei $d5 # sox can't handle the speed of the original
ei $e5
ei $fs5
ei $g5
ei $fs5
ei $e5
ei $d5
ei $b4
ei $d5
qu $e5 #compromises have been made
ei $e5
ei $b5
ei $e5
ei $d5
ei $b4
ei $d5
ei $e5
ei $ds5
ei $cs5
ei $b4
qu $gs4
qu $b4
qu $cs5 # compromises have been made
ei $cs5
ei $gs5
note 0.375 $ds5
ei $gs5
qu $e5 # compromises have been made
ei $e5
ei $gs5
ei $fs5
ei $e5
ei $ds5
ei $b4
note 0.375 $cs5
}
function end {
ei $b4
ei $cs5
ei $b4
ei $gs4
ei $b4
qu $c5
qu $g5
}
function main {
start
end
note 0.625 $fs5 # compromises have been made
start
end
note 0.3 $fs5
note 0.35 $ds6
}
qu $cs5
qu $ds5
main; main;
}
function part3 { : '
function eb { ei $e2; ei $b2; };
function db { ei $d2; ei $b2; };
function csa { ei $cs2; ei $a2; };
function cgda {
ei $c2
ei $g2
ei $d2
ei $a2
}
function bckgrnd {
eb; eb;
db; db;
csa; csa;
cgda
}
bckgrnd; bckgrnd;
eb; eb;
fu $fs4
csa; csa;
qu $g4
qu $a4
qu $b4
ei $b2; eb;
fu $b4
csa; csa;
cgda
'
declare -r la=0.13
function la { note $la $1; };
qu $gs4
function brrrr-text-real1 {
brrrr-text "$la $cs4"
brrrr-text "$la $ds4"
brrrr-text "$la $e4"
brrrr-text "$la $ds4"
brrrr-text "$la $gs3"
brrrr-text "$la $ds4"
brrrr-text "$la $gs3"
brrrr-text "$la $ds4"
brrrr-text "$la $cs4"
brrrr-text "$la $fs3"
}
function brrrr-mus1 {
play -q -V0 \
"|sox -n -p synth $la sin $cs4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $e4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $gs3" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $gs3" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $cs4" \
"|sox -n -p synth $la sin $fs3"
}
brrrr-text-real1 & brrrr-mus1;
qu $e4
ei $fs4
function brrrr-text-real2 {
brrrr-text "$la $gs3"
brrrr-text "$la $fs3"
brrrr-text "$la $e3"
brrrr-text "$la $ds3"
brrrr-text "$la $e3"
brrrr-text "$la $gs3"
brrrr-text "$la $cs3"
brrrr-text "$la $gs3"
brrrr-text "$la $e3"
brrrr-text "$la $e4"
brrrr-text "$la $ds4"
brrrr-text "$la $cs4"
brrrr-text "$la $fs4"
brrrr-text "$la $e4"
brrrr-text "$la $ds4"
}
function brrrr-mus2 {
play -q -V0 \
"|sox -n -p synth $la sin $gs3" \
"|sox -n -p synth $la sin $fs3" \
"|sox -n -p synth $la sin $e3" \
"|sox -n -p synth $la sin $ds3" \
"|sox -n -p synth $la sin $e3" \
"|sox -n -p synth $la sin $gs3" \
"|sox -n -p synth $la sin $cs3" \
"|sox -n -p synth $la sin $gs3" \
"|sox -n -p synth $la sin $e3" \
"|sox -n -p synth $la sin $e4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $cs4" \
"|sox -n -p synth $la sin $fs4" \
"|sox -n -p synth $la sin $e4" \
"|sox -n -p synth $la sin $ds4"
}
brrrr-text-real2 & brrrr-mus2;
qu $cs3
function brrrr-text-real3 {
brrrr-text "$la $cs4"
brrrr-text "$la $e3"
brrrr-text "$la $ds4"
brrrr-text "$la $fs3"
}
function brrrr-mus3 {
play -q -V0 \
"|sox -n -p synth $la sin $cs4" \
"|sox -n -p synth $la sin $e3" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $fs3"
}
brrrr-text-real3 & brrrr-mus3;
qu $e4
function brrrr-text-real4 {
brrrr-text "$la $e4"
brrrr-text "$la $ds4"
brrrr-text "$la $e4"
brrrr-text "$la $gs4"
brrrr-text "$la $as4"
brrrr-text "$la $fs4"
brrrr-text "$la $ds4"
brrrr-text "$la $as4"
brrrr-text "$la $fs4"
brrrr-text "$la $ds4"
brrrr-text "$la $as4"
brrrr-text "$la $ds4"
}
function brrrr-mus4 {
play -q -V0 \
"|sox -n -p synth $la sin $e4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $e4" \
"|sox -n -p synth $la sin $gs4" \
"|sox -n -p synth $la sin $as4" \
"|sox -n -p synth $la sin $fs4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $as4" \
"|sox -n -p synth $la sin $fs4" \
"|sox -n -p synth $la sin $ds4" \
"|sox -n -p synth $la sin $as4" \
"|sox -n -p synth $la sin $ds4"
}
brrrr-text-real4 & brrrr-mus4;
qu $fs4
qu $e4
ei $gs4
}
trap 'exit 0' SIGUSR2
intro
while true
do
loopstart
interlude
part1
part2
part3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment