示例#1
0
    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]))
示例#2
0
 def __init__(self):
     pykPlayer.__init__(self,
                        '',
                        None,
                        self.errorPopupCallback,
                        self.songFinishedCallback,
                        windowTitle="PyKaraoke")
     self.SupportsFontZoom = True
     self.selectedSong = None
示例#3
0
    def __init__(self, song, 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, errorNotifyCallback, doneCallback)

        self.Movie = None

        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]))
示例#4
0
    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
示例#5
0
    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
示例#6
0
文件: pympg.py 项目: astagi/pykaraoke
    def __init__(self, song, songDb,
                 errorNotifyCallback = None, doneCallback = None,
                 windowTitle = None, quitCallback = 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, windowTitle, quitCallback)

        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]))
示例#7
0
    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)
示例#8
0
 def __init__(self):
     pykPlayer.__init__(self, '', None, self.errorPopupCallback,
                        self.songFinishedCallback, windowTitle = "PyKaraoke")
     self.SupportsFontZoom = True
     self.selectedSong = None
示例#9
0
    def __init__(self, song, 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, 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

        # 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.display.fill((0, 0, 0))

        # A working surface for blitting tiles, one at a time.
        self.workingTile = pygame.Surface((TILE_WIDTH, TILE_HEIGHT),
                                          0, manager.display)

        # 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
        # options.zoom_mode == 'soft'.
        self.workingSurface = pygame.Surface((CDG_DISPLAY_WIDTH, CDG_DISPLAY_HEIGHT),
                                             pygame.HWSURFACE,
                                             manager.display)

        self.borderColour = None
        self.computeDisplaySize()

        # Open the cdg and sound files
        self.packetReader = aux.CdgPacketReader(self.cdgFileData.GetData(), self.workingTile)
        
        if self.soundFileData:
            audioProperties = self.getAudioProperties(self.soundFileData)
            try:
                manager.OpenAudio(suggestedProperties = (audioProperties))
                pygame.mixer.music.load(self.soundFileData.GetFilepath())
            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:
            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)        
