OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
12 #include "../string_func.h"
13 #include "../core/alloc_func.hpp"
14 #include "../sound/sound_driver.hpp"
15 #include "../video/video_driver.hpp"
16 #include "../gfx_func.h"
18 #include "../base_media_base.h"
19 #include "../thread.h"
20 #include "midifile.hpp"
22 #include <sys/types.h>
29 #include "../safeguards.h"
31 #ifndef EXTERNAL_PLAYER
33 #define EXTERNAL_PLAYER "timidity"
43 return "the extmidi driver does not work when Allegro is loaded.";
55 for (
const char *t = command; *t !=
'\0'; t++)
if (*t ==
' ') num_args++;
57 this->params = CallocT<char *>(num_args);
58 this->params[0] =
stredup(command);
63 this->params[p] = strchr(this->params[p - 1],
' ');
64 if (this->params[p] ==
nullptr)
break;
66 this->params[p][0] =
'\0';
72 this->params[p] = this->song;
90 if (!filename.empty()) {
104 if (this->pid != -1 && waitpid(this->pid,
nullptr, WNOHANG) == this->pid) {
107 if (this->pid == -1 && this->song[0] !=
'\0') this->DoPlay();
108 return this->pid != -1;
113 DEBUG(driver, 1,
"extmidi: set volume not implemented");
116 void MusicDriver_ExtMidi::DoPlay()
122 int d = open(
"/dev/null", O_RDONLY);
123 if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
124 execvp(this->params[0], this->params);
130 DEBUG(driver, 0,
"extmidi: couldn't fork: %s", strerror(errno));
134 this->song[0] =
'\0';
139 void MusicDriver_ExtMidi::DoStop()
141 if (this->pid <= 0)
return;
145 for (
int i = 0; i < 500; i++) {
146 kill(this->pid, SIGTERM);
147 if (waitpid(this->pid,
nullptr, WNOHANG) == this->pid) {
156 DEBUG(driver, 0,
"extmidi: gracefully stopping failed, trying the hard way");
159 kill(this->pid, SIGKILL);
160 waitpid(this->pid,
nullptr, 0);
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
const char * Start(const StringList ¶m) override
Start this driver.
void SetVolume(byte vol) override
Set the volume, if possible.
const char * GetDriverParam(const StringList &parm, const char *name)
Get a string parameter the list of parameters.
bool IsSongPlaying() override
Are we currently playing a song?
void PlaySong(const MusicSongInfo &song) override
Play a particular song.
#define DEBUG(name, level,...)
Output a line of debugging information.
Metadata about a music track.
std::vector< std::string > StringList
Type for a list of strings.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void StopSong() override
Stop playing the current song.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi
Factory for the midi player that uses external players.
void Stop() override
Stop this driver.
const char * GetName() const override
Get the name of this driver.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
#define EXTERNAL_PLAYER
The default external midi player.
#define lastof(x)
Get the last element of an fixed size array.