truelight@0: #ifndef __BEOS__ truelight@0: #ifndef __MORPHOS__ truelight@0: #include "stdafx.h" truelight@0: truelight@0: #include "ttd.h" truelight@0: #include "hal.h" pasky@1584: #include "sound.h" tron@1608: #include "string.h" tron@1608: #include truelight@0: #include truelight@0: #include truelight@0: #include truelight@0: #include truelight@0: #include truelight@0: #include truelight@0: tron@1608: static struct { tron@1608: char song[MAX_PATH]; tron@1608: int pid; tron@1608: } _midi; truelight@0: tron@1608: static void DoPlay(void); tron@1608: static void DoStop(void); tron@1608: tron@1608: static const char* ExtMidiStart(const char* const * parm) tron@342: { tron@1608: _midi.song[0] = '\0'; tron@1608: _midi.pid = -1; tron@342: return NULL; truelight@0: } truelight@0: tron@1608: static void ExtMidiStop(void) tron@342: { tron@1608: _midi.song[0] = '\0'; tron@1608: DoStop(); truelight@0: } truelight@0: tron@1608: static void ExtMidiPlaySong(const char* filename) tron@342: { tron@1608: ttd_strlcpy(_midi.song, filename, lengthof(_midi.song)); tron@1608: DoStop(); truelight@0: } truelight@0: tron@1608: static void ExtMidiStopSong(void) tron@342: { tron@1608: _midi.song[0] = '\0'; tron@1608: DoStop(); tron@342: } tron@342: tron@1608: static bool ExtMidiIsPlaying(void) tron@342: { tron@1608: if (_midi.pid != -1 && waitpid(_midi.pid, NULL, WNOHANG) == _midi.pid) tron@1608: _midi.pid = -1; tron@1608: if (_midi.pid == -1 && _midi.song[0] != '\0') DoPlay(); tron@1608: return _midi.pid != -1; tron@342: } tron@342: tron@1608: static void ExtMidiSetVolume(byte vol) tron@342: { tron@342: fprintf(stderr, "extmidi: set volume not implemented\n"); truelight@0: } truelight@0: tron@1608: static void DoPlay(void) tron@1608: { tron@1608: _midi.pid = fork(); tron@1608: switch (_midi.pid) { tron@1608: case 0: { tron@1608: int d; tron@1608: tron@1608: close(0); tron@1608: close(1); tron@1608: close(2); tron@1608: d = open("/dev/null", O_RDONLY); tron@1608: if (d != -1) { tron@1608: if (dup2(d, 1) != -1 && dup2(d, 2) != -1) { tron@1608: #if defined(MIDI_ARG) tron@1608: execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, NULL); tron@1608: #else tron@1608: execlp(msf.extmidi, "extmidi", _midi.song, NULL); tron@1608: #endif tron@1608: } tron@1608: } tron@1608: exit(1); tron@1608: } tron@1608: tron@1608: case -1: tron@1608: fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno)); tron@1608: /* FALLTHROUGH */ tron@1608: tron@1608: default: tron@1608: _midi.song[0] = '\0'; tron@1608: break; tron@1608: } tron@1608: } tron@1608: tron@1608: static void DoStop(void) tron@1608: { tron@1608: if (_midi.pid != -1) kill(_midi.pid, SIGTERM); tron@1608: } tron@1608: truelight@0: const HalMusicDriver _extmidi_music_driver = { tron@1608: ExtMidiStart, tron@1608: ExtMidiStop, tron@1608: ExtMidiPlaySong, tron@1608: ExtMidiStopSong, tron@1608: ExtMidiIsPlaying, tron@1608: ExtMidiSetVolume, truelight@0: }; tron@342: truelight@0: #endif /* __MORPHOS__ */ truelight@0: #endif /* __BEOS__ */