victor@2
|
1
|
victor@2
|
2
|
victor@2
|
3 '''
|
victor@2
|
4 Created on 13/06/2014
|
victor@2
|
5
|
victor@2
|
6 @author: victor
|
victor@2
|
7 '''
|
victor@2
|
8
|
victor@2
|
9 from Process import PipelineAlignment
|
victor@2
|
10 from Process import SymbolConversion
|
victor@2
|
11 from Functions import MeasureFunctions
|
victor@2
|
12
|
victor@2
|
13 class ProcessGroundS2:
|
victor@2
|
14
|
victor@2
|
15 def getSimilarity(self,omrs,part):
|
victor@2
|
16 '''
|
victor@2
|
17 main function to get the similarity vs the ground
|
victor@2
|
18
|
victor@2
|
19 return:
|
victor@2
|
20 result=percentage of similarity
|
victor@2
|
21 errors= array with errors to write in xml
|
victor@2
|
22 scoreWithErrors= score to write with colors
|
victor@2
|
23 '''
|
victor@2
|
24 pa=PipelineAlignment()
|
victor@2
|
25 mf=MeasureFunctions()
|
victor@2
|
26 for omr in omrs:
|
victor@2
|
27 try:
|
victor@2
|
28 omr=mf.convertVoicesToChord(omr)
|
victor@2
|
29 except:
|
victor@2
|
30 pass
|
victor@2
|
31
|
victor@2
|
32 omr_symbolsAlign=pa.alignGround(omrs,part)
|
victor@2
|
33
|
victor@2
|
34 omr_ground=omr_symbolsAlign[0]
|
victor@2
|
35 omr_part=omr_symbolsAlign[1]
|
victor@2
|
36
|
victor@2
|
37 count=0
|
victor@2
|
38 symbolsLength=0
|
victor@2
|
39 Errors=[]
|
victor@2
|
40 arrErrors=[]
|
victor@2
|
41 for i in range(len(omr_ground)):
|
victor@2
|
42
|
victor@2
|
43 sGround=omr_ground[i]
|
victor@2
|
44 sOMR=omr_part[i]
|
victor@2
|
45 if isinstance(sGround,list):
|
victor@2
|
46 sGroundSimple=sGround[0]
|
victor@2
|
47 else:
|
victor@2
|
48 sGroundSimple=sGround
|
victor@2
|
49 if isinstance(sOMR,list):
|
victor@2
|
50 sOMRSimple=sOMR[0]
|
victor@2
|
51 else:
|
victor@2
|
52 sOMRSimple=sOMR
|
victor@2
|
53
|
victor@2
|
54 #Removing grace notes
|
victor@2
|
55 if(self.isGraceNote(sGround) or self.isGraceNote(sOMR)):
|
victor@2
|
56 continue
|
victor@2
|
57
|
victor@2
|
58 if(self.isBarline(sGroundSimple) or self.isBarline(sOMRSimple)):
|
victor@2
|
59 continue
|
victor@2
|
60 #Removing Time Signatures. PS introduce a lot extra time signatures
|
victor@2
|
61 # if(self.isKeySignature(sGroundSimple) or self.isKeySignature(sOMRSimple)):
|
victor@2
|
62 # continue
|
victor@2
|
63 #Removing clef errors
|
victor@2
|
64 if(self.isClef(sGroundSimple) or self.isClef(sOMRSimple)):
|
victor@2
|
65 continue
|
victor@2
|
66 if(self.isRest(sGroundSimple) or self.isRest(sOMRSimple)):
|
victor@2
|
67 continue
|
victor@2
|
68 #Removing extra rest due to voices
|
victor@2
|
69 # if self.isRest(sOMRSimple):
|
victor@2
|
70 # if sGroundSimple=="*":
|
victor@2
|
71 # continue
|
victor@2
|
72
|
victor@2
|
73 if (sGroundSimple==sOMRSimple):
|
victor@2
|
74 if sGround[0]==sOMR[0] and sGround[1]==sOMR[1]:#not counting ties
|
victor@2
|
75 #if sGround[0]==sOMR[0]:
|
victor@2
|
76 count+=1
|
victor@2
|
77 else:
|
victor@2
|
78 Errors.append([sGround,sOMR,i])
|
victor@2
|
79 arrErrors.append(i)
|
victor@2
|
80
|
victor@2
|
81 else:
|
victor@2
|
82 Errors.append([sGround,sOMR,i])
|
victor@2
|
83 arrErrors.append(i)
|
victor@2
|
84 if sOMRSimple=="*":
|
victor@2
|
85 try:
|
victor@2
|
86 omr_part[i]=omr_ground[i]
|
victor@2
|
87 omr_part[i][5]="#00ff00" #note missing
|
victor@2
|
88 except:
|
victor@2
|
89 print "error",omr_part[i]
|
victor@2
|
90 elif sGroundSimple=="*":
|
victor@2
|
91 try:
|
victor@2
|
92 omr_part[i][5]="#0000ff" #extra note
|
victor@2
|
93 except:
|
victor@2
|
94 print "error",omr_part[i]
|
victor@2
|
95 else:
|
victor@2
|
96 try:
|
victor@2
|
97 omr_part[i]=omr_ground[i]
|
victor@2
|
98 omr_part[i][5]="#ff0000" #mistake in note
|
victor@2
|
99 except:
|
victor@2
|
100 print "error",omr_part[i]
|
victor@2
|
101
|
victor@2
|
102
|
victor@2
|
103 symbolsLength+=1
|
victor@2
|
104
|
victor@2
|
105 result=(float(count)/symbolsLength)*100
|
victor@2
|
106 sc=SymbolConversion()
|
victor@2
|
107 omr_part=sc.setVoices(omr_part)
|
victor@2
|
108 scoreWithErrors=sc.convertM21(omr_part)
|
victor@2
|
109 return result,Errors,scoreWithErrors
|
victor@2
|
110
|
victor@2
|
111 def isGraceNote(self,s):
|
victor@2
|
112 '''
|
victor@2
|
113 Returns true if the symbol is a grace note
|
victor@2
|
114 '''
|
victor@2
|
115 if isinstance(s,list):
|
victor@2
|
116 if s[0].find('N:')!=-1:
|
victor@2
|
117 duration=s[1]
|
victor@2
|
118 if float(duration)==0:
|
victor@2
|
119 return True
|
victor@2
|
120
|
victor@2
|
121 return False
|
victor@2
|
122
|
victor@2
|
123 def isKeySignature(self,s):
|
victor@2
|
124 '''
|
victor@2
|
125 Returns true if the symbol is a key signature
|
victor@2
|
126 '''
|
victor@2
|
127 if s.find('KS:')!=-1:
|
victor@2
|
128 return True
|
victor@2
|
129 return False
|
victor@2
|
130
|
victor@2
|
131 def isRest(self,s):
|
victor@2
|
132 '''
|
victor@2
|
133 Returns true if the symbol is a rest
|
victor@2
|
134 '''
|
victor@2
|
135 if s.find('R:')!=-1:
|
victor@2
|
136 return True
|
victor@2
|
137 return False
|
victor@2
|
138
|
victor@2
|
139 def isBarline(self,s):
|
victor@2
|
140 '''
|
victor@2
|
141 Returns true if the symbol is a barline
|
victor@2
|
142 '''
|
victor@2
|
143 if s.find('!')!=-1:
|
victor@2
|
144 return True
|
victor@2
|
145 return False
|
victor@2
|
146
|
victor@2
|
147 def isClef(self,s):
|
victor@2
|
148 '''
|
victor@2
|
149 Returns true if the symbol is a clef
|
victor@2
|
150 '''
|
victor@2
|
151 if s.find('CL:')!=-1:
|
victor@2
|
152 return True
|
victor@2
|
153 return False
|
victor@2
|
154
|
victor@2
|
155
|