#!/bin/bash # Bash script for playing procedural music # Polprog 2019 # 2 clause bsd licence, http://polprog.net beep_params="" beep="beep" bpm=220 quarter=$(( 60000/$bpm )) eigth=$(( $quarter/2 )) sixteenth=$(( $quarter/4)) # Note frequencies # from: http://pages.mtu.edu/~suits/notefreqs.html C=261 Db=277 D=293 Eb=311 E=329 F=349 Gb=369 G=392 Ab=415 A=440 Bb=466 B=493 # 72 c wide logoline=0 logo=( " __" " ______ ______ __ ______ ______ ______ ______/\\ \\" " /\\ __ \\/\\ __ \\/\\ \\ /\\ __ \\/\\ __ \\/\\ __ \\/\\ ___\\\\ \\_\\" " \\ \\ ___\\ \\ \\/\\ \\ \\ \\___\\ \\ ___\\ \\ __<_ \\ \\/\\ \\ \\ \\__ \\\\/_/_" " \\ \\_\\__/\\ \\_____\\ \\_____\\ \\_\\__/\\ \\ \\ \\ \\_\\_____\\ \\_____\\ /\\_\\" " \\/_/ \\/_____/\\/_____/\\/_/ \\/_/ /_/\\/_____/\\/_____/ \\/_/" " ___________________________________________________________" " /\\__________________________________________________________\\" " \\/__________________________________________________________/ ~2019" " ____ __ ____ ____ _____________" " _____/ __ \\ / / __ \\ __ \\___ | ___________ |" " \\ / /_/ // / /_/ // _\\/ / ||~# beep ||" " /__/ ____// / ____// / \\___\\ || ||" " / / / /_/ / \\ \\_/ / || ||~." " /_/ /____// \\___/ ||___________|| \\" " |_____________| /" " __/_________\\___ \\" " /__________ __ __ \\~" " /___________ _ ___ \\" " /_____________________\\" " Hope you enjoyed! :)" " " " http://polprog.net" ) beeps=( "-f 1000 -l 50 -n -f 1300 -l 250" #GBC "-f 190 -l 50 -n -f 250 -l 50 -n -f 200 -l 50 -n -f 260 \ -l 50 -n -f 210 -l 50 -n -f 270 -l 50 -n -f 280 -l 50" #mario shroom "-f 440 -l 50 -n -f 400 -l 50 -n -f 360 -l 50 -n -f 320 -l 50 -n -f 280 -l 50 -n -f 240 -l 50" #space invaders ) trap ctrl_c INT; ctrl_c() { exit 0; } if [ `tput cols` -lt 73 ]; then echo -e "Your terminal is too narrow\nIt must be wider than 73 cols :("; exit 1; fi echo -n "Trying to beep..." $beep ${beeps[$(($RANDOM % 3))]}; if [ "$?" -ne 0 ]; then echo "No permission to beep. Run this demo in a TTY or chmod +s your beep"; exit 1; fi echo "OK!"; sleep 1; #octave arp arp1(){ notea=$1 noteb=$(($1*2)) for i in `seq 1 4`; do $beep -f $notea -l $eigth -n -f $noteb -l $eigth; done; } #params: note1 note2 note3 notelen pauselen #result [note1] [note1] [note2] [note3] melody1(){ $beep -f $1 -l $4 -D $5 -r 2 ; $beep -f $2 -l $4 -D $5 -n -f $3 -l $4 -D $5; } #params: note1 note2 note3 notelen pauselen #result [note1] [note2] [note3] [note2] [note2] [note3] [note2] [note1] melody2(){ $beep -f $1 -l $4 -D $5 -n -f $3 -l $4 -D $5 ; $beep -f $3 -l $4 -D $5 -n -f $2 -l $4 -D $5 ; $beep -f $2 -l $4 -D $5 -n -f $3 -l $4 -D $5 ; $beep -f $2 -l $4 -D $5 -n -f $1 -l $4 -D $5 ; } #params 3 notes # result 4*melody2, 4 revolutions happy_phrase1(){ melody2 $1 $2 $3 $sixteenth $sixteenth; melody2 $2 $3 $(($1 * 2)) $sixteenth $sixteenth; melody2 $3 $(($1 * 2)) $(($2 * 2)) $sixteenth $sixteenth; melody2 $(($1 * 2)) $(($2 * 2)) $(($3 * 2)) $sixteenth $sixteenth; } show_logo_line(){ echo -e "${logo[$logoline]}"; logoline=$((logoline+1)); } for i in `seq 1 3`; do melody1 $C $E $G $eigth $eigth; melody1 $A $D $F $sixteenth $sixteenth; melody1 $E $E $E $sixteenth $sixteenth; show_logo_line; done; melody1 $G $E $G $eigth $eigth; melody1 $A $D $A $sixteenth $sixteenth; melody1 $G $E $C $sixteenth $sixteenth; show_logo_line; for i in `seq 1 2`; do arp1 $C; arp1 $E; arp1 $G; arp1 $(( $C * 2)); done; show_logo_line; for i in `seq 1 2`; do arp1 $A; arp1 $(( $D * 2)); arp1 $(( $F * 2)); arp1 $(( $A * 2)); done; show_logo_line; for i in `seq 1 3`; do melody1 $D $F $A $eigth $eigth; melody1 $C $E $G $sixteenth $sixteenth; melody1 $F $F $F $sixteenth $sixteenth; show_logo_line; done; melody1 $A $D $A $eigth $eigth; melody1 $C $E $G $sixteenth $sixteenth; melody1 $G $E $C $sixteenth $sixteenth; show_logo_line; for i in `seq 1 2`; do arp1 $D; arp1 $F; arp1 $A; arp1 $(($D * 2)); done show_logo_line; for i in `seq 1 2`; do arp1 $C; arp1 $E; arp1 $G; arp1 $(($C * 2)); done show_logo_line; happy_phrase1 $C $E $G; show_logo_line; happy_phrase1 $Eb $Gb $Bb; show_logo_line; happy_phrase1 $D $F $A; show_logo_line; happy_phrase1 $(($B / 2)) $E $Gb; show_logo_line; show_logo_line; for i in `seq 1 2`; do arp1 $Eb; arp1 $Gb; arp1 $Bb; arp1 $(($Eb * 2)); show_logo_line; done; for i in `seq 1 2`; do arp1 $C; arp1 $E; arp1 $G; arp1 $(( $C * 2)); show_logo_line; done; melody1 $C $C $C $sixteenth $sixteenth; melody1 $E $E $E $sixteenth $sixteenth; melody1 $G $G $G $sixteenth $sixteenth; melody1 $(($C * 2)) $(($C * 2)) $(($C * 2)) $sixteenth $sixteenth; show_logo_line; melody1 $C $C $C $eigth $sixteenth; melody1 $E $E $E $eigth $sixteenth; melody1 $G $G $G $eigth $sixteenth; melody1 $(($C * 2)) $(($C * 2)) $(($C * 2)) $eigth $sixteenth; show_logo_line; melody1 $C $C $C $quarter $sixteenth; melody1 $E $E $E $quarter $sixteenth; melody1 $G $G $G $quarter $sixteenth; melody1 $(($C * 2)) $(($C * 2)) $(($C * 2)) $quarter 0; show_logo_line; #inhibit last plain beep beep_params="$beep_params -l 1"; #for i in ${!logo[*]}; do # show_logo_line; sleep 1; # done; #echo "$beep_params" #$beep $beep_params