victor@2: victor@2: victor@2: ''' victor@2: Created on 13/06/2014 victor@2: victor@2: @author: victor victor@2: ''' victor@2: victor@2: from Process import PipelineAlignment victor@2: from Process import SymbolConversion victor@2: from Functions import MeasureFunctions victor@2: victor@2: class ProcessGroundS2: victor@2: victor@2: def getSimilarity(self,omrs,part): victor@2: ''' victor@2: main function to get the similarity vs the ground victor@2: victor@2: return: victor@2: result=percentage of similarity victor@2: errors= array with errors to write in xml victor@2: scoreWithErrors= score to write with colors victor@2: ''' victor@2: pa=PipelineAlignment() victor@2: mf=MeasureFunctions() victor@2: for omr in omrs: victor@2: try: victor@2: omr=mf.convertVoicesToChord(omr) victor@2: except: victor@2: pass victor@2: victor@2: omr_symbolsAlign=pa.alignGround(omrs,part) victor@2: victor@2: omr_ground=omr_symbolsAlign[0] victor@2: omr_part=omr_symbolsAlign[1] victor@2: victor@2: count=0 victor@2: symbolsLength=0 victor@2: Errors=[] victor@2: arrErrors=[] victor@2: for i in range(len(omr_ground)): victor@2: victor@2: sGround=omr_ground[i] victor@2: sOMR=omr_part[i] victor@2: if isinstance(sGround,list): victor@2: sGroundSimple=sGround[0] victor@2: else: victor@2: sGroundSimple=sGround victor@2: if isinstance(sOMR,list): victor@2: sOMRSimple=sOMR[0] victor@2: else: victor@2: sOMRSimple=sOMR victor@2: victor@2: #Removing grace notes victor@2: if(self.isGraceNote(sGround) or self.isGraceNote(sOMR)): victor@2: continue victor@2: victor@2: if(self.isBarline(sGroundSimple) or self.isBarline(sOMRSimple)): victor@2: continue victor@2: #Removing Time Signatures. PS introduce a lot extra time signatures victor@2: # if(self.isKeySignature(sGroundSimple) or self.isKeySignature(sOMRSimple)): victor@2: # continue victor@2: #Removing clef errors victor@2: if(self.isClef(sGroundSimple) or self.isClef(sOMRSimple)): victor@2: continue victor@2: if(self.isRest(sGroundSimple) or self.isRest(sOMRSimple)): victor@2: continue victor@2: #Removing extra rest due to voices victor@2: # if self.isRest(sOMRSimple): victor@2: # if sGroundSimple=="*": victor@2: # continue victor@2: victor@2: if (sGroundSimple==sOMRSimple): victor@2: if sGround[0]==sOMR[0] and sGround[1]==sOMR[1]:#not counting ties victor@2: #if sGround[0]==sOMR[0]: victor@2: count+=1 victor@2: else: victor@2: Errors.append([sGround,sOMR,i]) victor@2: arrErrors.append(i) victor@2: victor@2: else: victor@2: Errors.append([sGround,sOMR,i]) victor@2: arrErrors.append(i) victor@2: if sOMRSimple=="*": victor@2: try: victor@2: omr_part[i]=omr_ground[i] victor@2: omr_part[i][5]="#00ff00" #note missing victor@2: except: victor@2: print "error",omr_part[i] victor@2: elif sGroundSimple=="*": victor@2: try: victor@2: omr_part[i][5]="#0000ff" #extra note victor@2: except: victor@2: print "error",omr_part[i] victor@2: else: victor@2: try: victor@2: omr_part[i]=omr_ground[i] victor@2: omr_part[i][5]="#ff0000" #mistake in note victor@2: except: victor@2: print "error",omr_part[i] victor@2: victor@2: victor@2: symbolsLength+=1 victor@2: victor@2: result=(float(count)/symbolsLength)*100 victor@2: sc=SymbolConversion() victor@2: omr_part=sc.setVoices(omr_part) victor@2: scoreWithErrors=sc.convertM21(omr_part) victor@2: return result,Errors,scoreWithErrors victor@2: victor@2: def isGraceNote(self,s): victor@2: ''' victor@2: Returns true if the symbol is a grace note victor@2: ''' victor@2: if isinstance(s,list): victor@2: if s[0].find('N:')!=-1: victor@2: duration=s[1] victor@2: if float(duration)==0: victor@2: return True victor@2: victor@2: return False victor@2: victor@2: def isKeySignature(self,s): victor@2: ''' victor@2: Returns true if the symbol is a key signature victor@2: ''' victor@2: if s.find('KS:')!=-1: victor@2: return True victor@2: return False victor@2: victor@2: def isRest(self,s): victor@2: ''' victor@2: Returns true if the symbol is a rest victor@2: ''' victor@2: if s.find('R:')!=-1: victor@2: return True victor@2: return False victor@2: victor@2: def isBarline(self,s): victor@2: ''' victor@2: Returns true if the symbol is a barline victor@2: ''' victor@2: if s.find('!')!=-1: victor@2: return True victor@2: return False victor@2: victor@2: def isClef(self,s): victor@2: ''' victor@2: Returns true if the symbol is a clef victor@2: ''' victor@2: if s.find('CL:')!=-1: victor@2: return True victor@2: return False victor@2: victor@2: