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" 20 #include "../base_media_base.h" 21 #include "midifile.hpp" 23 #include <sys/types.h> 30 #include "../safeguards.h" 32 #ifndef EXTERNAL_PLAYER 34 #define EXTERNAL_PLAYER "timidity" 44 return "the extmidi driver does not work when Allegro is loaded.";
56 for (
const char *t = command; *t !=
'\0'; t++)
if (*t ==
' ') num_args++;
58 this->params = CallocT<char *>(num_args);
59 this->params[0] =
stredup(command);
64 this->params[p] = strchr(this->params[p - 1],
' ');
65 if (this->params[p] == NULL)
break;
67 this->params[p][0] =
'\0';
73 this->params[p] = this->song;
91 if (!filename.empty()) {
105 if (this->pid != -1 && waitpid(this->pid, NULL, WNOHANG) == this->pid) {
108 if (this->pid == -1 && this->song[0] !=
'\0') this->DoPlay();
109 return this->pid != -1;
114 DEBUG(driver, 1,
"extmidi: set volume not implemented");
117 void MusicDriver_ExtMidi::DoPlay()
123 int d = open(
"/dev/null", O_RDONLY);
124 if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
125 execvp(this->params[0], this->params);
131 DEBUG(driver, 0,
"extmidi: couldn't fork: %s", strerror(errno));
135 this->song[0] =
'\0';
140 void MusicDriver_ExtMidi::DoStop()
142 if (this->pid <= 0)
return;
146 for (
int i = 0; i < 500; i++) {
147 kill(this->pid, SIGTERM);
148 if (waitpid(this->pid, NULL, WNOHANG) == this->pid) {
157 DEBUG(driver, 0,
"extmidi: gracefully stopping failed, trying the hard way");
160 kill(this->pid, SIGKILL);
161 waitpid(this->pid, NULL, 0);
const char * GetDriverParam(const char *const *parm, const char *name)
Get a string parameter the list of parameters.
Metadata about a music track.
#define EXTERNAL_PLAYER
The default external midi player.
void PlaySong(const MusicSongInfo &song)
Play a particular song.
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.
#define DEBUG(name, level,...)
Output a line of debugging information.
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
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.