X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/f6e0db47250bd3666e1f46f22ed8153d77b46f2e..a38e2f50572bdaaff5aa6d99a8cefe91bb856ec5:/src/app/logfilereader.py?ds=inline diff --git a/src/app/logfilereader.py b/src/app/logfilereader.py index 502b332..a32d834 100755 --- a/src/app/logfilereader.py +++ b/src/app/logfilereader.py @@ -47,8 +47,31 @@ class LogFileReader(object) : if l.startswith('ENV soundfont :') : break soundFontFile = l.split(':', 1)[1].strip() + f.seek(pos) return soundFontFile + def getBank(self) : + f = self.logfile + pos = f.tell() + f.seek(0) + for l in self : + if l.startswith('APP bank :') : + break + f.seek(pos) + bank = l.split(':', 1)[1].strip() + return int(bank) + + def getPreset(self) : + f = self.logfile + pos = f.tell() + f.seek(0) + for l in self : + if l.startswith('APP preset :') : + break + f.seek(pos) + preset = l.split(':', 1)[1].strip() + return int(preset) + def getScreenResolution(self) : f = self.logfile pos = f.tell() @@ -57,6 +80,7 @@ class LogFileReader(object) : if l.startswith('ENV résolution écran :') : break screenResolution = eval(l.split(':', 1)[1].strip()) + f.seek(pos) return screenResolution def getFirstEventTicks(self) : @@ -67,6 +91,7 @@ class LogFileReader(object) : if l.startswith('EVT ') : break firstTicks = int(l.split(None, 2)[1]) + f.seek(pos) return firstTicks def __del__(self) : @@ -80,6 +105,7 @@ class LogFileReader(object) : return line def getEventsIterator(self) : + self.logfile.seek(0) while True : try : l = self.next() @@ -102,17 +128,20 @@ class LogFilePlayer(PlayingScreenBase) : """ def __init__(self, logfile) : - lfr = self.lfr = LogFileReader(logfile) - songFile = lfr.getSongFile() - soundFontFile = lfr.getSoundFontFile() - sfPath = lfr.getSoundFontFile() - synth = Synth(sfPath=sfPath) - self.song = musicXml2Song(songFile) - screenResolution = lfr.getScreenResolution() - - pygame.display.set_mode(screenResolution) - - super(LogFilePlayer, self).__init__(synth, self.song.distinctNotes) + lfr = self.lfr = LogFileReader(logfile) + songFile = lfr.getSongFile() + soundFontFile = lfr.getSoundFontFile() + sfPath = lfr.getSoundFontFile() + bank = lfr.getBank() + preset = lfr.getPreset() + synth = Synth(sfPath=sfPath) + synth.program_select(0, bank, preset) + self.song = musicXml2Song(songFile) + screenResolution = lfr.getScreenResolution() + + pygame.display.set_mode(screenResolution) + + super(LogFilePlayer, self).__init__(synth, self.song.distinctNotes) def run(self): self._running = True @@ -124,6 +153,7 @@ class LogFilePlayer(PlayingScreenBase) : eIter = self.lfr.getEventsIterator() for ticks, eventName, message in eIter : + t0 = pygame.time.get_ticks() ticks = int(ticks) if eventName == 'COLSTATECHANGE' : parts = message.split(None, 4) @@ -135,13 +165,22 @@ class LogFilePlayer(PlayingScreenBase) : state = state == 'True' col = self.columns[midi] col.update(state, syllabus=syllabus.decode('utf-8')) + + elif eventName == 'NOTEON': + chan, key, vel = [int(v) for v in message.split(None, 2)] + self.synth.noteon(chan, key, vel) + + elif eventName == 'NOTEOFF': + chan, key = [int(v) for v in message.split(None, 1)] + self.synth.noteoff(chan, key) + pygame.event.clear() # à virer #EventDispatcher.dispatchEvents() dirty = self.draw(pygame.display.get_surface()) pygame.display.update(dirty) - execTime = clock.tick() + execTime = pygame.time.get_ticks() - t0 delay = ticks - previousTicks - execTime if delay > 0 :