示例#10
0
    def __init__(self,
                 cdgfile,
                 size=(640, 480),
                 fullscreen=False,
                 zippath=None,
                 offsetTime=0,
                 errorNotifyCallback=None,
                 doneCallback=None):

        pykPlayer.__init__(self, cdgfile, errorNotifyCallback, doneCallback)

        # With the nomusic option no music will be played.
        soundFileData = None
        self.State = STATE_INIT
        self.InternalOffsetTime = offsetTime
        self.PlayTime = 0
        self.PlayStartTime = 0
        self.PlayFrame = 0
        self.displaySize = size
        self.fullScreen = fullscreen
        self.tempdir = tempfile.mkdtemp()
        # Check for a matching mp3 or ogg file.  Check extensions
        # in the following order.
        self.validexts = ['.wav', '.ogg', '.mp3']

        print "Get soundFileData"
        if zippath:
            print "Opening zip, %s" % zippath
            cdgfile, soundFilePath = self._extractZipData(cdgfile, zippath)
        else:
            basepath = os.path.splitext(cdgfile)[0]
            soundFilePath = None
            candidates = glob.glob("%s.*" % basepath)
            for candidate in candidates:
                name, ext = os.path.splitext(candidate)
                if ext.lower() in self.validexts:
                    soundFilePath = candidate
                    break

            if not soundFilePath:
                ErrorString = "There is no mp3 or ogg file to match :", cdgfile
                self.ErrorNotifyCallback(ErrorString)
                raise 'NoSoundFile'

        print "Get cdg file data."
        f = open(cdgfile, 'rb')
        try:
            self.cdgFileData = f.read()
        finally:
            f.close()

        # 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
        self.cdgZoom = 'soft'
        self.displayDepth = 8
        self.displayFlags = pygame.RESIZABLE | pygame.HWSURFACE
        if self.fullScreen:
            self.displayFlags |= pygame.FULLSCREEN

        print "Init player"
        pygame.mixer.pre_init(44100, -16, 2, 4096)
        pygame.init()
        pygame.mixer.init(44100, -16, 2, 4096)
        #pygame.mixer.pre_init(44100, -16, 2)
        pygame.display.init()
        pygame.display.set_caption(cdgfile)
        #pygame.mouse.set_visible(True)
        pygame.mouse.set_visible(False)
        self.display = pygame.display.set_mode(self.displaySize,
                                               self.displayFlags)
        self.displayTime = pygame.time.get_ticks()
        self.display.fill((100, 100, 100))

        print "Fill surface"
        self.surface = pygame.Surface(self.displaySize)
        self.surface.fill((128, 128, 0))
        # A working surface for blitting tiles, one at a time.
        self.workingTile = pygame.Surface((TILE_WIDTH, TILE_HEIGHT), 0,
                                          self.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,
            self.surface)
        #self.workingSurface = self.display
        self.borderColour = None
        print "Compute display size"
        self.computeDisplaySize()
        aux = aux_c
        if not aux:
            print "Using Python implementation of CDG interpreter."
            aux = aux_python
        else:
            print "Using C based CDG interpreter."
        print "Open cdg and sound files"
        # Open the cdg and sound files
        self.packetReader = aux.CdgPacketReader(self.cdgFileData,
                                                self.workingTile)
        print "test for sound file data"
        if soundFilePath:
            print "YES"
            # Play the music normally.
            audioProperties = None
            print "Use mp3 settings?"
            #if manager.settings.UseMp3Settings:
            print "Get audio properties"
            audioProperties = self.getAudioProperties(soundFilePath)
            #    print self.soundFileData
            print audioProperties

            if audioProperties == None:
                print "None audio properties"
                audioProperties = (None, None, None)
            try:
                print "Try open audio"
                #manager.OpenAudio(*audioProperties)
                print "Try music load: ", soundFilePath
                pygame.mixer.music.load(soundFilePath)
                print "OK"
            except:
                print "Oh noes!"
                self.Close()
                raise

            # Set an event for when the music finishes playing
            print "Set end event"
            pygame.mixer.music.set_endevent(pygame.USEREVENT)

        else:
            # Don't play anything.
            self.InternalOffsetTime = 0

        print "set to beginning"
        # 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 / 30)
示例#11
0
    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)
示例#12
0
    def __init__(self, song, errorNotifyCallback=None, doneCallback=None, Charset="iso-8859-1"):
        """The first parameter, song, may be either a pykdb.SongStruct
        instance, or it may be a filename. """

        pykPlayer.__init__(self, song, errorNotifyCallback, doneCallback)

        self.SupportsFontZoom = True

        # Parse the MIDI file
        self.midifile = midiParseData(self.SongDatas[0].GetData(), self.ErrorNotifyCallback, Charset)
        if (self.midifile == None):
            ErrorString = "ERROR: Could not parse the MIDI file"
            self.ErrorNotifyCallback (ErrorString)
            return
        elif (self.midifile.lyrics == None):    
            ErrorString = "ERROR: Could not get any lyric data from file"
            self.ErrorNotifyCallback (ErrorString)
            return

        # Debug out the found lyrics
        if debug:
            self.midifile.lyrics.write()

        manager.InitPlayer(self)
        manager.OpenDisplay()

        # Reduce the default sample rate on the GP2x to save CPU time.
        if env == ENV_GP2X:
            manager.OpenAudio(suggestedProperties = (12000, -16, 1))
        else:
            manager.OpenAudio(suggestedProperties = (22050, -16, 2))

        # 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()

        self.screenDirty = False
        self.initFont()

        # Windows reports the song time correctly (including period up
        # to the first note), so no need for the earliest note hack
        # there.  On timidity-based platforms, we anticipate our
        # lyrics display by the time of the first note.
        if env != ENV_WINDOWS:
            self.InternalOffsetTime += self.midifile.earliestNoteMS

        # Now word-wrap the text to fit our window.
        self.lyrics = self.midifile.lyrics.wordWrapLyrics(self.font)

        # By default, we will use the get_pos() functionality returned
        # by pygame to get the current time through the song, to
        # synchronize lyric display with the music.
        self.useMidiTimer = True

        if env == ENV_WINDOWS:
            # Unless we're running on Windows.  For some reason, MIDI
            # playback on Windows reports an unreliable time.  To
            # avoid that problem, we'll always use the CPU timer
            # instead of the MIDI timer.
            self.useMidiTimer = False

        # Load the MIDI player
        if not manager.options.nomusic:
            pygame.mixer.music.load(self.SongDatas[0].GetFilepath())

            # Set an event for when the music finishes playing
            pygame.mixer.music.set_endevent(pygame.USEREVENT)
        else:
            # If we're not playing music, use the CPU timer instead of
            # the MIDI timer.
            self.useMidiTimer = False

        # Reset all the state (current lyric index etc) and
        # paint the first numRows lines.
        self.resetPlayingState()
