comparison Syncopation models/basic_functions.py @ 29:7a1730bbf15a

updating files with new text reading code
author christopherh <christopher.harte@eecs.qmul.ac.uk>
date Sun, 12 Apr 2015 22:37:56 +0100
parents 5de1cb45c145
children 273450d5980a
comparison
equal deleted inserted replaced
28:5de1cb45c145 29:7a1730bbf15a
92 return upsampledVelocitySequence 92 return upsampledVelocitySequence
93 93
94 94
95 # convert a velocity sequence to its minimum time-span representation 95 # convert a velocity sequence to its minimum time-span representation
96 def velocity_sequence_to_min_timespan(velocitySequence): 96 def velocity_sequence_to_min_timespan(velocitySequence):
97 from music_objects import VelocitySequence
97 minTimeSpanVelocitySeq = [1] 98 minTimeSpanVelocitySeq = [1]
98 for divisors in find_divisor(len(velocitySequence)): 99 for divisors in find_divisor(len(velocitySequence)):
99 segments = subdivide(velocitySequence,divisors) 100 segments = subdivide(velocitySequence,divisors)
100 if len(segments)!=0: 101 if len(segments)!=0:
101 del minTimeSpanVelocitySeq[:] 102 del minTimeSpanVelocitySeq[:]
102 for s in segments: 103 for s in segments:
103 minTimeSpanVelocitySeq.append(s[0]) 104 minTimeSpanVelocitySeq.append(s[0])
104 if sum(minTimeSpanVelocitySeq) == sum(velocitySequence): 105 if sum(minTimeSpanVelocitySeq) == sum(velocitySequence):
105 break 106 break
106 return minTimeSpanVelocitySeq 107 return VelocitySequence(minTimeSpanVelocitySeq)
107 108
109 """
108 # convert a note sequence to its minimum time-span representation 110 # convert a note sequence to its minimum time-span representation
109 def note_sequence_to_min_timespan(noteSequence): 111 def note_sequence_to_min_timespan(noteSequence):
110 from music_objects import note_sequence_to_velocity_sequence 112 from music_objects import note_sequence_to_velocity_sequence
111 timeSpanTicks = len(note_sequence_to_velocity_sequence(noteSequence)) 113 timeSpanTicks = len(note_sequence_to_velocity_sequence(noteSequence))
112 # print timeSpanTicks 114 # print timeSpanTicks
127 for note in noteSequence: 129 for note in noteSequence:
128 note.startTime = note.startTime/delta_t 130 note.startTime = note.startTime/delta_t
129 note.duration = note.duration/delta_t 131 note.duration = note.duration/delta_t
130 132
131 return noteSequence 133 return noteSequence
132 134 """
133 135
134 # get_note_indices returns all the indices of all the notes in this velocity_sequence 136 # get_note_indices returns all the indices of all the notes in this velocity_sequence
135 def get_note_indices(velocitySequence): 137 def get_note_indices(velocitySequence):
136 noteIndices = [] 138 noteIndices = []
137 139