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.


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


 Possible states of the QuickTime music driver. More...


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


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

◆ QTStates

enum QTStates

Possible states of the QuickTime music driver.


No file loaded.


File loaded, playing.


File loaded, stopped.

Definition at line 164 of file qtmidi.cpp.

Function Documentation

◆ InitQuickTimeIfNeeded()

static void InitQuickTimeIfNeeded ( )

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

◆ LoadMovieForMIDIFile()

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

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

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

Definition at line 85 of file qtmidi.cpp.

Referenced by MusicDriver_QtMidi::PlaySong().

◆ SetMIDITypeIfNeeded()

static void SetMIDITypeIfNeeded ( const FSRef *  ref)

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

*refA FSSpec structure referencing a file.

Definition at line 55 of file qtmidi.cpp.