From: pin Date: Tue, 4 May 2010 11:09:07 +0000 (+0000) Subject: Les notes sont jouées. bugfix temps de d'attente. X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/commitdiff_plain/a38e2f50572bdaaff5aa6d99a8cefe91bb856ec5?ds=sidebyside;hp=b0a3123973062597484f6bc64ad0900eddc21ba7 Les notes sont jouées. bugfix temps de d'attente. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@162 fe552daf-6dbe-4428-90eb-1537e0879342 --- 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)