From a38e2f50572bdaaff5aa6d99a8cefe91bb856ec5 Mon Sep 17 00:00:00 2001 From: pin Date: Tue, 4 May 2010 11:09:07 +0000 Subject: [PATCH 1/1] =?utf8?q?Les=20notes=20sont=20jou=C3=A9es.=20bugfix?= =?utf8?q?=20temps=20de=20d'attente.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@162 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/logfilereader.py | 63 +++++++++++++++++++++++++++++++-------- src/app/startlogreader.py | 7 ----- 2 files changed, 51 insertions(+), 19 deletions(-) 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 : diff --git a/src/app/startlogreader.py b/src/app/startlogreader.py index d49d8ac..150ec34 100755 --- a/src/app/startlogreader.py +++ b/src/app/startlogreader.py @@ -26,13 +26,6 @@ def main() : lfp = LogFilePlayer(args[0]) lfp.run() pygame.quit() - - -# lr = LogFileReader(args[0]) -# -# print lr.getSongFile() -# - if __name__ == "__main__" : minwiipath = realpath(__file__).split(sep) -- 2.20.1