示例#13
0
文件: pykar.py 项目: thiagohersan/SDR
    def __init__(self,
                 song,
                 errorNotifyCallback=None,
                 doneCallback=None,
                 Charset="iso-8859-1"):
        """The first parameter, song, may be either a pykdb.SongStruct
        instance, or it may be a filename. """

        pykPlayer.__init__(self, song, errorNotifyCallback, doneCallback)

        self.SupportsFontZoom = True

        # Parse the MIDI file
        self.midifile = midiParseData(self.SongDatas[0].GetData(),
                                      self.ErrorNotifyCallback, Charset)
        if (self.midifile == None):
            ErrorString = "ERROR: Could not parse the MIDI file"
            self.ErrorNotifyCallback(ErrorString)
            return
        elif (self.midifile.lyrics == None):
            ErrorString = "ERROR: Could not get any lyric data from file"
            self.ErrorNotifyCallback(ErrorString)
            return

        # Debug out the found lyrics
        if debug:
            self.midifile.lyrics.write()

        manager.InitPlayer(self)
        manager.OpenDisplay()

        # Reduce the default sample rate on the GP2x to save CPU time.
        if env == ENV_GP2X:
            manager.OpenAudio(suggestedProperties=(12000, -16, 1))
        else:
            manager.OpenAudio(suggestedProperties=(22050, -16, 2))

        # 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()

        self.screenDirty = False
        self.initFont()

        # Windows reports the song time correctly (including period up
        # to the first note), so no need for the earliest note hack
        # there.  On timidity-based platforms, we anticipate our
        # lyrics display by the time of the first note.
        if env != ENV_WINDOWS:
            self.InternalOffsetTime += self.midifile.earliestNoteMS

        # Now word-wrap the text to fit our window.
        self.lyrics = self.midifile.lyrics.wordWrapLyrics(self.font)

        # By default, we will use the get_pos() functionality returned
        # by pygame to get the current time through the song, to
        # synchronize lyric display with the music.
        self.useMidiTimer = True

        if env == ENV_WINDOWS:
            # Unless we're running on Windows.  For some reason, MIDI
            # playback on Windows reports an unreliable time.  To
            # avoid that problem, we'll always use the CPU timer
            # instead of the MIDI timer.
            self.useMidiTimer = False

        # Load the MIDI player
        if not manager.options.nomusic:
            pygame.mixer.music.load(self.SongDatas[0].GetFilepath())

            # Set an event for when the music finishes playing
            pygame.mixer.music.set_endevent(pygame.USEREVENT)
        else:
            # If we're not playing music, use the CPU timer instead of
            # the MIDI timer.
            self.useMidiTimer = False

        # Reset all the state (current lyric index etc) and
        # paint the first numRows lines.
        self.resetPlayingState()
