From: pin Date: Tue, 27 Sep 2011 12:23:34 +0000 (+0000) Subject: Affichage du temps de référence de la chanson, au lieu de la difficulté (intervalle... X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/d6be77ba11018fc770a76f710b1a0f39e30049fa?hp=94e7b3f13f4247613609d53c95d0ba59a1eee9d1 Affichage du temps de référence de la chanson, au lieu de la difficulté (intervalle moyen). git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@395 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/minwii/widgets/songfilebrowser.py b/src/minwii/widgets/songfilebrowser.py index 2f0120e..4c5b55c 100755 --- a/src/minwii/widgets/songfilebrowser.py +++ b/src/minwii/widgets/songfilebrowser.py @@ -19,6 +19,7 @@ from pgu.gui.const import * from pgu.gui.dialog import Dialog from pgu.gui.app import Desktop import types +from datetime import timedelta import os import tempfile @@ -195,14 +196,29 @@ class FileOpenDialog(FileDialog): song = musicXml2Song(file) metadata['distinctNotes'] = len(song.distinctNotes) - histo = song.intervalsHistogram - coeffInter = reduce(lambda a, b : a + b, - [abs(k) * v for k, v in histo.items()]) + duration = song.duration / 1000. + duration = int(round(duration, 0)) + duration = timedelta(seconds=duration) + try : + duration = str(duration) # p.ex. 0:03:05 + duration = duration.split(':') + h, m, s = [int(n) for n in duration] + if h : raise ValueError(h) + duration = ':'.join([str(n).zfill(2) for n in (m, s)]) + except : + raise + duration = srt(duration) - totInter = reduce(lambda a, b: a+b, histo.values()) - totInter = totInter - histo.get(0, 0) - difficulty = int(round(float(coeffInter) / totInter, 0)) - metadata['difficulty'] = difficulty + metadata['duration'] = duration + + # histo = song.intervalsHistogram + # coeffInter = reduce(lambda a, b : a + b, + # [abs(k) * v for k, v in histo.items()]) + # + # totInter = reduce(lambda a, b: a+b, histo.values()) + # totInter = totInter - histo.get(0, 0) + # difficulty = int(round(float(coeffInter) / totInter, 0)) + # metadata['difficulty'] = difficulty return metadata @@ -222,7 +238,7 @@ class FileOpenDialog(FileDialog): if e.args and e.args[0] == 'not a musicxml file' : continue - line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(difficulty)d\n' % metadata + line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(duration)s\n' % metadata index.append(line) tmp.write(line) @@ -259,7 +275,7 @@ class FileOpenDialog(FileDialog): continue metadata = FileOpenDialog.getSongMetadata(filePath) - line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(difficulty)d\n' % metadata + line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(duration)s\n' % metadata indexedFiles[fileBaseName] = line # check for new files. @@ -275,7 +291,7 @@ class FileOpenDialog(FileDialog): continue metadata = FileOpenDialog.getSongMetadata(file) - line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(difficulty)d\n' % metadata + line = '%(file)s\t%(mtime)s\t%(title)s\t%(distinctNotes)d\t%(duration)s\n' % metadata indexedFiles[fileBaseName] = line # ok, the index is up to date !