12 #include "../stdafx.h" 
   14 #include "../string_func.h" 
   15 #include "../sound/sound_driver.hpp" 
   16 #include "../video/video_driver.hpp" 
   17 #include "../gfx_func.h" 
   20 #include <sys/types.h> 
   27 #include "../safeguards.h" 
   29 #ifndef EXTERNAL_PLAYER 
   31 #define EXTERNAL_PLAYER "timidity" 
   41     return "the extmidi driver does not work when Allegro is loaded.";
 
   47   this->command = 
stredup(command);
 
   74   if (this->pid != -1 && waitpid(this->pid, NULL, WNOHANG) == this->pid) {
 
   77   if (this->pid == -1 && this->song[0] != 
'\0') this->DoPlay();
 
   78   return this->pid != -1;
 
   83   DEBUG(driver, 1, 
"extmidi: set volume not implemented");
 
   86 void MusicDriver_ExtMidi::DoPlay()
 
   92       int d = open(
"/dev/null", O_RDONLY);
 
   93       if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
 
   95           execlp(this->command, 
"extmidi", MIDI_ARG, this->song, (
char*)0);
 
   97           execlp(this->command, 
"extmidi", this->song, (
char*)0);
 
  104       DEBUG(driver, 0, 
"extmidi: couldn't fork: %s", strerror(errno));
 
  108       this->song[0] = 
'\0';
 
  113 void MusicDriver_ExtMidi::DoStop()
 
  115   if (this->pid <= 0) 
return;
 
  119   for (
int i = 0; i < 500; i++) {
 
  120     kill(this->pid, SIGTERM);
 
  121     if (waitpid(this->pid, NULL, WNOHANG) == this->pid) {
 
  130   DEBUG(driver, 0, 
"extmidi: gracefully stopping failed, trying the hard way");
 
  133   kill(this->pid, SIGKILL);
 
  134   waitpid(this->pid, NULL, 0);