X-Git-Url: https://svn.cri.ensmp.fr/git/minwii.git/blobdiff_plain/c958fad0633273abbc1357fd5a9857e674c3707f..e26832c9e7be68fc16059f7a2d3c2478afbcfa91:/src/minwii/logfilereader.py diff --git a/src/minwii/logfilereader.py b/src/minwii/logfilereader.py index 44c3611..b7f84a1 100755 --- a/src/minwii/logfilereader.py +++ b/src/minwii/logfilereader.py @@ -6,12 +6,14 @@ $Id$ $URL$ """ +from types import StringTypes from widgets.playingscreen import PlayingScreenBase from eventutils import EventDispatcher from events import eventCodes from synth import Synth from musicxml import musicXml2Song import pygame +from backwardsfilereader import BackwardsReader SUPPORTED_FILE_HEADER = 'ENV winwii log format version : 1.0' @@ -33,7 +35,7 @@ class LogFileReader(object) : """ logfile : chemin d'accès au fichier de log MinWii. le format supporté est actuellement la version 1.0 uniquement. """ - if isinstance(logfile, str) : + if isinstance(logfile, StringTypes) : self.logfile = open(logfile, 'r') else : self.logfile = logfile @@ -106,6 +108,16 @@ class LogFileReader(object) : firstTicks = int(l.split(None, 2)[1]) return firstTicks + @inplaceread + def getLastEventTicks(self) : + "retourne le timecode du dernier événement (entier)" + for l in self.getBackwardLineIterator() : + if l.startswith('EVT ') : + break + + lastTicks = int(l.split(None, 2)[1]) + return lastTicks + def __del__(self) : self.logfile.close() @@ -139,6 +151,14 @@ class LogFileReader(object) : ticks, eventName = l.split(None, 3)[1:] ticks = int(ticks) yield ticks, eventName, '' + + def getBackwardLineIterator(self) : + br = BackwardsReader(self.logfile, BLKSIZE=128) + line = br.readline() + while line : + yield line.strip() + line = br.readline() + class LogFilePlayer(PlayingScreenBase) :