Changeset - r342:7bf7e37541c5
[Not reviewed]
master
0 1 0
tron - 20 years ago 2004-11-06 23:24:59
tron@openttd.org
(svn r518) Merge extmidi.c r441 to trunk:
- Whitespace cleanup
- Use execlp() with relative path instead of execl() with absolute path
1 file changed with 55 insertions and 54 deletions:
extmidi.c
55
54
0 comments (0 inline, 0 general)
extmidi.c
Show inline comments
 
@@ -12,83 +12,83 @@
 
#include <errno.h>
 

	
 
#ifndef EXTERNAL_PLAYER
 
#define EXTERNAL_PLAYER "/usr/bin/timidity"
 
#define EXTERNAL_PLAYER "timidity"
 
#endif
 

	
 
static pid_t _pid;
 

	
 
static void extmidi_kill(void) {
 
    if(_pid > 0) {
 
        kill(_pid, SIGKILL);
 
        while(waitpid(_pid, NULL, WNOHANG) != _pid);
 
    }
 
    _pid = 0;
 
static void extmidi_kill(void)
 
{
 
	if (_pid > 0) {
 
		kill(_pid, SIGKILL);
 
		while (waitpid(_pid, NULL, WNOHANG) != _pid);
 
	}
 
	_pid = 0;
 
}
 

	
 
static char *extmidi_start(char **parm) {
 
    _pid = 0;
 

	
 
    return NULL;
 
static char *extmidi_start(char **parm)
 
{
 
	_pid = 0;
 
	return NULL;
 
}
 

	
 
static void extmidi_stop(void) {
 
    extmidi_kill();
 
static void extmidi_stop(void)
 
{
 
	extmidi_kill();
 
}
 

	
 
static void extmidi_play_song(const char *filename) {
 
    extmidi_kill();
 
static void extmidi_play_song(const char *filename)
 
{
 
	extmidi_kill();
 

	
 
    _pid = fork();
 
    if(_pid < 0) {
 
        fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno));
 
        _pid = 0;
 
        return;
 
    }
 

	
 
    if(_pid == 0) {
 
        #if defined(MIDI_ARG)
 
			execl(EXTERNAL_PLAYER, "extmidi", MIDI_ARG, filename, NULL);
 
		#else
 
			execl(EXTERNAL_PLAYER, "extmidi", filename, NULL);
 
		#endif
 
	_pid = fork();
 
	if (_pid < 0) {
 
		fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno));
 
		_pid = 0;
 
		return;
 
	}
 

	
 
        fprintf(stderr, "extmidi: couldn't execl: %s\n", strerror(errno));
 

	
 
        exit(0);
 
    }
 

	
 

	
 

	
 
    usleep(500);
 
	if (_pid == 0) {
 
		#if defined(MIDI_ARG)
 
			execlp(EXTERNAL_PLAYER, "extmidi", MIDI_ARG, filename, NULL);
 
		#else
 
			execlp(EXTERNAL_PLAYER, "extmidi", filename, NULL);
 
		#endif
 
		fprintf(stderr, "extmidi: couldn't execl: %s\n", strerror(errno));
 
		exit(0);
 
	}
 

	
 
	usleep(500);
 

	
 
    if(_pid == waitpid(_pid, NULL, WNOHANG)) {
 
        fprintf(stderr, "extmidi: play song failed\n");
 
        _pid = 0;
 
	if (_pid == waitpid(_pid, NULL, WNOHANG)) {
 
		fprintf(stderr, "extmidi: play song failed\n");
 
		_pid = 0;
 

	
 
    usleep(5000);
 

	
 
    }
 
		usleep(5000);
 
	}
 
}
 

	
 
static void extmidi_stop_song(void) {
 
    extmidi_kill();
 
static void extmidi_stop_song(void)
 
{
 
	extmidi_kill();
 
}
 

	
 
static bool extmidi_is_playing(void) {
 
    if(_pid == 0)
 
        return 0;
 
static bool extmidi_is_playing(void)
 
{
 
	if (_pid == 0)
 
		return 0;
 

	
 
    if(waitpid(_pid, NULL, WNOHANG) == _pid) {
 
        _pid = 0;
 
        return 0;
 
    }
 
	if (waitpid(_pid, NULL, WNOHANG) == _pid) {
 
		_pid = 0;
 
		return 0;
 
	}
 

	
 
    return 1;
 
	return 1;
 
}
 

	
 
static void extmidi_set_volume(byte vol) {
 
    fprintf(stderr, "extmidi: set volume not implemented\n");
 
static void extmidi_set_volume(byte vol)
 
{
 
	fprintf(stderr, "extmidi: set volume not implemented\n");
 
}
 

	
 
const HalMusicDriver _extmidi_music_driver = {
 
@@ -99,5 +99,6 @@ const HalMusicDriver _extmidi_music_driv
 
	extmidi_is_playing,
 
	extmidi_set_volume,
 
};
 

	
 
#endif /* __MORPHOS__ */
 
#endif /* __BEOS__ */
0 comments (0 inline, 0 general)