author | tron |
Wed, 30 Mar 2005 19:52:26 +0000 | |
changeset 1608 | 70a3c1a6576d |
parent 1584 | 7122e759d56c |
child 1892 | 8717d92b32b1 |
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" |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
8 |
#include "string.h" |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
9 |
#include <fcntl.h> |
0 | 10 |
#include <sys/types.h> |
11 |
#include <sys/wait.h> |
|
12 |
#include <unistd.h> |
|
13 |
#include <signal.h> |
|
14 |
#include <sys/stat.h> |
|
15 |
#include <errno.h> |
|
16 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
17 |
static struct { |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
18 |
char song[MAX_PATH]; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
19 |
int pid; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
20 |
} _midi; |
0 | 21 |
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
22 |
static void DoPlay(void); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
23 |
static void DoStop(void); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
24 |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
25 |
static const char* ExtMidiStart(const char* const * parm) |
342 | 26 |
{ |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
27 |
_midi.song[0] = '\0'; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
28 |
_midi.pid = -1; |
342 | 29 |
return NULL; |
0 | 30 |
} |
31 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
32 |
static void ExtMidiStop(void) |
342 | 33 |
{ |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
34 |
_midi.song[0] = '\0'; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
35 |
DoStop(); |
0 | 36 |
} |
37 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
38 |
static void ExtMidiPlaySong(const char* filename) |
342 | 39 |
{ |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
40 |
ttd_strlcpy(_midi.song, filename, lengthof(_midi.song)); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
41 |
DoStop(); |
0 | 42 |
} |
43 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
44 |
static void ExtMidiStopSong(void) |
342 | 45 |
{ |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
46 |
_midi.song[0] = '\0'; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
47 |
DoStop(); |
342 | 48 |
} |
49 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
50 |
static bool ExtMidiIsPlaying(void) |
342 | 51 |
{ |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
52 |
if (_midi.pid != -1 && waitpid(_midi.pid, NULL, WNOHANG) == _midi.pid) |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
53 |
_midi.pid = -1; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
54 |
if (_midi.pid == -1 && _midi.song[0] != '\0') DoPlay(); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
55 |
return _midi.pid != -1; |
342 | 56 |
} |
57 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
58 |
static void ExtMidiSetVolume(byte vol) |
342 | 59 |
{ |
60 |
fprintf(stderr, "extmidi: set volume not implemented\n"); |
|
0 | 61 |
} |
62 |
||
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
63 |
static void DoPlay(void) |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
64 |
{ |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
65 |
_midi.pid = fork(); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
66 |
switch (_midi.pid) { |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
67 |
case 0: { |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
68 |
int d; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
69 |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
70 |
close(0); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
71 |
close(1); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
72 |
close(2); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
73 |
d = open("/dev/null", O_RDONLY); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
74 |
if (d != -1) { |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
75 |
if (dup2(d, 1) != -1 && dup2(d, 2) != -1) { |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
76 |
#if defined(MIDI_ARG) |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
77 |
execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, NULL); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
78 |
#else |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
79 |
execlp(msf.extmidi, "extmidi", _midi.song, NULL); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
80 |
#endif |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
81 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
82 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
83 |
exit(1); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
84 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
85 |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
86 |
case -1: |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
87 |
fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno)); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
88 |
/* FALLTHROUGH */ |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
89 |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
90 |
default: |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
91 |
_midi.song[0] = '\0'; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
92 |
break; |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
93 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
94 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
95 |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
96 |
static void DoStop(void) |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
97 |
{ |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
98 |
if (_midi.pid != -1) kill(_midi.pid, SIGTERM); |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
99 |
} |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
100 |
|
0 | 101 |
const HalMusicDriver _extmidi_music_driver = { |
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
102 |
ExtMidiStart, |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
103 |
ExtMidiStop, |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
104 |
ExtMidiPlaySong, |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
105 |
ExtMidiStopSong, |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
106 |
ExtMidiIsPlaying, |
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
107 |
ExtMidiSetVolume, |
0 | 108 |
}; |
342 | 109 |
|
0 | 110 |
#endif /* __MORPHOS__ */ |
111 |
#endif /* __BEOS__ */ |