victor@2: ''' victor@2: Created on 10/11/2014 victor@2: victor@2: @organization: Lancaster University & University of Leeds victor@2: @version: 1.0 victor@2: Created on 11/12/2014 victor@2: victor@2: @author: Victor Padilla victor@2: @contact: v.padilla@lancaster.ac.uk victor@2: victor@2: Functions related to the full score alignment. victor@2: It takes the n parts and align with the best omr full score victor@2: for the missing rest measuress victor@2: ''' victor@2: from music21 import converter victor@2: from music21 import stream victor@2: from Functions import HashFunctions victor@2: from Functions import FilesFunctions victor@2: victor@2: victor@2: class FullScoreAlignment: victor@2: ''' victor@2: Class for the full score alignment victor@2: victor@2: usage: victor@2: victor@2: fsa=FullScoreAlignment() victor@2: idCompleteScoreBetter=fsa.getIdBetterOMRFullScore(fsOMRs,partsNumber) victor@2: finalScore=fsa.runSynchronisingMeasuresNJ(subdirnameFullScore,subdirnameParts,fsOMRs[idCompleteScoreBetter]) victor@2: finalScore.write("musicxml", dirGeneral+'/finalScore.xml') victor@2: victor@2: ''' victor@2: def runSynchronisingMeasuresNJ(self,subdirnameParts,completeScore): victor@2: ''' victor@2: This function takes the different result.S2.xml files to construct victor@2: the final output. victor@2: victor@2: Example: victor@2: fsa=FullScoreAlignment() victor@2: idCompleteScoreBetter=fsa.getIdBetterOMRFullScore(fsOMRs,partsNumber) victor@2: finalScore=fsa.runSynchronisingMeasuresNJ(subdirnameFullScore,subdirnameParts,fsOMRs[idCompleteScoreBetter]) victor@2: finalScore.write("musicxml", dirGeneral+'/finalScore.xml') victor@2: ''' victor@2: victor@2: gapOMRs=[] victor@2: parts=[] victor@2: completeScoreParts=[] victor@2: victor@2: # Convert to Hash the better full score victor@2: hf=HashFunctions() victor@2: for p in completeScore.getElementsByClass(stream.Part): victor@2: sc=stream.Score() victor@2: sc.append(p) victor@2: completeScoreParts.append(sc) victor@2: completeScoreHash=hf.getHash(completeScoreParts) victor@2: victor@2: # Convert to hash the parts victor@2: for dirname in sorted(subdirnameParts): victor@2: print "--- ",dirname victor@2: path = dirname+"/XML/" victor@2: partId=int(dirname.split('\\')[-1]) victor@2: print partId victor@2: resultS2File=path+ "result.S2.xml" victor@2: resultS2=converter.parse(resultS2File,forceSource=False) victor@2: parts.append(resultS2) victor@2: partsHash=hf.getHash(parts) victor@2: victor@2: victor@2: for partHash in partsHash: victor@2: index=partsHash.index(partHash) victor@2: h=[] victor@2: h.append(partHash) victor@2: h.append(completeScoreHash[index]) victor@2: hf.alignHash(h) victor@2: partsHash[index]=h[0] victor@2: completeScoreHash[index]=h[1] victor@2: victor@2: gaps=hf.getGapsFromHashArray(h) victor@2: gapOMRs.append(gaps) victor@2: if(index