X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/7b2eb97ef51394bcc15f45a334a6e4cb71c6171c..02edbeba380166d7a95250df5e8f587745cc0df3:/src/minwii/musicxml.py?ds=sidebyside diff --git a/src/minwii/musicxml.py b/src/minwii/musicxml.py index ff819e1..54d859f 100755 --- a/src/minwii/musicxml.py +++ b/src/minwii/musicxml.py @@ -140,13 +140,9 @@ class Part(object) : break - def iterNotes(self, indefinitely=True) : + def iterNotes(self) : "exécution de la chanson avec l'alternance couplets / refrains" - if indefinitely == False : - iterable = self.verses - else : - iterable = cycle(self.verses) - for verse in iterable : + for verse in self.verses : if self.songStartsWithChorus : for note in self.chorus : yield note, 0 @@ -166,6 +162,31 @@ class Part(object) : else : for note in verse : yield note, 0 + + @property + def intervalsHistogram(self) : + histogram = {} + it = self.iterNotes() + previousNote = it.next()[0] + for note, _ in it : + interval = note.midi - previousNote.midi + if histogram.has_key(interval) : + histogram[interval] += 1 + else : + histogram[interval] = 1 + previousNote = note + return histogram + + @property + def duration(self) : + 'Durée de référence du morceau en milisecondes' + it = self.iterNotes() + duration = 0 + for note, verseIndex in it : + duration = duration + note.duration + duration = duration * self.quarterNoteDuration # en milisecondes + return duration + def pprint(self) : for note, verseIndex in self.iterNotes(indefinitely=False) : @@ -369,7 +390,8 @@ def musicXml2Song(input, partIndex=0, autoDetectChorus=True, printNotes=False) : doc = d.documentElement # TODO conversion préalable score-timewise -> score-partwise - assert doc.nodeName == u'score-partwise' + if doc.nodeName != u'score-partwise' : + raise ValueError('not a musicxml file') parts = doc.getElementsByTagName('part') leadPart = parts[partIndex] @@ -406,10 +428,13 @@ def main() : if len(args) != 1 : raise SystemExit(op.format_help()) - musicXml2Song(args[0], + song = musicXml2Song(args[0], partIndex=options.partIndex, autoDetectChorus=options.autoDetectChorus, printNotes=options.printNotes) + from pprint import pprint + pprint(song.intervalsHistogram) + print song.duration if __name__ == '__main__' :