def getnotes(self, voice = None):
# global mat
if voice is None:
return [self.getnotes(v) for v in xrange(len(self.s.parts))]
if self.notes[voice] is None:
endtimes = self.s.flat.notesAndRests.stream()._uniqueOffsetsAndEndTimes(endTimesOnly=True)
self.notes[voice] = [None] * len(endtimes)
notes = list(self.s.parts[voice].flat.notesAndRests)
j = 0 # index of current note
curr = 0.0
for i in xrange(len(endtimes)):
self.notes[voice][i] = map(lambda k: (isinstance(notes[j], note.Note) and \
k == pitchtoid(notes[j].pitch, self.key)) * \
(endtimes[i] - curr), range(Din))
# if current note ends here, go to next note
if endtimes[i] == notes[j].offset + notes[j].quarterLength:
j += 1
curr = endtimes[i]
self.notes[voice] = torch.FloatTensor(self.notes[voice])
n = self.notes[voice].clone().apply_(lambda n: int(n != 0))
# mat += n[:-1].t().mm(n[1:])
return self.notes[voice]
评论列表
文章目录