From d6be77ba11018fc770a76f710b1a0f39e30049fa Mon Sep 17 00:00:00 2001 From: pin Date: Tue, 27 Sep 2011 12:23:34 +0000 Subject: [PATCH 1/1] =?utf8?q?Affichage=20du=20temps=20de=20r=C3=A9f=C3=A9?= =?utf8?q?rence=20de=20la=20chanson,=20au=20lieu=20de=20la=20difficult?= =?utf8?q?=C3=A9=20(intervalle=20moyen).?= 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@395 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/minwii/widgets/songfilebrowser.py | 36 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) 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 ! -- 2.20.1