X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/7e08f1784451775c1712a0584299e8f4fda00ae6..HEAD:/src/minwii/widgets/songfilebrowser.py diff --git a/src/minwii/widgets/songfilebrowser.py b/src/minwii/widgets/songfilebrowser.py index fcb1c21..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 @@ -65,9 +66,9 @@ class FileOpenDialog(FileDialog): 'padding_right': 4, 'padding_top': 2, 'padding_bottom': 2} - self.title = basic.Label("Ouvrir un chanson", cls="dialog.title.label") + self.title = basic.Label("Ouvrir une chanson", cls="dialog.title.label") self.body = table.Table() - self.list = area.List(width=700, height=250) + self.list = area.List(width=880, height=375) self.input_dir = input.Input() self.input_file = input.Input() self._current_sort = 'alpha' @@ -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 !