From: pin Date: Mon, 8 Feb 2010 14:28:20 +0000 (+0000) Subject: Prise en charge des pauses / soupirs etc : on augmente la durée de la note précédente. X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/commitdiff_plain/300e41c1bf5fa8a5ff38db74396174a8f7f93bb7 Prise en charge des pauses / soupirs etc : on augmente la durée de la note précédente. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@15 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/songs/musicxmltosong.py b/src/songs/musicxmltosong.py index ed7dddf..826363e 100755 --- a/src/songs/musicxmltosong.py +++ b/src/songs/musicxmltosong.py @@ -9,6 +9,7 @@ import sys from types import StringTypes from xml.dom.minidom import parse from optparse import OptionParser +from itertools import cycle #from Song import Song # Do4 <=> midi 60 @@ -56,11 +57,16 @@ class Part(object) : divisions = int(_getNodeValue(measureNode, 'attributes/divisions', divisions)) for noteNode in measureNode.getElementsByTagName('note') : note = Note(noteNode, divisions, previous) - self.notes.append(note) - try : - self.notes[noteIndex-1].next = note - except IndexError: - pass + if not note.isRest : + self.notes.append(note) + try : + self.notes[noteIndex-1].next = note + except IndexError: + pass + else : + previous.addDuration(note) + continue + previous = note noteIndex += 1 @@ -133,9 +139,16 @@ class Note(object) : def __init__(self, node, divisions, previous) : self.node = node - self.step = _getNodeValue(node, 'pitch/step') - self.octave = int(_getNodeValue(node, 'pitch/octave')) - self.alter = int(_getNodeValue(node, 'pitch/alter', 0)) + self.isRest = False + self.step = _getNodeValue(node, 'pitch/step', None) + if self.step is not None : + self.octave = int(_getNodeValue(node, 'pitch/octave')) + self.alter = int(_getNodeValue(node, 'pitch/alter', 0)) + elif self.node.getElementsByTagName('rest') : + self.isRest = True + else : + NotImplementedError(self.node.toxml('utf-8')) + self._duration = float(_getNodeValue(node, 'duration')) self.lyrics = [] for ly in node.getElementsByTagName('lyric') : @@ -145,6 +158,10 @@ class Note(object) : self.previous = previous self.next = None + def addDuration(self, note) : + self._duration = self.duration + note.duration + self.divisions = 1 + @property def midi(self) : mid = DIATO_SCALE[self.step]