#!/bin/bash #=========================================================================== # # FILE: serial1.sh # # USAGE: ./serial1.sh # # DESCRIPTION: generates tonerow randomly, compiles on Lilypond # and plays resulting MIDI file. Suitable for gentle # alarm in morning on my raspberry pi radio # OPTIONS: --- # REQUIREMENTS: lilypond, timidity, shuf # BUGS: --- # NOTES: --- # AUTHOR: Jonathan Kulp (), # CREATED: 03/20/2013 07:35:41 AM CDT # minor amendments by Robin Newman #=========================================================================== export DISPLAY=:0 #add so can run via ssh terminal #needs midori as default browser to run via ssh # save blank file from leafpad as empty.html, view file in Filemanager, right click # choose properties and set open with to Midori pitches=/tmp/pitches.ily random=/tmp/random.ily lilyfile=/tmp/tonerow.ly midifile=/tmp/tonerow.midi stem=$(readlink -f $lilyfile | sed -e 's/\..*$//') withrhythms=/tmp/withrhythms.ily chordOne=/tmp/chord1.ily chordTwo=/tmp/chord2.ily chordThree=/tmp/chord3.ily prime=/tmp/prime.txt getpitches (){ # first make a list of all 12 chromatic pitches # using lilypond's naming conventions # one per line b/c it's easier to shuffle, add rhythms, etc cat > $pitches << EOFallpitches c' cis' d' dis' e' f' fis' g' gis' a' bes' b' EOFallpitches # now run them through the shuf command to put them in random order shuf $pitches > $random } # ------------ end of getpitches --------------- add_rhythms(){ # todo: randomize the rhythms sed -f - $random > $withrhythms << EOFrhythms 1s/$/4/ 3s/$/4../ 4s/$/16/ 5s/$/4/ 6s/$/4./ 7s/$/8/ 8s/$/4/ 9s/$/8/ 10s/$/8/ 11s/$/8/ 12s/$/8/ EOFrhythms } # ------------ end of add_rhythms --------------- chords(){ # stack up the notes of the row in 3 chords of # 4 notes each cat $random | sed -n '1,4p' \ | sed -e :a -e '$!N;s/\n/ /;ta' -e 'P;D' \ | sed -e 's/.*/<&>2/' > $chordOne #line amended from original cat $random | sed -n '5,8p' \ | sed -e :a -e '$!N;s/\n/ /;ta' -e 'P;D' \ | sed -e 's/.*/<&>4/' > $chordTwo #line amended from original cat $random | sed -n '9,12p' \ | sed -e :a -e '$!N;s/\n/ /;ta' -e 'P;D' \ | sed -e 's/.*/<&>2./' > $chordThree #line amended from original } # ------------ end of chords --------------- make_lily_file (){ # determine lilypond version for later inclusion version=$(lilypond --version | grep LilyPond | cut -d " " -f3) # make it cat the random list of pitches lilypitches=$(cat $withrhythms $chordOne $chordTwo $chordThree) # assemble the lilypond source file, sticking the # pitches in at the right place cat > $lilyfile << EOFscore \\score { { \\version "$version" \\time 3/4 #(set-accidental-style 'dodecaphonic) #(set-global-staff-size 24) \\set Staff.midiInstrument = "violin" \\partial 4 $lilypitches \\bar "|." } \\layout {} \\midi {\\tempo 4 = 100} } EOFscore #cat $lilyfile } # ------------ end of make_lily_file --------------- runlily(){ # compile the score redirecting all console output to /dev/null lilycmd="lilypond -dno-point-and-click -ddelete-intermediate-files -dpreview" $lilycmd $lilyfile &> /dev/null } # ------------ end of runlily --------------- html(){ web="$stem".html image="$stem".preview.png midi="$stem".midi cat > $web << EOFhtml 12-Tone Tune of the Day

Random 12-Tone Tune of the Day

randomly generated 12-tone
row

Midi file

Generated with bash and Lilypond

EOFhtml } # ------------ end of html --------------- # RUN ALL FUNCTIONS HERE cd /tmp getpitches chords add_rhythms make_lily_file runlily # sleep for half a second to make sure Lilypond has time to compile sleep .5 html #rm -f ~/.config/midori/session.xbel #neater if using midori. deletes other tabs #add & to next line to run as sub process so can work over ssh xdg-open $web & #wait for browser to open added a delay sleep 8 timidity $midifile &> /dev/null #clean stuff up rm /tmp/*.ily /tmp/*.eps # ------------ end of script ---------------