From d66b29b40071a6cbaf00e0d5b6d9041f24dbe45a Mon Sep 17 00:00:00 2001 From: Fabien Givors Date: Fri, 18 May 2018 14:38:55 +0200 Subject: [PATCH] midi and partition files generation --- Music/BoosterMusic/AmazingGraceMid.abc | 1 - .../{AmazingGrace.mma => AmazingGraceMid.mma} | 0 Music/Makefile | 41 ++++ Music/makeall | 15 -- Music/makemusic | 232 ------------------ Music/makescore | 12 - 6 files changed, 41 insertions(+), 260 deletions(-) rename Music/BoosterMusic/{AmazingGrace.mma => AmazingGraceMid.mma} (100%) create mode 100644 Music/Makefile delete mode 100755 Music/makeall delete mode 100755 Music/makemusic delete mode 100755 Music/makescore diff --git a/Music/BoosterMusic/AmazingGraceMid.abc b/Music/BoosterMusic/AmazingGraceMid.abc index 2f88058..ea1a663 100644 --- a/Music/BoosterMusic/AmazingGraceMid.abc +++ b/Music/BoosterMusic/AmazingGraceMid.abc @@ -4,7 +4,6 @@ Q: "English Waltz " 87 C: Traditional M: 3/4 % time signature L: 1/4 % default length -%%staves {RH LH} V: 1 clef=treble %%MIDI channel 4 %%MIDI program 1 4 diff --git a/Music/BoosterMusic/AmazingGrace.mma b/Music/BoosterMusic/AmazingGraceMid.mma similarity index 100% rename from Music/BoosterMusic/AmazingGrace.mma rename to Music/BoosterMusic/AmazingGraceMid.mma diff --git a/Music/Makefile b/Music/Makefile new file mode 100644 index 0000000..5870d5e --- /dev/null +++ b/Music/Makefile @@ -0,0 +1,41 @@ +dirs:= BeginnerCourse BoosterMusic +output:= PianoBoosterMusic +ABCs:=$(foreach dir, $(dirs), $(wildcard $(dir)/*.abc)) +MMAs:=$(filter-out $(foreach dir, $(dirs), $(wildcard $(dir)/*Lib.mma)),$(foreach dir, $(dirs), $(wildcard $(dir)/*.mma))) +MIDs:=$(foreach mma, $(MMAs:.mma=.mid), $(output)/$(mma)) +SOLs:=$(foreach abc, $(ABCs:.abc=.solo.mid), $(abc)) +SVGs:=$(foreach abc, $(ABCs:.abc=001.svg), $(output)/$(abc)) +MDs=:$(ABCs:.abc=_en.md) + +all: $(output)/README.html + +%.html: %.md + markdown $< > $@ + +$(output)/README.md: $(SVGs) $(MIDs) + cat music.md.start > $@ + sh -c '$(foreach mma, $(MMAs), \ + echo "## $(basename $(notdir $(mma)))"; \ + echo "![score]($(basename $(mma))001.svg)"; \ + echo ""; \ + [ -f "$(basename $(mma))_en.md" ] && cat "$(basename $(mma))_en.md" || true ; \ + echo "[midi file]($(basename $(mma)).mid)" ; \ + )' >> "$@" + cat music.md.end >> $@ + +$(output)/%001.svg: %.abc + $(foreach dir, $(dirs), mkdir -p $(output)/$(dir)) + abcm2ps -g -s 0.9 -c "$<" -O "$(output)/$(basename $<).svg" + +%.solo.mid: %.abc + abc2midi "$<" -o "$@" -RS + +$(output)/%.mid: %.mma $(SOLs) + $(foreach dir, $(dirs), mkdir -p $(output)/$(dir)) + sh -c 'cd $(dir $<); mma "$(notdir $<)" -o -f "../$@"' + +clean: + rm -f $(SOLs) $(wildcard $(output)/*/*.svg) + +cleanall: clean + rm -fr $(output) diff --git a/Music/makeall b/Music/makeall deleted file mode 100755 index 57f6e57..0000000 --- a/Music/makeall +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -SONGS=" - SkipToMyLoo - Greensleeves - ScarboroughFair - FrereJacques - AmazingGrace -" - -# bash for loop -for s in $SONGS; do - ./makemusic2 $s - #./makescore $s -done diff --git a/Music/makemusic b/Music/makemusic deleted file mode 100755 index c3b6072..0000000 --- a/Music/makemusic +++ /dev/null @@ -1,232 +0,0 @@ -#!/usr/bin/env python -import os -import sys - - -#mmaExec = "/home/louis/active/src/mma/mma-current/mma.py" -mmaExec = "/home/louis/active/src/mma-bin-1.5d/mma.py" -midiInfo = "InfoPages" - -class songDetails: - - def copyTranslations(self, outputDir): - infoSrcDir = self.directory + "/" + midiInfo ; - infoOutputDir = outputDir + '/' + self.directory + '/' + midiInfo - - - if os.path.isdir(infoSrcDir): - files = os.listdir(infoSrcDir) - for f in files: - - if (f.find(self.name)==0): - if not os.path.isdir(infoOutputDir): - os.mkdir(infoOutputDir) - os.system("cp \"{0}/{1}\" \"{2}/{3:02}-{1}\"".format(infoSrcDir, f, infoOutputDir, self.index)) - - def getOutputName(self): - return "/%02d-%s"%(self.index, self.name) - - - def createMusic(self, outputDir, webDir, tempDir): # create music - - if not os.path.isdir(outputDir + '/' + self.directory): - os.mkdir(outputDir + '/' + self.directory) - if not os.path.isdir(webDir + '/' + self.directory): - os.mkdir(webDir + '/' + self.directory) - if not os.path.isdir(tempDir + '/' + self.directory): - os.mkdir(tempDir + '/' + self.directory) - - outputName = outputDir + '/' + self.directory + self.getOutputName() - webName = webDir + '/' + self.directory + "/" + self.name - tempName = tempDir + '/' + self.directory + self.getOutputName() - - srcName = self.directory + "/" + self.name - - abcMidiName = srcName - if os.path.isfile(abcMidiName + "Mid.abc"): - abcMidiName += "Mid" - print "abcName " + srcName - - # http://moinejf.free.fr/ (abcplus.sourceforge.net) - cmd = "abc2midi \"{0}.abc\" -o \"{1}.solo.mid\" -RS".format(abcMidiName, abcMidiName) - print cmd - if os.system(cmd) != 0: - return False - - # http://mellowood.ca/mma/ - cmd = "cd \"{0}\";{1} \"{2}.mma\" -f \"../{3}.mid\"".format( self.directory, mmaExec, self.name, outputName ) - print cmd - if os.system(cmd) != 0: - return False - - psName = srcName - - if os.path.isfile(psName + "Ps.abc"): - psName += "Ps" - print "psName " + psName - - # http://abc.sourceforge.net/ (abcplus.sourceforge.net) - cmd = "abcm2ps -s 0.8 -c \"{0}.abc\" -O \"{1}.ps\"" .format( psName, tempName ) - print cmd - if os.system(cmd) != 0: - return False - - # http://www.ghostscript.com/ - ps2pdf is part of ghostscript - cmd = "ps2pdf \"{0}.ps\" \"{1}.pdf\"".format( tempName, outputName ) - print cmd - if os.system(cmd) != 0: - return False - os.remove("{0}.ps".format(tempName)) - - - cmd = "abcm2ps -E -s 1.0 -c \"{0}.abc\" -O \"{1}.ps\"".format( psName, tempName) - print cmd - if os.system(cmd) != 0: - return False - - - - - # from imagemagick - cmd = "convert -density 90x90 -alpha off \"{0}001.eps\" \"{1}.png\"" .format(tempName, webName) - print cmd - if os.system(cmd) != 0: - return False - - self.copyTranslations(outputDir) - - os.remove("{0}001.eps".format(tempName )) - - os.system("cp \"{0}.abc\" \"{1}.abc\"".format(abcMidiName, webName)) - os.system("cp \"{0}.mma\" \"{1}.mma\"".format(srcName, webName)) - os.system("cp \"{0}.pdf\" \"{1}.pdf\"".format(outputName, webName)) - os.system("cp \"{0}.mid\" \"{1}.mid\"".format(outputName, webName)) - pbCfg = self.directory + "/" + "pb.cfg" - - if os.path.isfile(pbCfg): - os.remove(pbCfg) - - - - f = open( webDir + "/" + self.directory + ".html", 'a') - if f == 0: - return False - webName = self.directory + "/" + self.name - - str = """ -

-

- Piano Music - {0} - Piano Music - {0}

- Download the MIDI file {0}.mid - and the pdf {0}.pdf
- (This music was generated from the {0}.abc - and the MMA file {0}.mma )
-

-""".format(self.name, webName) - - f.write(str) - f.close() - - - return True - -def addSong(songs, directory, index, name): - details = songDetails() - details.directory = directory - details.index = index - details.name = name - songs.append(details) - - -def runMain(argv): - - if len(argv) > 3: - print "usage: makescore args" - return - - doSingleSong = "" - doSingleNumber = -1 - - if len(argv) == 2: - #doSingleSong = argv[1] - doSingleNumber = int(argv[1]) - 1 - #doSingleNumber = 7 - - outputRootDir = "Output" - zipFileName = "BoosterMusicBooks" - MUSIC_RELEASE = "1" - outputDir = outputRootDir + '/' + zipFileName + MUSIC_RELEASE - webDir = outputRootDir + '/' + "MusicWeb" - tempDir = outputRootDir + '/' + "Temp" - - if not os.path.isdir("Output"): - os.mkdir("Output") - if not os.path.isdir(outputDir): - os.mkdir(outputDir) - if not os.path.isdir(webDir): - os.mkdir(webDir) - if not os.path.isdir(tempDir): - os.mkdir(tempDir) - - musicHtmlPage = webDir + "/music.html" - #musicHtmlPage = "music.html" - if os.path.isfile(musicHtmlPage): - os.remove(musicHtmlPage) - os.system("cp music.html.start \"{0}\"".format(webDir + "/" + "Beginner Course" + ".html")) - os.system("cp music.html.start \"{0}\"".format(webDir + "/" + "Booster Music" + ".html")) - - - songs=[] - - addSong(songs, "Beginner Course", 1, "StartWithMiddleC") - addSong(songs, "Beginner Course", 2, "ChordOfCMajor") - addSong(songs, "Beginner Course", 3, "UpAndDown") - addSong(songs, "Beginner Course", 4, "ClairDeLaLune") - addSong(songs, "Beginner Course", 5, "ChordOfFMajor") - addSong(songs, "Beginner Course", 6, "DownAndUp") - addSong(songs, "Booster Music", 1, "ClairDeLaLune") - addSong(songs, "Booster Music", 2, "LavendersBlue") - addSong(songs, "Booster Music", 3, "SkipToMyLoo") - addSong(songs, "Booster Music", 4, "FrereJacques") - addSong(songs, "Booster Music", 5, "ScarboroughFair") - addSong(songs, "Booster Music", 6, "Greensleeves") - addSong(songs, "Booster Music", 7, "AmazingGrace") - - result = False - found = False - for n,song in enumerate(songs): - if len(doSingleSong) > 0: - if doSingleSong != song.name: - continue - if doSingleNumber != -1 and doSingleNumber != n: - continue - - found = True - result = song.createMusic(outputDir, webDir, tempDir) - if not result: - break - - if found == False: - for n,song in enumerate(songs): - print "{0} {1}".format(n, song.name) - return - - - if result and len(doSingleSong) == 0 and doSingleNumber == -1: - os.system("cat music.html.end >>\"{0}\"".format(webDir + "/" + "Beginner Course" + ".html")) - os.system("cat music.html.end >>\"{0}\"".format(webDir + "/" + "Booster Music" + ".html")) - - if os.path.isfile("{0}/{1}.zip".format(outputRootDir, zipFileName )): - os.remove("{0}/{1}.zip".format(outputRootDir, zipFileName )) - - #cmd = "gzip \"{0}\" >\"{1}.zip\"" .format(outputDir, outputDir ) - cmd = "cd {0};zip -r {1}.zip \"{2}\" " .format(outputRootDir, zipFileName, zipFileName + MUSIC_RELEASE ) - print cmd - if os.system(cmd) != 0: - return False - - - -if __name__ == "__main__": - runMain(sys.argv) diff --git a/Music/makescore b/Music/makescore deleted file mode 100755 index ba402d9..0000000 --- a/Music/makescore +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -#rename to makemusic.bat to run on windows - -# create the output dir if does not exist -[ -a PianoBoosterMusic ] || mkdir "PianoBoosterMusic" - -# from abc plus -abcm2ps -s 0.9 -c $1.abc -O PianoBoosterMusic/$1.ps - -# from imagemagick -convert -density 120x120 PianoBoosterMusic/$1.ps PianoBoosterMusic/$1.png -