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