22
33bar_mappings = [{}, {}, {}]
44
5- actNumber = 3
6- pagedir = 'Act3'
7-
8- with open ('scanscore_xml/Act 3 .xml' , 'r' , encoding = 'utf8' ) as f :
9- tree = ET .parse (f )
10-
11- pageWidth = float (tree .find (".//page-width" ).text )
12- pageHeight = float (tree .find (".//page-height" ).text )
13-
14- defaultLeftMargin = float (tree .find (".//defaults" ).find (".//left-margin" ).text )
15- defaultRightMargin = float (tree .find (".//defaults" ).find (".//right-margin" ).text )
16- defaultTopMargin = float (tree .find (".//defaults" ).find (".//top-margin" ).text )
17- defaultBottomMargin = float (tree .find (".//defaults" ).find (".//bottom-margin" ).text )
18-
19- defaultStaffDistance = float (tree .find (".//defaults" ).find (".//staff-distance" ).text )
20-
21-
22- for child in tree .getroot ():
23- if child .tag == "part" :
24- page = 1
25- x = defaultLeftMargin
26- y = defaultTopMargin
27- for measure in child :
28- if measure .tag == "measure" :
29- measureWidth = float (measure .attrib ["width" ])
30-
31- p = measure .find ("print" )
32- if p :
33- if "new-page" in p .attrib :
34- page += 1
35- x = defaultLeftMargin + float (p .find ("system-layout" ).find ("system-margins" ).find ("left-margin" ).text )
36- y = defaultTopMargin + float (p .find ("system-layout" ).find ("top-system-distance" ).text )
37- if "new-system" in p .attrib :
38- x = defaultLeftMargin + float (p .find ("system-layout" ).find ("system-margins" ).find ("left-margin" ).text )
39-
40- bar_mappings [actNumber - 1 ][measure .attrib ["number" ]] = {
41- "page" : page , "image" : f"data/pages/{ pagedir } /sheet{ page } .png" ,
42- "x" : x / pageWidth , "y" : y / pageHeight , "width" : measureWidth / pageWidth , "height" : (pageHeight - defaultBottomMargin - y )/ pageHeight }
43- x += measureWidth
44- else :
45- raise (ValueError , "part should only have measures inside" )
5+ for actNumber in ( 2 , 3 ):
6+ pagedir = 'Act' + str ( actNumber )
7+
8+ with open (f 'scanscore_xml/Act { actNumber } .xml' , 'r' , encoding = 'utf8' ) as f :
9+ tree = ET .parse (f )
10+
11+ pageWidth = float (tree .find (".//page-width" ).text )
12+ pageHeight = float (tree .find (".//page-height" ).text )
13+
14+ defaultLeftMargin = float (tree .find (".//defaults" ).find (".//left-margin" ).text )
15+ defaultRightMargin = float (tree .find (".//defaults" ).find (".//right-margin" ).text )
16+ defaultTopMargin = float (tree .find (".//defaults" ).find (".//top-margin" ).text )
17+ defaultBottomMargin = float (tree .find (".//defaults" ).find (".//bottom-margin" ).text )
18+
19+ defaultStaffDistance = float (tree .find (".//defaults" ).find (".//staff-distance" ).text )
20+
21+
22+ for child in tree .getroot ():
23+ if child .tag == "part" :
24+ page = 1
25+ x = defaultLeftMargin
26+ y = defaultTopMargin
27+ for measure in child :
28+ if measure .tag == "measure" :
29+ measureWidth = float (measure .attrib ["width" ])
30+
31+ p = measure .find ("print" )
32+ if p is not None :
33+ if "new-page" in p .attrib :
34+ page += 1
35+ x = defaultLeftMargin + float (p .find ("system-layout" ).find ("system-margins" ).find ("left-margin" ).text )
36+ y = defaultTopMargin + float (p .find ("system-layout" ).find ("top-system-distance" ).text )
37+ if "new-system" in p .attrib :
38+ x = defaultLeftMargin + float (p .find ("system-layout" ).find ("system-margins" ).find ("left-margin" ).text )
39+
40+ bar_mappings [actNumber - 1 ][measure .attrib ["number" ]] = {
41+ "page" : page , "image" : f"data/pages/{ pagedir } /sheet{ page } .png" ,
42+ "x" : x / pageWidth , "y" : y / pageHeight , "width" : measureWidth / pageWidth , "height" : (pageHeight - defaultBottomMargin - y )/ pageHeight }
43+ x += measureWidth
44+ else :
45+ raise (ValueError , "part should only have measures inside" )
4646
4747print (bar_mappings )
0 commit comments