|
@@ -44,12 +44,14 @@
|
|
|
#include <unistd.h>
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
// we need to include debug.h after CoreServices because defining DEBUG will break CoreServices in OSX 10.2
|
|
|
#include "../debug.h"
|
|
|
|
|
|
static FMusicDriver_QtMidi iFMusicDriver_QtMidi;
|
|
|
|
|
|
|
|
|
enum {
|
|
|
midiType = 'Midi' /**< OSType code for MIDI songs. */
|
|
|
};
|
|
|
|
|
|
|
|
@@ -204,36 +206,33 @@ static int _quicktime_state = QT_STAT
|
|
|
/**
|
|
|
* Maps OpenTTD volume to QuickTime notion of volume.
|
|
|
*/
|
|
|
#define VOLUME ((short)((0x00FF & _quicktime_volume) << 1))
|
|
|
|
|
|
|
|
|
static void StopSong();
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Initialized the MIDI player, including QuickTime initialization.
|
|
|
*
|
|
|
* @todo Give better error messages by inspecting error codes returned by
|
|
|
* @c Gestalt() and @c EnterMovies(). Needs changes in
|
|
|
* #InitQuickTimeIfNeeded.
|
|
|
*/
|
|
|
static const char* StartDriver(const char * const *parm)
|
|
|
const char *MusicDriver_QtMidi::Start(const char * const *parm)
|
|
|
{
|
|
|
InitQuickTimeIfNeeded();
|
|
|
return (_quicktime_started) ? NULL : "can't initialize QuickTime";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Checks wether the player is active.
|
|
|
*
|
|
|
* This function is called at regular intervals from OpenTTD's main loop, so
|
|
|
* we call @c MoviesTask() from here to let QuickTime do its work.
|
|
|
*/
|
|
|
static bool SongIsPlaying()
|
|
|
bool MusicDriver_QtMidi::IsSongPlaying()
|
|
|
{
|
|
|
if (!_quicktime_started) return true;
|
|
|
|
|
|
switch (_quicktime_state) {
|
|
|
case QT_STATE_IDLE:
|
|
|
case QT_STATE_STOP:
|
|
@@ -255,13 +254,13 @@ static bool SongIsPlaying()
|
|
|
/**
|
|
|
* Stops the MIDI player.
|
|
|
*
|
|
|
* Stops playing and frees any used resources before returning. As it
|
|
|
* deinitilizes QuickTime, the #_quicktime_started flag is set to @c false.
|
|
|
*/
|
|
|
static void StopDriver()
|
|
|
void MusicDriver_QtMidi::Stop()
|
|
|
{
|
|
|
if (!_quicktime_started) return;
|
|
|
|
|
|
DEBUG(driver, 2, "qtmidi: stopping driver...");
|
|
|
switch (_quicktime_state) {
|
|
|
case QT_STATE_IDLE:
|
|
@@ -281,13 +280,13 @@ static void StopDriver()
|
|
|
|
|
|
/**
|
|
|
* Starts playing a new song.
|
|
|
*
|
|
|
* @param filename Path to a MIDI file.
|
|
|
*/
|
|
|
static void PlaySong(const char *filename)
|
|
|
void MusicDriver_QtMidi::PlaySong(const char *filename)
|
|
|
{
|
|
|
if (!_quicktime_started) return;
|
|
|
|
|
|
DEBUG(driver, 2, "qtmidi: trying to play '%s'", filename);
|
|
|
switch (_quicktime_state) {
|
|
|
case QT_STATE_PLAY:
|
|
@@ -309,13 +308,13 @@ static void PlaySong(const char *filenam
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Stops playing the current song, if the player is active.
|
|
|
*/
|
|
|
static void StopSong()
|
|
|
void MusicDriver_QtMidi::StopSong()
|
|
|
{
|
|
|
if (!_quicktime_started) return;
|
|
|
|
|
|
switch (_quicktime_state) {
|
|
|
case QT_STATE_IDLE:
|
|
|
/* XXX Fall-through -- no break needed. */
|
|
@@ -337,13 +336,13 @@ static void StopSong()
|
|
|
* As QuickTime controls volume in a per-movie basis, the desired volume is
|
|
|
* stored in #_quicktime_volume, and the volume is set here using the
|
|
|
* #VOLUME macro, @b and when loading new song in #PlaySong.
|
|
|
*
|
|
|
* @param vol The desired volume, range of the value is @c 0-127
|
|
|
*/
|
|
|
static void SetVolume(byte vol)
|
|
|
void MusicDriver_QtMidi::SetVolume(byte vol)
|
|
|
{
|
|
|
if (!_quicktime_started) return;
|
|
|
|
|
|
_quicktime_volume = vol;
|
|
|
|
|
|
DEBUG(driver, 2, "qtmidi: set volume to %u (%hi)", vol, VOLUME);
|
|
@@ -354,18 +353,6 @@ static void SetVolume(byte vol)
|
|
|
case QT_STATE_PLAY:
|
|
|
case QT_STATE_STOP:
|
|
|
SetMovieVolume(_quicktime_movie, VOLUME);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Table of callbacks that implement the QuickTime MIDI player.
|
|
|
*/
|
|
|
const HalMusicDriver _qtime_music_driver = {
|
|
|
StartDriver,
|
|
|
StopDriver,
|
|
|
PlaySong,
|
|
|
StopSong,
|
|
|
SongIsPlaying,
|
|
|
SetVolume,
|
|
|
};
|