from pgu.gui.dialog import Dialog
from pgu.gui.app import Desktop
import types
+from datetime import timedelta
import os
import tempfile
'padding_bottom': 2}
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'
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
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)
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.
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 !