author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1301 | bf64ba5b6774 |
child 1584 | 7122e759d56c |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef __BEOS__ |
2 |
#ifndef __MORPHOS__ |
|
3 |
#include "stdafx.h" |
|
4 |
||
5 |
#include "ttd.h" |
|
6 |
#include "hal.h" |
|
7 |
#include <sys/types.h> |
|
8 |
#include <sys/wait.h> |
|
9 |
#include <unistd.h> |
|
10 |
#include <signal.h> |
|
11 |
#include <sys/stat.h> |
|
12 |
#include <errno.h> |
|
13 |
||
14 |
#ifndef EXTERNAL_PLAYER |
|
342 | 15 |
#define EXTERNAL_PLAYER "timidity" |
0 | 16 |
#endif |
17 |
||
18 |
static pid_t _pid; |
|
19 |
||
342 | 20 |
static void extmidi_kill(void) |
21 |
{ |
|
22 |
if (_pid > 0) { |
|
23 |
kill(_pid, SIGKILL); |
|
24 |
while (waitpid(_pid, NULL, WNOHANG) != _pid); |
|
25 |
} |
|
26 |
_pid = 0; |
|
0 | 27 |
} |
28 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
342
diff
changeset
|
29 |
static const char *extmidi_start(const char * const *parm) |
342 | 30 |
{ |
31 |
_pid = 0; |
|
32 |
return NULL; |
|
0 | 33 |
} |
34 |
||
342 | 35 |
static void extmidi_stop(void) |
36 |
{ |
|
37 |
extmidi_kill(); |
|
0 | 38 |
} |
39 |
||
342 | 40 |
static void extmidi_play_song(const char *filename) |
41 |
{ |
|
42 |
extmidi_kill(); |
|
0 | 43 |
|
342 | 44 |
_pid = fork(); |
45 |
if (_pid < 0) { |
|
46 |
fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno)); |
|
47 |
_pid = 0; |
|
48 |
return; |
|
49 |
} |
|
0 | 50 |
|
342 | 51 |
if (_pid == 0) { |
52 |
#if defined(MIDI_ARG) |
|
53 |
execlp(EXTERNAL_PLAYER, "extmidi", MIDI_ARG, filename, NULL); |
|
54 |
#else |
|
55 |
execlp(EXTERNAL_PLAYER, "extmidi", filename, NULL); |
|
56 |
#endif |
|
57 |
fprintf(stderr, "extmidi: couldn't execl: %s\n", strerror(errno)); |
|
58 |
exit(0); |
|
59 |
} |
|
60 |
||
61 |
usleep(500); |
|
62 |
||
63 |
if (_pid == waitpid(_pid, NULL, WNOHANG)) { |
|
64 |
fprintf(stderr, "extmidi: play song failed\n"); |
|
65 |
_pid = 0; |
|
66 |
||
67 |
usleep(5000); |
|
68 |
} |
|
0 | 69 |
} |
70 |
||
342 | 71 |
static void extmidi_stop_song(void) |
72 |
{ |
|
73 |
extmidi_kill(); |
|
74 |
} |
|
75 |
||
76 |
static bool extmidi_is_playing(void) |
|
77 |
{ |
|
78 |
if (_pid == 0) |
|
79 |
return 0; |
|
80 |
||
81 |
if (waitpid(_pid, NULL, WNOHANG) == _pid) { |
|
82 |
_pid = 0; |
|
83 |
return 0; |
|
84 |
} |
|
85 |
||
86 |
return 1; |
|
87 |
} |
|
88 |
||
89 |
static void extmidi_set_volume(byte vol) |
|
90 |
{ |
|
91 |
fprintf(stderr, "extmidi: set volume not implemented\n"); |
|
0 | 92 |
} |
93 |
||
94 |
const HalMusicDriver _extmidi_music_driver = { |
|
95 |
extmidi_start, |
|
96 |
extmidi_stop, |
|
97 |
extmidi_play_song, |
|
98 |
extmidi_stop_song, |
|
99 |
extmidi_is_playing, |
|
100 |
extmidi_set_volume, |
|
101 |
}; |
|
342 | 102 |
|
0 | 103 |
#endif /* __MORPHOS__ */ |
104 |
#endif /* __BEOS__ */ |