OK chaps I've knocked up a quick proof of concept. Jay, could you try
out the attached pycdg.py please? Basically I've just divided the screen
into four segments. I now only do the scaling on the segments that have
been updated. I'm not sure how it will pan out, so before I tidy it up
and do it properly, could you give this one a go? FPS is set to 30.
That first draft was a little rough round the edges. Amongst other
things, it didn't update the screen on Preset commands. I've attached
the latest version for your testing pleasure.
Beware that this one includes some code to bar any screen updates if the
decoding gets 1/4 second behind the music. I figure the best thing to do
in these situations is to not add insult to injury by carrying on
performing slow output scaling. If there's a spell of heavy CPU activity
it'll stop doing any updates, allowing the CPU to catch up quicker. The
thinking is that a spell of no updates is better than a spell of out of
sync updates.
Cheers,
Kelvin.
#!/usr/bin/env python
# pycdg - CDG/MP3+G Karaoke Player
# Copyright (C) 2005 Kelvin Lawson ([EMAIL PROTECTED])
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# OVERVIEW
#
# pycdg is a CDG karaoke player which supports MP3+G and OGG+G tracks.
#
# The player uses the pygame library (www.pygame.org), and can therefore
# run on any operating system that runs pygame (currently Linux, Windows
# and OSX).
#
# You can use this file as a standalone player, or together with
# PyKaraoke. PyKaraoke provides a graphical user interface, playlists,
# searchable song database etc.
#
# For those writing a media player or similar project who would like
# CDG support, this module has been designed to be easily incorporated
# into such projects and is released under the LGPL.
# REQUIREMENTS
#
# pycdg requires the following to be installed on your system:
# . Python (www.python.org)
# . Pygame (www.pygame.org)
# . Numeric module (numpy.sourceforge.net)
# USAGE INSTRUCTIONS
#
# To start the player, pass the CDG filename/path on the command line:
# python pycdg.py /songs/theboxer.cdg
#
# You can also incorporate a CDG player in your own projects by
# importing this module. The class cdgPlayer is exported by the
# module. You can import and start it as follows:
# import pycdg
# player = pycdg.cdgPlayer("/songs/theboxer.cdg")
# player.Play()
#
# The class also exports Close(), Pause(), Rewind(), GetPos().
#
# There are two optional parameters to the initialiser, errorNotifyCallback
# and doneCallback:
#
# errorNotifyCallback, if provided, will be used to print out any error
# messages (e.g. song file not found). This allows the module to fit
# together well with GUI playlist managers by utilising the same GUI's
# error popup window mechanism (or similar). If no callback is provided,
# errors are printed to stdout. errorNotifyCallback should take one
# parameter, the error string, e.g.:
# def errorPopup (ErrorString):
# msgBox (ErrorString)
#
# doneCallback can be used to register a callback so that the player
# calls you back when the song is finished playing. The callback should
# take no parameters, e.g.:
# def songFinishedCallback():
# msgBox ("Song is finished")
#
# To register callbacks, pass the functions in to the initialiser:
# cdgPlayer ("/songs/theboxer.cdg", errorPopup, songFinishedCallback)
# These parameters are optional and default to None.
#
# If the initialiser fails (e.g. the song file is not present), __init__
# raises an exception.
# IMPLEMENTATION DETAILS
#
# pycdg is implemented as one python module. It performs all
# of the CDG file decoding locally, and gets audio playback
# and video display capabilities from the pygame library.
# It also uses the python Numeric module, which provides
# fast handling of the arrays of pixel data for the display.
#
# All of the information on the CDG file format was learned
# from the fabulous "CDG Revealed" tutorial at www.jbum.com.
#
# The player is run within a thread to allow for easy
# integration with media player programs. The thread starts
# the pygame MP3/OGG playback, and then monitors the current
# time in the song. It reads the CDG file at the correct
# location for the current position of the song, and decodes
# the CDG commands stored there. If the CDG command requires
# a screen u