from musicxml import musicXml2Song
import pygame
-SUPPORTED_FILE_HEADER = 'ENV winwii log format version : 1.0-alpha'
+SUPPORTED_FILE_HEADER = 'ENV winwii log format version : 1.0'
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()
if l.startswith('ENV résolution écran :') :
break
screenResolution = eval(l.split(':', 1)[1].strip())
+ f.seek(pos)
return screenResolution
def getFirstEventTicks(self) :
if l.startswith('EVT ') :
break
firstTicks = int(l.split(None, 2)[1])
+ f.seek(pos)
return firstTicks
def __del__(self) :
return line
def getEventsIterator(self) :
+ self.logfile.seek(0)
while True :
try :
l = self.next()
"""
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
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)
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)
+
+ elif eventName.startswith('COL') :
+ pos = [int(n) for n in message.split(None, 4)[-1].strip('()').split(',')]
+ self.cursor.setPosition(pos)
+
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 :