From ebf72d7fe428b8af78d5b5906c4c01e4ef59447c Mon Sep 17 00:00:00 2001 From: "benoit.pin" Date: Fri, 19 Nov 2010 09:15:20 +0000 Subject: [PATCH 1/1] =?utf8?q?Ajout=20d'une=20propri=C3=A9t=C3=A9=20qui=20?= =?utf8?q?donne=20l'histogramme=20des=20fr=C3=A9quences=20d'intervalles.?= 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@315 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/minwii/musicxml.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/minwii/musicxml.py b/src/minwii/musicxml.py index 8bc2508..7468eca 100755 --- a/src/minwii/musicxml.py +++ b/src/minwii/musicxml.py @@ -162,6 +162,20 @@ 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 def pprint(self) : for note, verseIndex in self.iterNotes(indefinitely=False) : @@ -365,7 +379,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] @@ -402,10 +417,12 @@ 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) if __name__ == '__main__' : -- 2.20.1