def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) self.Movie = None manager.setCpuSpeed('mpg') manager.InitPlayer(self) manager.OpenDisplay(depth=DISPLAY_DEPTH) # Close the mixer while using Movie manager.CloseAudio() # Open the Movie module filepath = self.SongDatas[0].GetFilepath() if type(filepath) == unicode: filepath = filepath.encode(sys.getfilesystemencoding()) self.Movie = pygame.movie.Movie(filepath) self.Movie.set_display( manager.display, (0, 0, manager.displaySize[0], manager.displaySize[1]))
def doStuff(self): pykPlayer.doStuff(self) if self.screenDirty: self.paintWindow() self.screenDirty = False if self.heldKey: elapsed = pygame.time.get_ticks() - self.heldStartTicks repeat = 0 if elapsed > 4000: repeat = int((elapsed - 4000) / 5.) + 256 else: repeat = int(math.pow((elapsed / 1000.), 4)) if elapsed > 1000: manager.setCpuSpeed('menu_fast') elif manager.cpuSpeed != 'menu_fast': manager.setCpuSpeed('menu_slow') if repeat > self.heldRepeat: self.handleRepeatable(self.heldKey[0], self.heldKey[1], self.heldKey[2], repeat - self.heldRepeat) self.heldRepeat = repeat else: elapsed = pygame.time.get_ticks() - self.heldStartTicks if elapsed > 20000: manager.setCpuSpeed('menu_idle') elif elapsed > 2000: manager.setCpuSpeed('menu_slow')
def changeSort(self): file = self.songDb.SongList[self.currentRow] sort = None if self.songDb.Sort == 'title': if self.songDb.GotArtists: sort = 'artist' else: sort = 'filename' elif self.songDb.Sort == 'artist': sort = 'filename' else: # 'filename' if self.songDb.GotTitles: sort = 'title' elif self.songDb.GotArtists: sort = 'artist' if not sort: # No need to change anything. return sortApplied = self.songDb.SelectSort(sort, allowResort=False) if not sortApplied: # Changing the sort will require re-sorting the list. Pop # up a message indicating we're doing this. This is # particularly necessary for low-end CPU's, for which this # process might take a few seconds, like the GP2X. manager.setCpuSpeed('load') manager.display.fill((0, 0, 0)) winWidth, winHeight = manager.displaySize winCenterX = winWidth / 2 winCenterY = winHeight / 2 text = self.subtitleFont.render("Sorting", True, (255, 255, 255)) rect = text.get_rect() rect = rect.move(winCenterX - rect.centerx, winCenterY - rect.centery) manager.display.blit(text, rect) pygame.display.flip() self.songDb.SelectSort(sort, allowResort=True) if file.sameSongs: # If we were on the filename list, we might have been looking # at a file that doesn't actually appear in the artist or # title list. Be sure we look up the one that does appear. file = file.sameSongs[0] self.currentRow = bisect.bisect_left(self.songDb.SongList, file) self.screenDirty = True
def changeSort(self): file = self.songDb.SongList[self.currentRow] sort = None if self.songDb.Sort == 'title': if self.songDb.GotArtists: sort = 'artist' else: sort = 'filename' elif self.songDb.Sort == 'artist': sort = 'filename' else: # 'filename' if self.songDb.GotTitles: sort = 'title' elif self.songDb.GotArtists: sort = 'artist' if not sort: # No need to change anything. return sortApplied = self.songDb.SelectSort(sort, allowResort = False) if not sortApplied: # Changing the sort will require re-sorting the list. Pop # up a message indicating we're doing this. This is # particularly necessary for low-end CPU's, for which this # process might take a few seconds, like the GP2X. manager.setCpuSpeed('load') manager.display.fill((0,0,0)) winWidth, winHeight = manager.displaySize winCenterX = winWidth / 2 winCenterY = winHeight / 2 text = self.subtitleFont.render("Sorting", True, (255,255,255)) rect = text.get_rect() rect = rect.move(winCenterX - rect.centerx, winCenterY - rect.centery) manager.display.blit(text, rect) pygame.display.flip() self.songDb.SelectSort(sort, allowResort = True) if file.sameSongs: # If we were on the filename list, we might have been looking # at a file that doesn't actually appear in the artist or # title list. Be sure we look up the one that does appear. file = file.sameSongs[0] self.currentRow = bisect.bisect_left(self.songDb.SongList, file) self.screenDirty = True
def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) self.Movie = None manager.setCpuSpeed("mpg") manager.InitPlayer(self) # Close the audio and the display manager.CloseAudio() manager.CloseDisplay() manager.CloseCPUControl() self.procReturnCode = None self.proc = None
def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) self.Movie = None manager.setCpuSpeed('mpg') manager.InitPlayer(self) # Close the audio and the display manager.CloseAudio() manager.CloseDisplay() manager.CloseCPUControl() self.procReturnCode = None self.proc = None
def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) self.Movie = None manager.setCpuSpeed("mpg") manager.InitPlayer(self) manager.OpenDisplay(depth=DISPLAY_DEPTH) # Close the mixer while using Movie manager.CloseAudio() # Open the Movie module filepath = self.SongDatas[0].GetFilepath() self.Movie = pygame.movie.Movie(filepath) self.Movie.set_display(manager.display, (0, 0, manager.displaySize[0], manager.displaySize[1]))
def beginSong(self, file): self.selectedSong = None manager.setCpuSpeed('load') manager.display.fill((0, 0, 0)) winWidth, winHeight = manager.displaySize winCenter = winWidth / 2 rowA = winHeight / 3 rowC = winHeight * 5 / 6 self.__writeSongTitle(file, rowA) text = self.subtitleFont.render("Loading", True, (255, 255, 255)) rect = text.get_rect() rect = rect.move(winCenter - rect.centerx, rowC) manager.display.blit(text, rect) pygame.display.flip() # This will call the songFinishedCallback, so call it early. self.shutdown() self.writeMarkedSongs() player = file.MakePlayer(self.songDb, self.errorPopupCallback, self.songFinishedCallback) if player == None: return # Start playing. try: player.Play() except: self.errorPopupCallback("Error starting player.\n%s\n%s" % (sys.exc_info()[0], sys.exc_info()[1])) return # Go to sleep until the song is over. try: manager.WaitForPlayer() except: self.errorPopupCallback("Error while playing song.\n%s\n%s" % (sys.exc_info()[0], sys.exc_info()[1])) return # The song is over. Now recover control and redisplay the # song list. manager.OpenCPUControl() manager.setCpuSpeed('menu_fast') self.heldStartTicks = pygame.time.get_ticks() manager.InitPlayer(self) manager.OpenDisplay() # In case the screen has been resized during the song. self.setupScrollWindow() self.screenDirty = True # Discard any events that occurred while we were resetting the # display. for event in pygame.event.get(): pass
def start(self): self.appStart = pygame.time.get_ticks() self.heldStartTicks = self.appStart manager.OpenCPUControl() manager.setCpuSpeed('startup') self.numSongInfoLines = 1 self.setupSplashScreen() manager.InitPlayer(self) self.setupScrollWindow() self.screenDirty = True needsSave = False if manager.options.scan_dir: # Replace the old scan list. self.songDb.Settings.FolderList = [manager.options.scan_dir] needsSave = True if manager.options.scan_dirs: # Add one or more new directories to the list. self.songDb.Settings.FolderList += manager.options.scan_dirs needsSave = True if manager.options.scan: # Re-scan the files. self.songDb.BuildSearchDatabase(pykdb.AppYielder(), MiniBusyCancelDialog(self)) needsSave = True else: # Read the existing database. self.songDb.LoadDatabase(self.errorPopupCallback) if needsSave: self.songDb.SaveSettings() self.songDb.SaveDatabase() if not self.songDb.FullSongList: # No files. self.errorPopupCallback("No songs in catalog.") return if manager.options.validate: manager.ValidateDatabase(self.songDb) return if self.songDb.GotTitles: self.numSongInfoLines += 1 if self.songDb.GotArtists: self.numSongInfoLines += 1 self.setupScrollWindow() self.readMarkedSongs() if self.songDb.GotTitles: self.songDb.SelectSort('title') elif self.songDb.GotArtists: self.songDb.SelectSort('artist') else: self.songDb.SelectSort('filename') self.currentRow = 0 self.searchString = '' self.heldKey = None self.heldStartTicks = 0 self.heldRepeat = 0 manager.setCpuSpeed('wait') # Now that we've finished loading, wait up a second and give # the user a chance to view the splash screen, in case we # loaded too fast. if self.splashStart != None: splashTime = pygame.time.get_ticks() - self.splashStart remainingTime = 2500 - splashTime if remainingTime > 0: pygame.time.wait(remainingTime) self.running = True manager.setCpuSpeed('menu_fast') self.heldStartTicks = pygame.time.get_ticks() while self.running: manager.Poll() self.writeMarkedSongs() manager.CloseDisplay()
def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) # Setup FullScreen Mode manager.settings.FullScreen = 1 manager.settings.PlayerSize = (manager.options.size_x, manager.options.size_y) manager.displayFlags |= pygame.FULLSCREEN # With the nomusic option no music will be played. soundFileData = None if not manager.options.nomusic: # Check for a matching mp3 or ogg file. Check extensions # in the following order. validexts = [ '.wav', '.ogg', '.mp3' ] for ext in validexts: for data in self.SongDatas: if data.Ext == ext: # Found a match! soundFileData = data break if soundFileData: break if not soundFileData: ErrorString = "There is no mp3 or ogg file to match " + self.Song.DisplayFilename self.ErrorNotifyCallback (ErrorString) raise 'NoSoundFile' self.cdgFileData = self.SongDatas[0] self.soundFileData = soundFileData self.soundLength = 0 # Handle a bug in pygame (pre-1.7) which means that the position # timer carries on even when the song has been paused. self.pauseOffsetTime = 0 manager.settings.CdgZoom = 'full' manager.InitPlayer(self) #manager.OpenDisplay(displaySize=[CDG_DISPLAY_WIDTH, CDG_DISPLAY_HEIGHT]) manager.OpenDisplay() manager.surface.fill((0, 0, 0)) # A working surface for blitting tiles, one at a time. self.workingTile = pygame.Surface((TILE_WIDTH, TILE_HEIGHT), 0, manager.surface) # A surface that contains the set of all tiles as they are to # be assembled onscreen. This surface is kept at the original # scale, then zoomed to display size. It is only used if # settings.CdgZoom == 'soft'. self.workingSurface = pygame.Surface((CDG_DISPLAY_WIDTH, CDG_DISPLAY_HEIGHT), pygame.HWSURFACE, manager.surface) self.borderColour = None self.computeDisplaySize() aux = aux_c if not aux or not manager.settings.CdgUseC: print "Using Python implementation of CDG interpreter." aux = aux_python # Open the cdg and sound files self.packetReader = aux.CdgPacketReader(self.cdgFileData.GetData(), self.workingTile) manager.setCpuSpeed('cdg') if self.soundFileData: # Play the music normally. audioProperties = None if manager.settings.UseMp3Settings: audioProperties = self.getAudioProperties(self.soundFileData) if audioProperties == None: audioProperties = (None, None, None) try: manager.OpenAudio(*audioProperties) audio_path = self.soundFileData.GetFilepath() if type(audio_path) == unicode: audio_path = audio_path.encode(sys.getfilesystemencoding()) pygame.mixer.music.load(audio_path) except: self.Close() raise # Set an event for when the music finishes playing pygame.mixer.music.set_endevent(pygame.USEREVENT) # Account for the size of the playback buffer in the lyrics # display. Assume that the buffer will be mostly full. On a # slower computer that's struggling to keep up, this may not # be the right amount of delay, but it should usually be # pretty close. self.InternalOffsetTime = -manager.GetAudioBufferMS() else: # Don't play anything. self.InternalOffsetTime = 0 # Set the CDG file at the beginning self.cdgReadPackets = 0 self.cdgPacketsDue = 0 self.LastPos = self.curr_pos = 0 # Some session-wide constants. self.ms_per_update = (1000.0 / manager.options.fps)
def beginSong(self, file): self.selectedSong = None manager.setCpuSpeed('load') manager.display.fill((0,0,0)) winWidth, winHeight = manager.displaySize winCenter = winWidth / 2 rowA = winHeight / 3 rowC = winHeight * 5 / 6 self.__writeSongTitle(file, rowA) text = self.subtitleFont.render("Loading", True, (255,255,255)) rect = text.get_rect() rect = rect.move(winCenter - rect.centerx, rowC) manager.display.blit(text, rect) pygame.display.flip() # This will call the songFinishedCallback, so call it early. self.shutdown() self.writeMarkedSongs() player = file.MakePlayer( self.songDb, self.errorPopupCallback, self.songFinishedCallback) if player == None: return # Start playing. try: player.Play() except: self.errorPopupCallback("Error starting player.\n%s\n%s" % (sys.exc_info()[0], sys.exc_info()[1])) return # Go to sleep until the song is over. try: manager.WaitForPlayer() except: self.errorPopupCallback("Error while playing song.\n%s\n%s" % (sys.exc_info()[0], sys.exc_info()[1])) return # The song is over. Now recover control and redisplay the # song list. manager.OpenCPUControl() manager.setCpuSpeed('menu_fast') self.heldStartTicks = pygame.time.get_ticks() manager.InitPlayer(self) manager.OpenDisplay() # In case the screen has been resized during the song. self.setupScrollWindow() self.screenDirty = True # Discard any events that occurred while we were resetting the # display. for event in pygame.event.get(): pass
def start(self): self.appStart = pygame.time.get_ticks() self.heldStartTicks = self.appStart manager.OpenCPUControl() manager.setCpuSpeed('startup') self.numSongInfoLines = 1 self.setupSplashScreen() manager.InitPlayer(self) self.setupScrollWindow() self.screenDirty = True needsSave = False if manager.options.scan_dir: # Replace the old scan list. self.songDb.Settings.FolderList = [ manager.options.scan_dir ] needsSave = True if manager.options.scan_dirs: # Add one or more new directories to the list. self.songDb.Settings.FolderList += manager.options.scan_dirs needsSave = True if manager.options.scan: # Re-scan the files. self.songDb.BuildSearchDatabase(pykdb.AppYielder(), MiniBusyCancelDialog(self)) needsSave = True else: # Read the existing database. self.songDb.LoadDatabase(self.errorPopupCallback) if needsSave: self.songDb.SaveSettings() self.songDb.SaveDatabase() if not self.songDb.FullSongList: # No files. self.errorPopupCallback("No songs in catalog.") return if manager.options.validate: manager.ValidateDatabase(self.songDb) return if self.songDb.GotTitles: self.numSongInfoLines += 1 if self.songDb.GotArtists: self.numSongInfoLines += 1 self.setupScrollWindow() self.readMarkedSongs() if self.songDb.GotTitles: self.songDb.SelectSort('title') elif self.songDb.GotArtists: self.songDb.SelectSort('artist') else: self.songDb.SelectSort('filename') self.currentRow = 0 self.searchString = '' self.heldKey = None self.heldStartTicks = 0 self.heldRepeat = 0 manager.setCpuSpeed('wait') # Now that we've finished loading, wait up a second and give # the user a chance to view the splash screen, in case we # loaded too fast. if self.splashStart != None: splashTime = pygame.time.get_ticks() - self.splashStart remainingTime = 2500 - splashTime if remainingTime > 0: pygame.time.wait(remainingTime) self.running = True manager.setCpuSpeed('menu_fast') self.heldStartTicks = pygame.time.get_ticks() while self.running: manager.Poll() self.writeMarkedSongs() manager.CloseDisplay()
def __init__(self, song, songDb, errorNotifyCallback=None, doneCallback=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ pykPlayer.__init__(self, song, songDb, errorNotifyCallback, doneCallback) # With the nomusic option no music will be played. soundFileData = None if not manager.options.nomusic: # Check for a matching mp3 or ogg file. Check extensions # in the following order. validexts = ['.wav', '.ogg', '.mp3'] for ext in validexts: for data in self.SongDatas: if data.Ext == ext: # Found a match! soundFileData = data break if soundFileData: break if not soundFileData: ErrorString = "There is no mp3 or ogg file to match " + self.Song.DisplayFilename self.ErrorNotifyCallback(ErrorString) raise 'NoSoundFile' self.cdgFileData = self.SongDatas[0] self.soundFileData = soundFileData self.soundLength = 0 # Handle a bug in pygame (pre-1.7) which means that the position # timer carries on even when the song has been paused. self.pauseOffsetTime = 0 manager.InitPlayer(self) manager.OpenDisplay() manager.surface.fill((0, 0, 0)) # A working surface for blitting tiles, one at a time. self.workingTile = pygame.Surface((TILE_WIDTH, TILE_HEIGHT), 0, manager.surface) # A surface that contains the set of all tiles as they are to # be assembled onscreen. This surface is kept at the original # scale, then zoomed to display size. It is only used if # settings.CdgZoom == 'soft'. self.workingSurface = pygame.Surface( (CDG_DISPLAY_WIDTH, CDG_DISPLAY_HEIGHT), pygame.HWSURFACE, manager.surface) self.borderColour = None self.computeDisplaySize() aux = aux_c if not aux or not manager.settings.CdgUseC: print("Using Python implementation of CDG interpreter.") aux = aux_python # Open the cdg and sound files self.packetReader = aux.CdgPacketReader(self.cdgFileData.GetData(), self.workingTile) manager.setCpuSpeed('cdg') if self.soundFileData: # Play the music normally. audioProperties = None if manager.settings.UseMp3Settings: audioProperties = self.getAudioProperties(self.soundFileData) if audioProperties == None: audioProperties = (None, None, None) try: manager.OpenAudio(*audioProperties) audio_path = self.soundFileData.GetFilepath() if type(audio_path) == unicode: audio_path = audio_path.encode(sys.getfilesystemencoding()) pygame.mixer.music.load(audio_path) except: self.Close() raise # Set an event for when the music finishes playing pygame.mixer.music.set_endevent(pygame.USEREVENT) # Account for the size of the playback buffer in the lyrics # display. Assume that the buffer will be mostly full. On a # slower computer that's struggling to keep up, this may not # be the right amount of delay, but it should usually be # pretty close. self.InternalOffsetTime = -manager.GetAudioBufferMS() else: # Don't play anything. self.InternalOffsetTime = 0 # Set the CDG file at the beginning self.cdgReadPackets = 0 self.cdgPacketsDue = 0 self.LastPos = self.curr_pos = 0 # Some session-wide constants. self.ms_per_update = (1000.0 / manager.options.fps)