author | peter1138 |
Tue, 22 Jan 2008 07:27:06 +0000 | |
changeset 8374 | 7a1b6c89cb89 |
parent 7965 | e651c71175d6 |
permissions | -rw-r--r-- |
3970 | 1 |
/* $Id$ */ |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
2 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
3 |
/** |
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
5584
diff
changeset
|
4 |
* @file qtmidi.cpp |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
5 |
* @brief MIDI music player for MacOS X using QuickTime. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
6 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
7 |
* This music player should work in all MacOS X releases starting from 10.0, |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
8 |
* as QuickTime is an integral part of the system since the old days of the |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
9 |
* Motorola 68k-based Macintoshes. The only extra dependency apart from |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
10 |
* QuickTime itself is Carbon, which is included since 10.0 as well. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
11 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
12 |
* QuickTime gets fooled with the MIDI files from Transport Tycoon Deluxe |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
13 |
* because of the @c .gm suffix. To force QuickTime to load the MIDI files |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
14 |
* without the need of dealing with the individual QuickTime components |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
15 |
* needed to play music (data source, MIDI parser, note allocators, |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
16 |
* synthesizers and the like) some Carbon functions are used to set the file |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
17 |
* type as seen by QuickTime, using @c FSpSetFInfo() (which modifies the |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
18 |
* file's resource fork). |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
19 |
*/ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
20 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
21 |
|
7965
e651c71175d6
(svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents:
7839
diff
changeset
|
22 |
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3 |
e651c71175d6
(svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents:
7839
diff
changeset
|
23 |
#include <AvailabilityMacros.h> |
e651c71175d6
(svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents:
7839
diff
changeset
|
24 |
|
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
25 |
/* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
26 |
* OpenTTD includes. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
27 |
*/ |
3016
958672b0f8e2
(svn r3596) -Codechange: [OSX] changed to use Apple's macros instead of OTTD macros for endian conversion
bjarni
parents:
2741
diff
changeset
|
28 |
#define WindowClass OSX_WindowClass |
958672b0f8e2
(svn r3596) -Codechange: [OSX] changed to use Apple's macros instead of OTTD macros for endian conversion
bjarni
parents:
2741
diff
changeset
|
29 |
#include <QuickTime/QuickTime.h> |
958672b0f8e2
(svn r3596) -Codechange: [OSX] changed to use Apple's macros instead of OTTD macros for endian conversion
bjarni
parents:
2741
diff
changeset
|
30 |
#undef WindowClass |
958672b0f8e2
(svn r3596) -Codechange: [OSX] changed to use Apple's macros instead of OTTD macros for endian conversion
bjarni
parents:
2741
diff
changeset
|
31 |
|
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
32 |
#include "../stdafx.h" |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
33 |
#include "qtmidi.h" |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
34 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
35 |
/* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
36 |
* System includes. We need to workaround with some defines because there's |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
37 |
* stuff already defined in QuickTime headers. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
38 |
*/ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
39 |
#define OTTD_Random OSX_OTTD_Random |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
40 |
#undef OTTD_Random |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
41 |
#undef WindowClass |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
42 |
#undef SL_ERROR |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
43 |
#undef bool |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
44 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
45 |
#include <assert.h> |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
46 |
#include <unistd.h> |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
47 |
#include <fcntl.h> |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
48 |
|
2741
65d4de069014
(svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents:
2548
diff
changeset
|
49 |
// we need to include debug.h after CoreServices because defining DEBUG will break CoreServices in OSX 10.2 |
65d4de069014
(svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents:
2548
diff
changeset
|
50 |
#include "../debug.h" |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
51 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
52 |
static FMusicDriver_QtMidi iFMusicDriver_QtMidi; |
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
53 |
|
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
54 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
55 |
enum { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
56 |
midiType = 'Midi' /**< OSType code for MIDI songs. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
57 |
}; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
58 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
59 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
60 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
61 |
* Sets the @c OSType of a given file to @c 'Midi', but only if it's not |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
62 |
* already set. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
63 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
64 |
* @param *spec A @c FSSpec structure referencing a file. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
65 |
*/ |
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
66 |
static void SetMIDITypeIfNeeded(const FSRef *ref) |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
67 |
{ |
5433
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
68 |
FSCatalogInfo catalogInfo; |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
69 |
|
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
70 |
assert(ref); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
71 |
|
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
72 |
if (noErr != FSGetCatalogInfo(ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL)) return; |
5433
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
73 |
if (!(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)) { |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
74 |
FileInfo * const info = (FileInfo *) catalogInfo.finderInfo; |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
75 |
if (info->fileType != midiType && !(info->finderFlags & kIsAlias)) { |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
76 |
OSErr e; |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
77 |
info->fileType = midiType; |
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
78 |
e = FSSetCatalogInfo(ref, kFSCatInfoFinderInfo, &catalogInfo); |
5433
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
79 |
if (e == noErr) { |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
80 |
DEBUG(driver, 3, "qtmidi: changed filetype to 'Midi'"); |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
81 |
} else { |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
82 |
DEBUG(driver, 0, "qtmidi: changing filetype to 'Midi' failed - error %d", e); |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
83 |
} |
d98fcaa8dbc3
(svn r7639) -Fix: FS#487 Changed music/qtmidi.c to not use functions deprecated by Apple (pvz)
bjarni
parents:
5389
diff
changeset
|
84 |
} |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
85 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
86 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
87 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
88 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
89 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
90 |
* Loads a MIDI file and returns it as a QuickTime Movie structure. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
91 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
92 |
* @param *path String with the path of an existing MIDI file. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
93 |
* @param *moov Pointer to a @c Movie where the result will be stored. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
94 |
* @return Wether the file was loaded and the @c Movie successfully created. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
95 |
*/ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
96 |
static bool LoadMovieForMIDIFile(const char *path, Movie *moov) |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
97 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
98 |
int fd; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
99 |
int ret; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
100 |
char magic[4]; |
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
101 |
FSRef fsref; |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
102 |
FSSpec fsspec; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
103 |
short refnum = 0; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
104 |
short resid = 0; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
105 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
106 |
assert(path != NULL); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
107 |
assert(moov != NULL); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
108 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
109 |
DEBUG(driver, 2, "qtmidi: start loading '%s'...", path); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
110 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
111 |
/* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
112 |
* XXX Manual check for MIDI header ('MThd'), as I don't know how to make |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
113 |
* QuickTime load MIDI files without a .mid suffix without knowing it's |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
114 |
* a MIDI file and setting the OSType of the file to the 'Midi' value. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
115 |
* Perhahaps ugly, but it seems that it does the Right Thing(tm). |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
116 |
*/ |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
117 |
fd = open(path, O_RDONLY, 0); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
118 |
if (fd == -1) return false; |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
119 |
ret = read(fd, magic, 4); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
120 |
close(fd); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
121 |
if (ret < 4) return false; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
122 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
123 |
DEBUG(driver, 3, "qtmidi: header is '%.4s'", magic); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
124 |
if (magic[0] != 'M' || magic[1] != 'T' || magic[2] != 'h' || magic[3] != 'd') |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
125 |
return false; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
126 |
|
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
127 |
if (noErr != FSPathMakeRef((const UInt8 *) path, &fsref, NULL)) return false; |
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
128 |
SetMIDITypeIfNeeded(&fsref); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
129 |
|
7839
feb131e32620
(svn r11389) -Fix [FS#1386]: Replace calls to deprecated API with newer ones and handle broken iconv declaration in OSX 10.5.
egladil
parents:
7776
diff
changeset
|
130 |
if (noErr != FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsspec, NULL)) return false; |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
131 |
if (OpenMovieFile(&fsspec, &refnum, fsRdPerm) != noErr) return false; |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
132 |
DEBUG(driver, 3, "qtmidi: '%s' successfully opened", path); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
133 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
134 |
if (noErr != NewMovieFromFile(moov, refnum, &resid, NULL, |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
135 |
newMovieActive | newMovieDontAskUnresolvedDataRefs, NULL)) { |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
136 |
CloseMovieFile(refnum); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
137 |
return false; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
138 |
} |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
139 |
DEBUG(driver, 3, "qtmidi: movie container created"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
140 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
141 |
CloseMovieFile(refnum); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
142 |
return true; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
143 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
144 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
145 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
146 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
147 |
* Flag which has the @c true value when QuickTime is available and |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
148 |
* initialized. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
149 |
*/ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
150 |
static bool _quicktime_started = false; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
151 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
152 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
153 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
154 |
* Initialize QuickTime if needed. This function sets the |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
155 |
* #_quicktime_started flag to @c true if QuickTime is present in the system |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
156 |
* and it was initialized properly. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
157 |
*/ |
6247 | 158 |
static void InitQuickTimeIfNeeded() |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
159 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
160 |
OSStatus dummy; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
161 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
162 |
if (_quicktime_started) return; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
163 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
164 |
DEBUG(driver, 2, "qtmidi: initializing Quicktime"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
165 |
/* Be polite: check wether QuickTime is available and initialize it. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
166 |
_quicktime_started = |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
167 |
(noErr == Gestalt(gestaltQuickTime, &dummy)) && |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
168 |
(noErr == EnterMovies()); |
5389 | 169 |
if (!_quicktime_started) DEBUG(driver, 0, "qtmidi: Quicktime initialization failed!"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
170 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
171 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
172 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
173 |
/** Possible states of the QuickTime music driver. */ |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
174 |
enum { |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
175 |
QT_STATE_IDLE, /**< No file loaded. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
176 |
QT_STATE_PLAY, /**< File loaded, playing. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
177 |
QT_STATE_STOP, /**< File loaded, stopped. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
178 |
}; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
179 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
180 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
181 |
static Movie _quicktime_movie; /**< Current QuickTime @c Movie. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
182 |
static byte _quicktime_volume = 127; /**< Current volume. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
183 |
static int _quicktime_state = QT_STATE_IDLE; /**< Current player state. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
184 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
185 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
186 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
187 |
* Maps OpenTTD volume to QuickTime notion of volume. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
188 |
*/ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
189 |
#define VOLUME ((short)((0x00FF & _quicktime_volume) << 1)) |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
190 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
191 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
192 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
193 |
* Initialized the MIDI player, including QuickTime initialization. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
194 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
195 |
* @todo Give better error messages by inspecting error codes returned by |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
196 |
* @c Gestalt() and @c EnterMovies(). Needs changes in |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
197 |
* #InitQuickTimeIfNeeded. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
198 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
199 |
const char *MusicDriver_QtMidi::Start(const char * const *parm) |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
200 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
201 |
InitQuickTimeIfNeeded(); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
202 |
return (_quicktime_started) ? NULL : "can't initialize QuickTime"; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
203 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
204 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
205 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
206 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
207 |
* Checks wether the player is active. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
208 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
209 |
* This function is called at regular intervals from OpenTTD's main loop, so |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
210 |
* we call @c MoviesTask() from here to let QuickTime do its work. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
211 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
212 |
bool MusicDriver_QtMidi::IsSongPlaying() |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
213 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
214 |
if (!_quicktime_started) return true; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
215 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
216 |
switch (_quicktime_state) { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
217 |
case QT_STATE_IDLE: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
218 |
case QT_STATE_STOP: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
219 |
/* Do nothing. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
220 |
break; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
221 |
case QT_STATE_PLAY: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
222 |
MoviesTask(_quicktime_movie, 0); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
223 |
/* Check wether movie ended. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
224 |
if (IsMovieDone(_quicktime_movie) || |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
225 |
(GetMovieTime(_quicktime_movie, NULL) >= |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
226 |
GetMovieDuration(_quicktime_movie))) |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
227 |
_quicktime_state = QT_STATE_STOP; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
228 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
229 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3970
diff
changeset
|
230 |
return _quicktime_state == QT_STATE_PLAY; |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
231 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
232 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
233 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
234 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
235 |
* Stops the MIDI player. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
236 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
237 |
* Stops playing and frees any used resources before returning. As it |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
238 |
* deinitilizes QuickTime, the #_quicktime_started flag is set to @c false. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
239 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
240 |
void MusicDriver_QtMidi::Stop() |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
241 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
242 |
if (!_quicktime_started) return; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
243 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
244 |
DEBUG(driver, 2, "qtmidi: stopping driver..."); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
245 |
switch (_quicktime_state) { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
246 |
case QT_STATE_IDLE: |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
247 |
DEBUG(driver, 3, "qtmidi: stopping not needed, already idle"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
248 |
/* Do nothing. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
249 |
break; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
250 |
case QT_STATE_PLAY: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
251 |
StopSong(); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
252 |
case QT_STATE_STOP: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
253 |
DisposeMovie(_quicktime_movie); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
254 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
255 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
256 |
ExitMovies(); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
257 |
_quicktime_started = false; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
258 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
259 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
260 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
261 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
262 |
* Starts playing a new song. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
263 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
264 |
* @param filename Path to a MIDI file. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
265 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
266 |
void MusicDriver_QtMidi::PlaySong(const char *filename) |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
267 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
268 |
if (!_quicktime_started) return; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
269 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
270 |
DEBUG(driver, 2, "qtmidi: trying to play '%s'", filename); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
271 |
switch (_quicktime_state) { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
272 |
case QT_STATE_PLAY: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
273 |
StopSong(); |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
274 |
DEBUG(driver, 3, "qtmidi: previous tune stopped"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
275 |
/* XXX Fall-through -- no break needed. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
276 |
case QT_STATE_STOP: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
277 |
DisposeMovie(_quicktime_movie); |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
278 |
DEBUG(driver, 3, "qtmidi: previous tune disposed"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
279 |
_quicktime_state = QT_STATE_IDLE; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
280 |
/* XXX Fall-through -- no break needed. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
281 |
case QT_STATE_IDLE: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
282 |
LoadMovieForMIDIFile(filename, &_quicktime_movie); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
283 |
SetMovieVolume(_quicktime_movie, VOLUME); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
284 |
StartMovie(_quicktime_movie); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
285 |
_quicktime_state = QT_STATE_PLAY; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
286 |
} |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
287 |
DEBUG(driver, 3, "qtmidi: playing '%s'", filename); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
288 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
289 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
290 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
291 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
292 |
* Stops playing the current song, if the player is active. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
293 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
294 |
void MusicDriver_QtMidi::StopSong() |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
295 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
296 |
if (!_quicktime_started) return; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
297 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
298 |
switch (_quicktime_state) { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
299 |
case QT_STATE_IDLE: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
300 |
/* XXX Fall-through -- no break needed. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
301 |
case QT_STATE_STOP: |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
302 |
DEBUG(driver, 3, "qtmidi: stop requested, but already idle"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
303 |
/* Do nothing. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
304 |
break; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
305 |
case QT_STATE_PLAY: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
306 |
StopMovie(_quicktime_movie); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
307 |
_quicktime_state = QT_STATE_STOP; |
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
308 |
DEBUG(driver, 3, "qtmidi: player stopped"); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
309 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
310 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
311 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
312 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
313 |
/** |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
314 |
* Changes the playing volume of the MIDI player. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
315 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
316 |
* As QuickTime controls volume in a per-movie basis, the desired volume is |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
317 |
* stored in #_quicktime_volume, and the volume is set here using the |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
318 |
* #VOLUME macro, @b and when loading new song in #PlaySong. |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
319 |
* |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
320 |
* @param vol The desired volume, range of the value is @c 0-127 |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
321 |
*/ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
322 |
void MusicDriver_QtMidi::SetVolume(byte vol) |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
323 |
{ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
324 |
if (!_quicktime_started) return; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
325 |
|
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
326 |
_quicktime_volume = vol; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
327 |
|
5388
db011d108caa
(svn r7577) -Fix (r7565): Missed out some OSX files (Bjarni)
Darkvater
parents:
4000
diff
changeset
|
328 |
DEBUG(driver, 2, "qtmidi: set volume to %u (%hi)", vol, VOLUME); |
2496
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
329 |
switch (_quicktime_state) { |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
330 |
case QT_STATE_IDLE: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
331 |
/* Do nothing. */ |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
332 |
break; |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
333 |
case QT_STATE_PLAY: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
334 |
case QT_STATE_STOP: |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
335 |
SetMovieVolume(_quicktime_movie, VOLUME); |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
336 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
337 |
} |
74c42595f8e8
(svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents:
diff
changeset
|
338 |