From 7b2eb97ef51394bcc15f45a334a6e4cb71c6171c Mon Sep 17 00:00:00 2001 From: pin Date: Tue, 29 Jun 2010 12:44:46 +0000 Subject: [PATCH] =?utf8?q?bugfix=20:=20le=20refrain=20n'est=20plus=20r?= =?utf8?q?=C3=A9p=C3=A9t=C3=A9=20=C3=A0=20la=20fin=20de=20la=20chanson.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@259 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/minwii/musicxml.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/minwii/musicxml.py b/src/minwii/musicxml.py index d7651b2..ff819e1 100755 --- a/src/minwii/musicxml.py +++ b/src/minwii/musicxml.py @@ -57,9 +57,8 @@ class Part(object) : self._parseMusic() self.verses = [[]] self.chorus = [] - if autoDetectChorus : - self._findChorus() - self._findVersesLoops() + self.songStartsWithChorus = False + self._findVersesLoops(autoDetectChorus) def _parseMusic(self) : divisions = 0 @@ -121,25 +120,7 @@ class Part(object) : self.quarterNoteDuration = int(round(60000/tempo)) - - def _findChorus(self): - """ le refrain correspond aux notes pour lesquelles - il n'existe q'une seule syllable attachée. - """ - start = stop = None - for i, note in enumerate(self.notes) : - ll = len(note.lyrics) - if start is None and ll == 1 : - start = i - elif start is not None and ll > 1 : - stop = i - break - if not (start or stop) : - self.chorus = [] - else : - self.chorus = self.notes[start:stop] - - def _findVersesLoops(self) : + def _findVersesLoops(self, autoDetectChorus) : "recherche des couplets / boucles" verse = self.verses[0] for note in self.notes[:-1] : @@ -151,6 +132,13 @@ class Part(object) : self.verses.append(verse) verse.append(self.notes[-1]) + if autoDetectChorus and len(self.verses) > 1 : + for i, verse in enumerate(self.verses) : + if len(verse[0].lyrics) == 1 : + self.chorus = self.verses.pop(i) + self.songStartsWithChorus = i==0 + break + def iterNotes(self, indefinitely=True) : "exécution de la chanson avec l'alternance couplets / refrains" @@ -159,6 +147,10 @@ class Part(object) : else : iterable = cycle(self.verses) for verse in iterable : + if self.songStartsWithChorus : + for note in self.chorus : + yield note, 0 + #print "---partie---" repeats = len(verse[0].lyrics) if repeats > 1 : -- 2.20.1