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