-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphrase_parser.py
More file actions
84 lines (59 loc) · 2.42 KB
/
phrase_parser.py
File metadata and controls
84 lines (59 loc) · 2.42 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#takes note data and parses into phrases based on rest time between
#takes in file_info = (float, int, str): (timestamp, length in ms, note/undef)
def phrase_parser(file_info):
#go through times, find undef sequences, parse out undef rest length, use to create chunks of 'phrases', use those phrases to make definite and relative frequency phrases
phrase_info = []
phrase = []
note_time_variance = 1000
for info in file_info:
note = info[2]
note_length = int(info[1])
start_time = float(info[0])
note_a = [start_time, note_length, note]
#checks if the phrase is a rest
if 'undefined' in info:
#if it is over 1 sec, consider it a phrase break
if note_length > note_time_variance:
phrase_info.append(phrase)
phrase = []
phrase_break = [start_time, note_length, 'phrase_break']
phrase_info.append(phrase_break)
#if it is not a rest, consider it a phrase, have the notes and rests appended to phrase info as lists in a list
else:
phrase.append(note_a)
#appends undefined notes as info
else:
phrase.append(note_a)
if 'phrase_break' not in info:
phrase_info.append(phrase)
#removes empty strings
phrase_info = [x for x in phrase_info if x != []]
# print(phrase_info)
#compare notes relative to each other, broken up by phrase breaks
phrase_and_length_info = []
phrase_notes = []
#goes through and creates TextGrid-able lists
for phrase in phrase_info:
phrase_start = phrase[0]
if type(phrase_start) == list:
phrase_start = phrase_start[0]
phrase_length = 0
phrase_notes = []
if 'phrase_break' in phrase:
phrase_and_length_info.append(phrase)
else:
for note in phrase:
phrase_length += note[1]
note_val = str(note[2])
phrase_notes.append(note_val)
phrase_and_length_info.append([phrase_start, phrase_length, phrase_notes])
return(phrase_and_length_info, phrase_info)
#--------------------------#
# for x in phrase_info:
# print(x)
# for x in phrase_and_length_info:
# print(x)
# print(phrase_and_length_info)
#returns file info of type (float, int, str): (timestamp, length, notes in sequence)
#(11.0, 30.0s, '5 4 5 5 3')
#(11.0, 30.0s, 'F E F F D')