Mercurial > hg > syncopation-dataset
comparison Syncopation models/music_objects.py @ 38:cc38b3047ed9
updated syncopation.y to allow output of sync for a bar list
also fixed some problems in models and other modules
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Mon, 13 Apr 2015 23:06:49 +0100 |
parents | 3a878de00d19 |
children | 6371e8f21f7d |
comparison
equal
deleted
inserted
replaced
37:fefbe0d853c6 | 38:cc38b3047ed9 |
---|---|
113 velocitySequence += [0]*(timespanTicks - len(velocitySequence)) | 113 velocitySequence += [0]*(timespanTicks - len(velocitySequence)) |
114 else: | 114 else: |
115 velocitySequence += [0]*(noteSequence[-1].duration-1) | 115 velocitySequence += [0]*(noteSequence[-1].duration-1) |
116 | 116 |
117 # normalising velocity sequence between 0-1 | 117 # normalising velocity sequence between 0-1 |
118 velocitySequence = VelocitySequence([float(v)/max(velocitySequence) for v in velocitySequence]) | 118 if max(velocitySequence)>0: |
119 velocitySequence = VelocitySequence([float(v)/max(velocitySequence) for v in velocitySequence]) | |
119 | 120 |
120 return velocitySequence | 121 return velocitySequence |
121 | 122 |
122 | 123 |
123 class BarList(list): | 124 class BarList(list): |
160 self.noteSequence = velocity_sequence_to_note_sequence(self.velocitySequence, nextbarVelocitySequence) | 161 self.noteSequence = velocity_sequence_to_note_sequence(self.velocitySequence, nextbarVelocitySequence) |
161 return self.noteSequence | 162 return self.noteSequence |
162 | 163 |
163 def get_velocity_sequence(self): | 164 def get_velocity_sequence(self): |
164 if self.velocitySequence == None: | 165 if self.velocitySequence == None: |
165 self.velocitySequence = note_sequence_to_velocity_sequence(self.noteSequence) | 166 self.velocitySequence = note_sequence_to_velocity_sequence(self.noteSequence, self.get_bar_ticks()) |
166 return self.velocitySequence | 167 return self.velocitySequence |
167 | 168 |
168 def get_binary_sequence(self): | 169 def get_binary_sequence(self): |
169 return ceiling(self.get_velocity_sequence()) | 170 return ceiling(self.get_velocity_sequence()) |
170 | 171 |
191 | 192 |
192 # return the length of a bar in time units (ticks) | 193 # return the length of a bar in time units (ticks) |
193 def get_bar_ticks(self): | 194 def get_bar_ticks(self): |
194 return calculate_bar_ticks(self.timeSignature.get_numerator(),self.timeSignature.get_denominator(), self.tpq) | 195 return calculate_bar_ticks(self.timeSignature.get_numerator(),self.timeSignature.get_denominator(), self.tpq) |
195 | 196 |
197 def is_empty(self): | |
198 if max(self.get_velocity_sequence())>0: | |
199 return False | |
200 else: | |
201 return True | |
202 | |
196 def to_string(self, sequenceType=None): | 203 def to_string(self, sequenceType=None): |
204 output = "t{"+self.timeSignature.to_string()+"}" | |
205 prev = self.get_previous_bar() | |
206 if prev!=None: | |
207 if prev.get_time_signature()==self.get_time_signature(): | |
208 output="" | |
209 | |
197 if sequenceType==None or sequenceType=="v": | 210 if sequenceType==None or sequenceType=="v": |
198 output = "v{"+self.get_velocity_sequence().to_string()+"}" | 211 output += "v{"+self.get_velocity_sequence().to_string()+"}" |
199 else: | 212 else: |
200 output = "y{"+self.get_note_sequence().to_string()+"}" | 213 output += "y{"+self.get_note_sequence().to_string()+"}" |
201 return output | 214 return output |
202 | 215 |
203 | 216 |
204 class TimeSignature(): | 217 class TimeSignature(): |
205 def __init__(self, inputString): | 218 def __init__(self, inputString): |