equal
deleted
inserted
replaced
44 #include <unistd.h> |
44 #include <unistd.h> |
45 #include <fcntl.h> |
45 #include <fcntl.h> |
46 |
46 |
47 // we need to include debug.h after CoreServices because defining DEBUG will break CoreServices in OSX 10.2 |
47 // we need to include debug.h after CoreServices because defining DEBUG will break CoreServices in OSX 10.2 |
48 #include "../debug.h" |
48 #include "../debug.h" |
|
49 |
|
50 static FMusicDriver_QtMidi iFMusicDriver_QtMidi; |
49 |
51 |
50 |
52 |
51 enum { |
53 enum { |
52 midiType = 'Midi' /**< OSType code for MIDI songs. */ |
54 midiType = 'Midi' /**< OSType code for MIDI songs. */ |
53 }; |
55 }; |
205 * Maps OpenTTD volume to QuickTime notion of volume. |
207 * Maps OpenTTD volume to QuickTime notion of volume. |
206 */ |
208 */ |
207 #define VOLUME ((short)((0x00FF & _quicktime_volume) << 1)) |
209 #define VOLUME ((short)((0x00FF & _quicktime_volume) << 1)) |
208 |
210 |
209 |
211 |
210 static void StopSong(); |
|
211 |
|
212 |
|
213 /** |
212 /** |
214 * Initialized the MIDI player, including QuickTime initialization. |
213 * Initialized the MIDI player, including QuickTime initialization. |
215 * |
214 * |
216 * @todo Give better error messages by inspecting error codes returned by |
215 * @todo Give better error messages by inspecting error codes returned by |
217 * @c Gestalt() and @c EnterMovies(). Needs changes in |
216 * @c Gestalt() and @c EnterMovies(). Needs changes in |
218 * #InitQuickTimeIfNeeded. |
217 * #InitQuickTimeIfNeeded. |
219 */ |
218 */ |
220 static const char* StartDriver(const char * const *parm) |
219 const char *MusicDriver_QtMidi::Start(const char * const *parm) |
221 { |
220 { |
222 InitQuickTimeIfNeeded(); |
221 InitQuickTimeIfNeeded(); |
223 return (_quicktime_started) ? NULL : "can't initialize QuickTime"; |
222 return (_quicktime_started) ? NULL : "can't initialize QuickTime"; |
224 } |
223 } |
225 |
224 |
228 * Checks wether the player is active. |
227 * Checks wether the player is active. |
229 * |
228 * |
230 * This function is called at regular intervals from OpenTTD's main loop, so |
229 * This function is called at regular intervals from OpenTTD's main loop, so |
231 * we call @c MoviesTask() from here to let QuickTime do its work. |
230 * we call @c MoviesTask() from here to let QuickTime do its work. |
232 */ |
231 */ |
233 static bool SongIsPlaying() |
232 bool MusicDriver_QtMidi::IsSongPlaying() |
234 { |
233 { |
235 if (!_quicktime_started) return true; |
234 if (!_quicktime_started) return true; |
236 |
235 |
237 switch (_quicktime_state) { |
236 switch (_quicktime_state) { |
238 case QT_STATE_IDLE: |
237 case QT_STATE_IDLE: |
256 * Stops the MIDI player. |
255 * Stops the MIDI player. |
257 * |
256 * |
258 * Stops playing and frees any used resources before returning. As it |
257 * Stops playing and frees any used resources before returning. As it |
259 * deinitilizes QuickTime, the #_quicktime_started flag is set to @c false. |
258 * deinitilizes QuickTime, the #_quicktime_started flag is set to @c false. |
260 */ |
259 */ |
261 static void StopDriver() |
260 void MusicDriver_QtMidi::Stop() |
262 { |
261 { |
263 if (!_quicktime_started) return; |
262 if (!_quicktime_started) return; |
264 |
263 |
265 DEBUG(driver, 2, "qtmidi: stopping driver..."); |
264 DEBUG(driver, 2, "qtmidi: stopping driver..."); |
266 switch (_quicktime_state) { |
265 switch (_quicktime_state) { |
282 /** |
281 /** |
283 * Starts playing a new song. |
282 * Starts playing a new song. |
284 * |
283 * |
285 * @param filename Path to a MIDI file. |
284 * @param filename Path to a MIDI file. |
286 */ |
285 */ |
287 static void PlaySong(const char *filename) |
286 void MusicDriver_QtMidi::PlaySong(const char *filename) |
288 { |
287 { |
289 if (!_quicktime_started) return; |
288 if (!_quicktime_started) return; |
290 |
289 |
291 DEBUG(driver, 2, "qtmidi: trying to play '%s'", filename); |
290 DEBUG(driver, 2, "qtmidi: trying to play '%s'", filename); |
292 switch (_quicktime_state) { |
291 switch (_quicktime_state) { |
310 |
309 |
311 |
310 |
312 /** |
311 /** |
313 * Stops playing the current song, if the player is active. |
312 * Stops playing the current song, if the player is active. |
314 */ |
313 */ |
315 static void StopSong() |
314 void MusicDriver_QtMidi::StopSong() |
316 { |
315 { |
317 if (!_quicktime_started) return; |
316 if (!_quicktime_started) return; |
318 |
317 |
319 switch (_quicktime_state) { |
318 switch (_quicktime_state) { |
320 case QT_STATE_IDLE: |
319 case QT_STATE_IDLE: |
338 * stored in #_quicktime_volume, and the volume is set here using the |
337 * stored in #_quicktime_volume, and the volume is set here using the |
339 * #VOLUME macro, @b and when loading new song in #PlaySong. |
338 * #VOLUME macro, @b and when loading new song in #PlaySong. |
340 * |
339 * |
341 * @param vol The desired volume, range of the value is @c 0-127 |
340 * @param vol The desired volume, range of the value is @c 0-127 |
342 */ |
341 */ |
343 static void SetVolume(byte vol) |
342 void MusicDriver_QtMidi::SetVolume(byte vol) |
344 { |
343 { |
345 if (!_quicktime_started) return; |
344 if (!_quicktime_started) return; |
346 |
345 |
347 _quicktime_volume = vol; |
346 _quicktime_volume = vol; |
348 |
347 |
355 case QT_STATE_STOP: |
354 case QT_STATE_STOP: |
356 SetMovieVolume(_quicktime_movie, VOLUME); |
355 SetMovieVolume(_quicktime_movie, VOLUME); |
357 } |
356 } |
358 } |
357 } |
359 |
358 |
360 |
|
361 /** |
|
362 * Table of callbacks that implement the QuickTime MIDI player. |
|
363 */ |
|
364 const HalMusicDriver _qtime_music_driver = { |
|
365 StartDriver, |
|
366 StopDriver, |
|
367 PlaySong, |
|
368 StopSong, |
|
369 SongIsPlaying, |
|
370 SetVolume, |
|
371 }; |
|