From 66bbf336c6af7353ef0aeed58002c46543b30635 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 2 Jan 2007 19:19:48 +0000 Subject: (svn r7759) -Merge: makefile rewrite. This merge features: - A proper ./configure, so everything needs to be configured only once, not for every make. - Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies. - A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC. - Proper support for OSX universal binaries. - Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files. - Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files. Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy. --- src/music/extmidi.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/music/extmidi.c (limited to 'src/music/extmidi.c') diff --git a/src/music/extmidi.c b/src/music/extmidi.c new file mode 100644 index 000000000..901fa4fd7 --- /dev/null +++ b/src/music/extmidi.c @@ -0,0 +1,108 @@ +/* $Id$ */ + +#ifndef __MORPHOS__ +#include "../stdafx.h" +#include "../openttd.h" +#include "../sound.h" +#include "../string.h" +#include "../variables.h" +#include "../debug.h" +#include "extmidi.h" +#include +#include +#include +#include +#include +#include +#include + +static struct { + char song[MAX_PATH]; + pid_t pid; +} _midi; + +static void DoPlay(void); +static void DoStop(void); + +static const char* ExtMidiStart(const char* const * parm) +{ + _midi.song[0] = '\0'; + _midi.pid = -1; + return NULL; +} + +static void ExtMidiStop(void) +{ + _midi.song[0] = '\0'; + DoStop(); +} + +static void ExtMidiPlaySong(const char* filename) +{ + ttd_strlcpy(_midi.song, filename, lengthof(_midi.song)); + DoStop(); +} + +static void ExtMidiStopSong(void) +{ + _midi.song[0] = '\0'; + DoStop(); +} + +static bool ExtMidiIsPlaying(void) +{ + if (_midi.pid != -1 && waitpid(_midi.pid, NULL, WNOHANG) == _midi.pid) + _midi.pid = -1; + if (_midi.pid == -1 && _midi.song[0] != '\0') DoPlay(); + return _midi.pid != -1; +} + +static void ExtMidiSetVolume(byte vol) +{ + DEBUG(driver, 1, "extmidi: set volume not implemented"); +} + +static void DoPlay(void) +{ + _midi.pid = fork(); + switch (_midi.pid) { + case 0: { + int d; + + close(0); + d = open("/dev/null", O_RDONLY); + if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) { + #if defined(MIDI_ARG) + execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, (char*)0); + #else + execlp(msf.extmidi, "extmidi", _midi.song, (char*)0); + #endif + } + _exit(1); + } + + case -1: + DEBUG(driver, 0, "extmidi: couldn't fork: %s", strerror(errno)); + /* FALLTHROUGH */ + + default: + _midi.song[0] = '\0'; + break; + } +} + +static void DoStop(void) +{ + if (_midi.pid != -1) kill(_midi.pid, SIGTERM); +} + +const HalMusicDriver _extmidi_music_driver = { + ExtMidiStart, + ExtMidiStop, + ExtMidiPlaySong, + ExtMidiStopSong, + ExtMidiIsPlaying, + ExtMidiSetVolume, +}; + +#endif /* __MORPHOS__ */ -- cgit v1.2.3-70-g09d2