示例#14
0
    def __init__(
            self, 
            cdgfile,
            size=(640,480),
            fullscreen=False,
            zippath=None,
            offsetTime=0,
            errorNotifyCallback=None,
            doneCallback=None
        ):

        pykPlayer.__init__(self, cdgfile, errorNotifyCallback, doneCallback)

        # With the nomusic option no music will be played.
        soundFileData = None
        self.State = STATE_INIT
        self.InternalOffsetTime = offsetTime
        self.PlayTime = 0
        self.PlayStartTime = 0
        self.PlayFrame = 0
        self.displaySize = size
        self.fullScreen = fullscreen 
        self.tempdir = tempfile.mkdtemp()
        # Check for a matching mp3 or ogg file.  Check extensions
        # in the following order.
        self.validexts = [
            '.wav', '.ogg', '.mp3'
        ]

        print "Get soundFileData"
        if zippath:
            print "Opening zip, %s" % zippath
            cdgfile, soundFilePath = self._extractZipData(cdgfile, zippath)
        else:
            basepath = os.path.splitext(cdgfile)[0]
            soundFilePath = None
            candidates = glob.glob("%s.*" % basepath)
            for candidate in candidates:
                name, ext = os.path.splitext(candidate)
                if ext.lower() in self.validexts:
                    soundFilePath = candidate
                    break

            if not soundFilePath:
                ErrorString = "There is no mp3 or ogg file to match :", cdgfile 
                self.ErrorNotifyCallback (ErrorString)
                raise 'NoSoundFile'

        print "Get cdg file data."
        f = open(cdgfile, 'rb')
        try:
            self.cdgFileData = f.read()
        finally:
            f.close()

        # 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
        self.cdgZoom = 'soft'
        self.displayDepth = 8
        self.displayFlags = pygame.RESIZABLE | pygame.HWSURFACE
        if self.fullScreen:
            self.displayFlags |= pygame.FULLSCREEN

        print "Init player"
        pygame.mixer.pre_init(44100, -16, 2, 4096)    
        pygame.init()
        pygame.mixer.init(44100, -16, 2, 4096)    
        #pygame.mixer.pre_init(44100, -16, 2)    
        pygame.display.init()
        pygame.display.set_caption(cdgfile)
        #pygame.mouse.set_visible(True)
        pygame.mouse.set_visible(False)
        self.display = pygame.display.set_mode(self.displaySize, self.displayFlags)
        self.displayTime = pygame.time.get_ticks()
        self.display.fill((100,100,100))

        print "Fill surface"
        self.surface = pygame.Surface(self.displaySize)
        self.surface.fill((128, 128, 0))
        # A working surface for blitting tiles, one at a time.
        self.workingTile = pygame.Surface((TILE_WIDTH, TILE_HEIGHT),
                                          0, self.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,
                                             self.surface)
        #self.workingSurface = self.display
        self.borderColour = None
        print "Compute display size"
        self.computeDisplaySize()
        aux = aux_c
        if not aux: 
            print "Using Python implementation of CDG interpreter."
            aux = aux_python
        else:
            print "Using C based CDG interpreter."
        print "Open cdg and sound files"
        # Open the cdg and sound files
        self.packetReader = aux.CdgPacketReader(self.cdgFileData, self.workingTile)
        print "test for sound file data"
        if soundFilePath:
            print "YES"
            # Play the music normally.
            audioProperties = None
            print "Use mp3 settings?"
            #if manager.settings.UseMp3Settings:
            print "Get audio properties"
            audioProperties = self.getAudioProperties(soundFilePath)
            #    print self.soundFileData
            print audioProperties

            if audioProperties == None:
                print "None audio properties"
                audioProperties = (None, None, None)
            try:
                print "Try open audio"
                #manager.OpenAudio(*audioProperties)
                print "Try music load: ", soundFilePath
                pygame.mixer.music.load(soundFilePath)
                print "OK"
            except:
                print "Oh noes!"
                self.Close()
                raise

            # Set an event for when the music finishes playing
            print "Set end event"
            pygame.mixer.music.set_endevent(pygame.USEREVENT)

        else:
            # Don't play anything.
            self.InternalOffsetTime = 0
            
        print "set to beginning"
        # 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 / 30)