OpenTTD
Macros | Enumerations | Functions | Variables
qtmidi.cpp File Reference

MIDI music player for MacOS X using QuickTime. More...

#include "../stdafx.h"
#include "qtmidi.h"
#include "../debug.h"
#include <QuickTime/QuickTime.h>
#include "../safeguards.h"

Go to the source code of this file.

Macros

#define Rect   OTTDRect
#define Point   OTTDPoint
#define VOLUME   ((short)((0x00FF & _quicktime_volume) << 1))
 Maps OpenTTD volume to QuickTime notion of volume.

Enumerations

enum  QTStates { QT_STATE_IDLE, QT_STATE_PLAY, QT_STATE_STOP }
 Possible states of the QuickTime music driver. More...

Functions

static void SetMIDITypeIfNeeded (const FSRef *ref)
 Sets the OSType of a given file to 'Midi', but only if it's not already set.
static bool LoadMovieForMIDIFile (const char *path, Movie *moov)
 Loads a MIDI file and returns it as a QuickTime Movie structure.
static void InitQuickTimeIfNeeded ()
 Initialize QuickTime if needed.

Variables

static FMusicDriver_QtMidi iFMusicDriver_QtMidi
static const uint MIDI_TYPE = 'Midi'
 OSType code for MIDI songs.
static bool _quicktime_started = false
 Flag which has the true value when QuickTime is available and initialized.
static Movie _quicktime_movie
 Current QuickTime Movie.
static byte _quicktime_volume = 127
 Current volume.
static int _quicktime_state = QT_STATE_IDLE
 Current player state.

Detailed Description

MIDI music player for MacOS X using QuickTime.

This music player should work in all MacOS X releases starting from 10.0, as QuickTime is an integral part of the system since the old days of the Motorola 68k-based Macintoshes. The only extra dependency apart from QuickTime itself is Carbon, which is included since 10.0 as well.

QuickTime gets fooled with the MIDI files from Transport Tycoon Deluxe because of the .gm suffix. To force QuickTime to load the MIDI files without the need of dealing with the individual QuickTime components needed to play music (data source, MIDI parser, note allocators, synthesizers and the like) some Carbon functions are used to set the file type as seen by QuickTime, using FSpSetFInfo() (which modifies the file's resource fork).

Definition in file qtmidi.cpp.

Enumeration Type Documentation

enum QTStates

Possible states of the QuickTime music driver.

Enumerator:
QT_STATE_IDLE 

No file loaded.

QT_STATE_PLAY 

File loaded, playing.

QT_STATE_STOP 

File loaded, stopped.

Definition at line 164 of file qtmidi.cpp.

Function Documentation

static void InitQuickTimeIfNeeded ( )
static

Initialize QuickTime if needed.

This function sets the _quicktime_started flag to true if QuickTime is present in the system and it was initialized properly.

Definition at line 148 of file qtmidi.cpp.

References _quicktime_started, and DEBUG.

Referenced by MusicDriver_QtMidi::Start().

static bool LoadMovieForMIDIFile ( const char *  path,
Movie *  moov 
)
static

Loads a MIDI file and returns it as a QuickTime Movie structure.

Parameters
*pathString with the path of an existing MIDI file.
*moovPointer to a Movie where the result will be stored.
Returns
Whether the file was loaded and the Movie successfully created.

Definition at line 85 of file qtmidi.cpp.

References DEBUG, and SetMIDITypeIfNeeded().

Referenced by MusicDriver_QtMidi::PlaySong().

static void SetMIDITypeIfNeeded ( const FSRef *  ref)
static

Sets the OSType of a given file to 'Midi', but only if it's not already set.

Parameters
*refA FSSpec structure referencing a file.

Definition at line 55 of file qtmidi.cpp.

References DEBUG, and MIDI_TYPE.

Referenced by LoadMovieForMIDIFile().