X-Git-Url: https://svn.cri.ensmp.fr/git/minwii.git/blobdiff_plain/6b0b3c12e74171acf85694f61a2814082af8d7ca..refs/heads/master:/src/minwii/widgets/songfilebrowser.py 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 !