-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_data_tools.py
44 lines (33 loc) · 1.59 KB
/
score_data_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#==============================================================================
# Get the durations per measure
#==============================================================================
def get_measure_duration(music_xml_tree):
measures = music_xml_tree.findall('part/measure')
measure_duration = 0 #Duration per half bars
first_measure = measures[0]
first_measure_notes = first_measure.findall('note')
for note in first_measure_notes:
measure_duration += int(note.find('duration').text)
measure_duration /= 2
return measure_duration
#==============================================================================
# Get the number of half notes being transposed upwards
#==============================================================================
def get_transpose(music_xml_tree):
measures = music_xml_tree.findall('part/measure')
first_measure = measures[0]
transpose = int(first_measure.find('attributes/key/fifths').text) #volume of transpose
transpose *= -7
transpose = transpose % 12
return transpose
#==============================================================================
# Get the index of the part of the music XML that contains notes
#==============================================================================
def get_part_index(music_xml_tree):
score_size = len(music_xml_tree.getchildren())
part_index = 0
for score_index in range(0, score_size):
if(music_xml_tree[score_index].tag == 'part'):
part_index = score_index
break
return part_index