Codechange: Pass a MusicSongInfo struct instead of bare filename to music drivers.
Preparation for later extending the info passed to music drivers.
This commit is contained in:

committed by
Michael Lutz

parent
1c2d29e1a3
commit
f946b3da56
@@ -58,10 +58,12 @@ void MusicDriver_Allegro::Stop()
|
||||
if (--_allegro_instance_count == 0) allegro_exit();
|
||||
}
|
||||
|
||||
void MusicDriver_Allegro::PlaySong(const char *filename)
|
||||
void MusicDriver_Allegro::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
if (_midi != NULL) destroy_midi(_midi);
|
||||
_midi = load_midi(filename);
|
||||
_midi = load_midi(song.filename);
|
||||
play_midi(_midi, false);
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../openttd.h"
|
||||
#include "bemidi.h"
|
||||
#include "../base_media_base.h"
|
||||
|
||||
/* BeOS System Includes */
|
||||
#include <MidiSynthFile.h>
|
||||
@@ -34,11 +35,13 @@ void MusicDriver_BeMidi::Stop()
|
||||
midiSynthFile.UnloadFile();
|
||||
}
|
||||
|
||||
void MusicDriver_BeMidi::PlaySong(const char *filename)
|
||||
void MusicDriver_BeMidi::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
this->Stop();
|
||||
entry_ref midiRef;
|
||||
get_ref_for_path(filename, &midiRef);
|
||||
get_ref_for_path(song.filename, &midiRef);
|
||||
midiSynthFile.LoadFile(&midiRef);
|
||||
midiSynthFile.Start();
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "../os/macosx/macos.h"
|
||||
#include "cocoa_m.h"
|
||||
#include "../debug.h"
|
||||
#include "../base_media_base.h"
|
||||
|
||||
#define Rect OTTDRect
|
||||
#define Point OTTDPoint
|
||||
@@ -143,8 +144,10 @@ void MusicDriver_Cocoa::Stop()
|
||||
*
|
||||
* @param filename Path to a MIDI file.
|
||||
*/
|
||||
void MusicDriver_Cocoa::PlaySong(const char *filename)
|
||||
void MusicDriver_Cocoa::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
DEBUG(driver, 2, "cocoa_m: trying to play '%s'", filename);
|
||||
|
||||
this->StopSong();
|
||||
@@ -158,7 +161,7 @@ void MusicDriver_Cocoa::PlaySong(const char *filename)
|
||||
return;
|
||||
}
|
||||
|
||||
const char *os_file = OTTD2FS(filename);
|
||||
const char *os_file = OTTD2FS(song.filename);
|
||||
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)os_file, strlen(os_file), false);
|
||||
|
||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
|
||||
|
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "../core/mem_func.hpp"
|
||||
#include "../thread/thread.h"
|
||||
#include "../fileio_func.h"
|
||||
#include "../base_media_base.h"
|
||||
#include "dmusic.h"
|
||||
#include "midifile.hpp"
|
||||
#include "midi.h"
|
||||
@@ -1225,11 +1226,13 @@ void MusicDriver_DMusic::Stop()
|
||||
}
|
||||
|
||||
|
||||
void MusicDriver_DMusic::PlaySong(const char *filename)
|
||||
void MusicDriver_DMusic::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
ThreadMutexLocker lock(_thread_mutex);
|
||||
|
||||
_playback.next_file.LoadFile(filename);
|
||||
_playback.next_file.LoadFile(song.filename);
|
||||
_playback.next_segment.start = 0;
|
||||
_playback.next_segment.end = 0;
|
||||
_playback.next_segment.loop = false;
|
||||
|
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "../video/video_driver.hpp"
|
||||
#include "../gfx_func.h"
|
||||
#include "extmidi.h"
|
||||
#include "../base_media_base.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -83,9 +84,11 @@ void MusicDriver_ExtMidi::Stop()
|
||||
this->DoStop();
|
||||
}
|
||||
|
||||
void MusicDriver_ExtMidi::PlaySong(const char *filename)
|
||||
void MusicDriver_ExtMidi::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
strecpy(this->song, filename, lastof(this->song));
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
strecpy(this->song, song.filename, lastof(this->song));
|
||||
this->DoStop();
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "../sound_type.h"
|
||||
#include "../debug.h"
|
||||
#include "libtimidity.h"
|
||||
#include "../base_media_base.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -73,11 +74,13 @@ void MusicDriver_LibTimidity::Stop()
|
||||
mid_exit();
|
||||
}
|
||||
|
||||
void MusicDriver_LibTimidity::PlaySong(const char *filename)
|
||||
void MusicDriver_LibTimidity::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
this->StopSong();
|
||||
|
||||
_midi.stream = mid_istream_open_file(filename);
|
||||
_midi.stream = mid_istream_open_file(song.filename);
|
||||
if (_midi.stream == NULL) {
|
||||
DEBUG(driver, 0, "Could not open music file");
|
||||
return;
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "../driver.h"
|
||||
|
||||
struct MusicSongInfo;
|
||||
|
||||
/** Driver for all music playback. */
|
||||
class MusicDriver : public Driver {
|
||||
public:
|
||||
@@ -21,7 +23,7 @@ public:
|
||||
* Play a particular song.
|
||||
* @param filename The name of file with the song to play.
|
||||
*/
|
||||
virtual void PlaySong(const char *filename) = 0;
|
||||
virtual void PlaySong(const MusicSongInfo &song) = 0;
|
||||
|
||||
/**
|
||||
* Stop playing the current song.
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop() { }
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename) { }
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song) { }
|
||||
|
||||
/* virtual */ void StopSong() { }
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../openttd.h"
|
||||
#include "os2_m.h"
|
||||
#include "../base_media_base.h"
|
||||
|
||||
#define INCL_DOS
|
||||
#define INCL_OS2MM
|
||||
@@ -49,11 +50,13 @@ static long CDECL MidiSendCommand(const char *cmd, ...)
|
||||
/** OS/2's music player's factory. */
|
||||
static FMusicDriver_OS2 iFMusicDriver_OS2;
|
||||
|
||||
void MusicDriver_OS2::PlaySong(const char *filename)
|
||||
void MusicDriver_OS2::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
MidiSendCommand("close all");
|
||||
|
||||
if (MidiSendCommand("open %s type sequencer alias song", filename) != 0) {
|
||||
if (MidiSendCommand("open %s type sequencer alias song", song.filename) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "qtmidi.h"
|
||||
#include "../debug.h"
|
||||
#include "../base_media_base.h"
|
||||
|
||||
#define Rect OTTDRect
|
||||
#define Point OTTDPoint
|
||||
@@ -258,8 +259,9 @@ void MusicDriver_QtMidi::Stop()
|
||||
*
|
||||
* @param filename Path to a MIDI file.
|
||||
*/
|
||||
void MusicDriver_QtMidi::PlaySong(const char *filename)
|
||||
void MusicDriver_QtMidi::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
if (!_quicktime_started) return;
|
||||
|
||||
DEBUG(driver, 2, "qtmidi: trying to play '%s'", filename);
|
||||
@@ -276,7 +278,7 @@ void MusicDriver_QtMidi::PlaySong(const char *filename)
|
||||
FALLTHROUGH;
|
||||
|
||||
case QT_STATE_IDLE:
|
||||
LoadMovieForMIDIFile(filename, &_quicktime_movie);
|
||||
LoadMovieForMIDIFile(song.filename, &_quicktime_movie);
|
||||
SetMovieVolume(_quicktime_movie, VOLUME);
|
||||
StartMovie(_quicktime_movie);
|
||||
_quicktime_state = QT_STATE_PLAY;
|
||||
|
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "../debug.h"
|
||||
#include "midifile.hpp"
|
||||
#include "midi.h"
|
||||
#include "../base_media_base.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
@@ -304,12 +305,14 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW
|
||||
}
|
||||
}
|
||||
|
||||
void MusicDriver_Win32::PlaySong(const char *filename)
|
||||
void MusicDriver_Win32::PlaySong(const MusicSongInfo &song)
|
||||
{
|
||||
if (song.filetype != MTT_STANDARDMIDI) return;
|
||||
|
||||
DEBUG(driver, 2, "Win32-MIDI: PlaySong: entry");
|
||||
EnterCriticalSection(&_midi.lock);
|
||||
|
||||
_midi.next_file.LoadFile(filename);
|
||||
_midi.next_file.LoadFile(song.filename);
|
||||
_midi.next_segment.start = 0;
|
||||
_midi.next_segment.end = 0;
|
||||
_midi.next_segment.loop = false;
|
||||
|
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/* virtual */ void Stop();
|
||||
|
||||
/* virtual */ void PlaySong(const char *filename);
|
||||
/* virtual */ void PlaySong(const MusicSongInfo &song);
|
||||
|
||||
/* virtual */ void StopSong();
|
||||
|
||||
|
Reference in New Issue
Block a user