12 #include "../stdafx.h" 14 #include "../string_func.h" 15 #include "../core/alloc_func.hpp" 16 #include "../sound/sound_driver.hpp" 17 #include "../video/video_driver.hpp" 18 #include "../gfx_func.h" 21 #include <sys/types.h> 28 #include "../safeguards.h" 30 #ifndef EXTERNAL_PLAYER 32 #define EXTERNAL_PLAYER "timidity" 42 return "the extmidi driver does not work when Allegro is loaded.";
54 for (
const char *t = command; *t !=
'\0'; t++)
if (*t ==
' ') num_args++;
56 this->params = CallocT<char *>(num_args);
57 this->params[0] =
stredup(command);
62 this->params[p] = strchr(this->params[p - 1],
' ');
63 if (this->params[p] == NULL)
break;
65 this->params[p][0] =
'\0';
71 this->params[p] = this->song;
100 if (this->pid != -1 && waitpid(this->pid, NULL, WNOHANG) == this->pid) {
103 if (this->pid == -1 && this->song[0] !=
'\0') this->DoPlay();
104 return this->pid != -1;
109 DEBUG(driver, 1,
"extmidi: set volume not implemented");
112 void MusicDriver_ExtMidi::DoPlay()
118 int d = open(
"/dev/null", O_RDONLY);
119 if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
120 execvp(this->params[0], this->params);
126 DEBUG(driver, 0,
"extmidi: couldn't fork: %s", strerror(errno));
130 this->song[0] =
'\0';
135 void MusicDriver_ExtMidi::DoStop()
137 if (this->pid <= 0)
return;
141 for (
int i = 0; i < 500; i++) {
142 kill(this->pid, SIGTERM);
143 if (waitpid(this->pid, NULL, WNOHANG) == this->pid) {
152 DEBUG(driver, 0,
"extmidi: gracefully stopping failed, trying the hard way");
155 kill(this->pid, SIGKILL);
156 waitpid(this->pid, NULL, 0);
const char * GetDriverParam(const char *const *parm, const char *name)
Get a string parameter the list of parameters.
#define EXTERNAL_PLAYER
The default external midi player.
bool IsSongPlaying()
Are we currently playing a song?
void StopSong()
Stop playing the current song.
void Stop()
Stop this driver.
#define lastof(x)
Get the last element of an fixed size array.
void SetVolume(byte vol)
Set the volume, if possible.
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi
Factory for the midi player that uses external players.
const char * GetName() const
Get the name of this driver.
Base support for playing music via an external application.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
void PlaySong(const char *filename)
Play a particular song.
#define DEBUG(name, level,...)
Output a line of debugging information.
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
const char * Start(const char *const *param)
Start this driver.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.