comparison Syncopation models/basic_functions.py @ 19:9030967a05f8

Refactored parameter_setter, basic_functions. Halfway fixing parameter argument in LHL model.
author csong <csong@eecs.qmul.ac.uk>
date Fri, 03 Apr 2015 22:57:27 +0100
parents 4fb9c00e4ef0
children b959c2acb927
comparison
equal deleted inserted replaced
18:43fa04812800 19:9030967a05f8
91 91
92 return note_indices 92 return note_indices
93 93
94 # The get_H returns a sequence of metrical weight for a certain metrical level (horizontal), 94 # The get_H returns a sequence of metrical weight for a certain metrical level (horizontal),
95 # given the sequence of metrical weights in a hierarchy (vertical) and a sequence of subdivisions. 95 # given the sequence of metrical weights in a hierarchy (vertical) and a sequence of subdivisions.
96 def get_H(weight_seq,subdivision_seq, level): 96 def get_H(weightSequence,subdivisionSequence, level):
97 H = [] 97 H = []
98 #print len(weight_seq), len(subdivision_seq), level 98 #print len(weight_seq), len(subdivision_seq), level
99 if (level <= len(subdivision_seq)-1) & (level <= len(weight_seq)-1): 99 if (level <= len(subdivisionSequence)-1) and (level <= len(weightSequence)-1):
100 if level == 0: 100 if level == 0:
101 H = repeat([weight_seq[0]],subdivision_seq[0]) 101 H = repeat([weightSequence[0]],subdivisionSequence[0])
102 else: 102 else:
103 H_pre = get_H(weight_seq,subdivision_seq,level-1) 103 H_pre = get_H(weightSequence,subdivisionSequence,level-1)
104 for h in H_pre: 104 for h in H_pre:
105 H = concatenate(H, concatenate([h], repeat([weight_seq[level]],subdivision_seq[level]-1))) 105 H = concatenate(H, concatenate([h], repeat([weightSequence[level]],subdivisionSequence[level]-1)))
106 else: 106 else:
107 print 'Error: a subdivision factor or metrical weight is not defined for the request metrical level.' 107 print 'Error: a subdivision factor or metrical weight is not defined for the request metrical level.'
108 return H 108 return H
109 109
110 # The get_subdivision_seq function returns the subdivision sequence of several common time-signatures defined by GTTM, 110 # # The get_subdivision_seq function returns the subdivision sequence of several common time-signatures defined by GTTM,
111 # or ask for the top three level of subdivision_seq manually set by the user. 111 # # or ask for the top three level of subdivision_seq manually set by the user.
112 def get_subdivision_seq(timesig, L_max): 112 # def get_subdivision_seq(timesig, L_max):
113 subdivision_seq = [] 113 # subdivision_seq = []
114 114
115 if timesig == '2/4' or timesig == '4/4': 115 # if timesig == '2/4' or timesig == '4/4':
116 subdivision_seq = [1,2,2] 116 # subdivision_seq = [1,2,2]
117 elif timesig == '3/4' or timesig == '3/8': 117 # elif timesig == '3/4' or timesig == '3/8':
118 subdivision_seq = [1,3,2] 118 # subdivision_seq = [1,3,2]
119 elif timesig == '6/8': 119 # elif timesig == '6/8':
120 subdivision_seq = [1,2,3] 120 # subdivision_seq = [1,2,3]
121 elif timesig == '9/8': 121 # elif timesig == '9/8':
122 subdivision_seq = [1,3,3] 122 # subdivision_seq = [1,3,3]
123 elif timesig == '12/8': 123 # elif timesig == '12/8':
124 subdivision_seq = [1,4,3] 124 # subdivision_seq = [1,4,3]
125 elif timesig == '5/4' or timesig == '5/8': 125 # elif timesig == '5/4' or timesig == '5/8':
126 subdivision_seq = [1,5,2] 126 # subdivision_seq = [1,5,2]
127 elif timesig == '7/4' or timesig == '7/8': 127 # elif timesig == '7/4' or timesig == '7/8':
128 subdivision_seq = [1,7,2] 128 # subdivision_seq = [1,7,2]
129 elif timesig == '11/4' or timesig == '11/8': 129 # elif timesig == '11/4' or timesig == '11/8':
130 subdivision_seq = [1,11,2] 130 # subdivision_seq = [1,11,2]
131 else: 131 # else:
132 print 'Time-signature',timesig,'is undefined. Please indicate subdivision sequence for this requested time-signature, e.g. [1,2,2] for 4/4 meter.' 132 # print 'Time-signature',timesig,'is undefined. Please indicate subdivision sequence for this requested time-signature, e.g. [1,2,2] for 4/4 meter.'
133 for i in range(3): 133 # for i in range(3):
134 s = int(input('Enter the subdivision factor at metrical level '+str(i)+':')) 134 # s = int(input('Enter the subdivision factor at metrical level '+str(i)+':'))
135 subdivision_seq.append(s) 135 # subdivision_seq.append(s)
136 136
137 if L_max > 2: 137 # if L_max > 2:
138 subdivision_seq = subdivision_seq + [2]*(L_max-2) 138 # subdivision_seq = subdivision_seq + [2]*(L_max-2)
139 else: 139 # else:
140 subdivision_seq = subdivision_seq[0:L_max+1] 140 # subdivision_seq = subdivision_seq[0:L_max+1]
141 141
142 return subdivision_seq 142 # return subdivision_seq
143 143
144 144
145 def get_rhythm_category(velocitySequence, subdivisionSequence): 145 def get_rhythm_category(velocitySequence, subdivisionSequence):
146 ''' 146 '''
147 The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm. 147 The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm.