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 "../thread.h" 22 #include "midifile.hpp" 24 #include <sys/types.h> 31 #include "../safeguards.h" 33 #ifndef EXTERNAL_PLAYER 35 #define EXTERNAL_PLAYER "timidity" 45 return "the extmidi driver does not work when Allegro is loaded.";
57 for (
const char *t = command; *t !=
'\0'; t++)
if (*t ==
' ') num_args++;
59 this->params = CallocT<char *>(num_args);
60 this->params[0] =
stredup(command);
65 this->params[p] = strchr(this->params[p - 1],
' ');
66 if (this->params[p] ==
nullptr)
break;
68 this->params[p][0] =
'\0';
74 this->params[p] = this->song;
92 if (!filename.empty()) {
100 this->song[0] =
'\0';
106 if (this->pid != -1 && waitpid(this->pid,
nullptr, WNOHANG) == this->pid) {
109 if (this->pid == -1 && this->song[0] !=
'\0') this->DoPlay();
110 return this->pid != -1;
115 DEBUG(driver, 1,
"extmidi: set volume not implemented");
118 void MusicDriver_ExtMidi::DoPlay()
124 int d = open(
"/dev/null", O_RDONLY);
125 if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
126 execvp(this->params[0], this->params);
132 DEBUG(driver, 0,
"extmidi: couldn't fork: %s", strerror(errno));
136 this->song[0] =
'\0';
141 void MusicDriver_ExtMidi::DoStop()
143 if (this->pid <= 0)
return;
147 for (
int i = 0; i < 500; i++) {
148 kill(this->pid, SIGTERM);
149 if (waitpid(this->pid,
nullptr, WNOHANG) == this->pid) {
158 DEBUG(driver, 0,
"extmidi: gracefully stopping failed, trying the hard way");
161 kill(this->pid, SIGKILL);
162 waitpid(this->pid,
nullptr, 0);
const char * GetDriverParam(const char *const *parm, const char *name)
Get a string parameter the list of parameters.
Metadata about a music track.
const char * Start(const char *const *param) override
Start this driver.
void SetVolume(byte vol) override
Set the volume, if possible.
#define EXTERNAL_PLAYER
The default external midi player.
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
#define lastof(x)
Get the last element of an fixed size array.
void StopSong() override
Stop playing the current song.
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi
Factory for the midi player that uses external players.
void PlaySong(const MusicSongInfo &song) override
Play a particular song.
void Stop() override
Stop 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.
const char * GetName() const override
Get the name of this driver.
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.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool IsSongPlaying() override
Are we currently playing a song?