31 #include "../stdafx.h" 36 #define Point OTTDPoint 37 #include <QuickTime/QuickTime.h> 41 #include "../safeguards.h" 57 FSCatalogInfo catalogInfo;
61 if (noErr != FSGetCatalogInfo(ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL))
return;
62 if (!(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)) {
63 FileInfo *
const info = (FileInfo *) catalogInfo.finderInfo;
64 if (info->fileType !=
MIDI_TYPE && !(info->finderFlags & kIsAlias)) {
67 e = FSSetCatalogInfo(ref, kFSCatInfoFinderInfo, &catalogInfo);
69 DEBUG(driver, 3,
"qtmidi: changed filetype to 'Midi'");
71 DEBUG(driver, 0,
"qtmidi: changing filetype to 'Midi' failed - error %d", e);
98 DEBUG(driver, 2,
"qtmidi: start loading '%s'...", path);
106 fd = open(path, O_RDONLY, 0);
107 if (fd == -1)
return false;
108 ret = read(fd, magic, 4);
110 if (ret < 4)
return false;
112 DEBUG(driver, 3,
"qtmidi: header is '%.4s'", magic);
113 if (magic[0] !=
'M' || magic[1] !=
'T' || magic[2] !=
'h' || magic[3] !=
'd') {
117 if (noErr != FSPathMakeRef((
const UInt8 *) path, &fsref, NULL))
return false;
120 if (noErr != FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsspec, NULL))
return false;
121 if (OpenMovieFile(&fsspec, &refnum, fsRdPerm) != noErr)
return false;
122 DEBUG(driver, 3,
"qtmidi: '%s' successfully opened", path);
124 if (noErr != NewMovieFromFile(moov, refnum, &resid, NULL,
125 newMovieActive | newMovieDontAskUnresolvedDataRefs, NULL)) {
126 CloseMovieFile(refnum);
129 DEBUG(driver, 3,
"qtmidi: movie container created");
131 CloseMovieFile(refnum);
154 DEBUG(driver, 2,
"qtmidi: initializing Quicktime");
157 (noErr == Gestalt(gestaltQuickTime, &dummy)) &&
158 (noErr == EnterMovies());
179 #define VOLUME ((short)((0x00FF & _quicktime_volume) << 1)) 236 DEBUG(driver, 2,
"qtmidi: stopping driver...");
239 DEBUG(driver, 3,
"qtmidi: stopping not needed, already idle");
265 DEBUG(driver, 2,
"qtmidi: trying to play '%s'", filename);
269 DEBUG(driver, 3,
"qtmidi: previous tune stopped");
274 DEBUG(driver, 3,
"qtmidi: previous tune disposed");
284 DEBUG(driver, 3,
"qtmidi: playing '%s'", filename);
300 DEBUG(driver, 3,
"qtmidi: stop requested, but already idle");
307 DEBUG(driver, 3,
"qtmidi: player stopped");
327 DEBUG(driver, 2,
"qtmidi: set volume to %u (%hi)", vol,
VOLUME);
Base of music playback via the QuickTime driver.
bool IsSongPlaying()
Checks whether the player is active.
void PlaySong(const char *filename)
Starts playing a new song.
static void InitQuickTimeIfNeeded()
Initialize QuickTime if needed.
void StopSong()
Stops playing the current song, if the player is active.
static int _quicktime_state
Current player state.
void Stop()
Stops the MIDI player.
void SetVolume(byte vol)
Changes the playing volume of the MIDI player.
static Movie _quicktime_movie
Current QuickTime Movie.
static bool LoadMovieForMIDIFile(const char *path, Movie *moov)
Loads a MIDI file and returns it as a QuickTime Movie structure.
static byte _quicktime_volume
Current volume.
#define DEBUG(name, level,...)
Output a line of debugging information.
QTStates
Possible states of the QuickTime music driver.
static const uint MIDI_TYPE
OSType code for MIDI songs.
static bool _quicktime_started
Flag which has the true value when QuickTime is available and initialized.
static void SetMIDITypeIfNeeded(const FSRef *ref)
Sets the OSType of a given file to 'Midi', but only if it's not already set.
const char * Start(const char *const *param)
Initialized the MIDI player, including QuickTime initialization.
#define VOLUME
Maps OpenTTD volume to QuickTime notion of volume.