author | peter1138 |
Thu, 05 Jul 2007 12:23:54 +0000 | |
changeset 7666 | a5fccd76176a |
parent 6573 | 7624f942237f |
child 7668 | 293aec8511ae |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#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
|
4 |
#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
|
5 |
#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
|
6 |
#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
|
7 |
#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
|
8 |
#include "../variables.h" |
3721
200e79fe4502
(svn r4692) - Use DEBUG() instead of direct fprintf in extmidi music driver, and silence 'set volume not implemented' warning at the default debug level.
peter1138
parents:
2458
diff
changeset
|
9 |
#include "../debug.h" |
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
|
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]; |
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2420
diff
changeset
|
21 |
pid_t pid; |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
22 |
} _midi; |
0 | 23 |
|
6573 | 24 |
static void DoPlay(); |
25 |
static void DoStop(); |
|
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
26 |
|
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
27 |
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi; |
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
28 |
|
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
29 |
const char* MusicDriver_ExtMidi::Start(const char* const * parm) |
342 | 30 |
{ |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
31 |
_midi.song[0] = '\0'; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
32 |
_midi.pid = -1; |
342 | 33 |
return NULL; |
0 | 34 |
} |
35 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
36 |
void MusicDriver_ExtMidi::Stop() |
342 | 37 |
{ |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
38 |
_midi.song[0] = '\0'; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
39 |
DoStop(); |
0 | 40 |
} |
41 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
42 |
void MusicDriver_ExtMidi::PlaySong(const char* filename) |
342 | 43 |
{ |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
44 |
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
|
45 |
DoStop(); |
0 | 46 |
} |
47 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
48 |
void MusicDriver_ExtMidi::StopSong() |
342 | 49 |
{ |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
50 |
_midi.song[0] = '\0'; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
51 |
DoStop(); |
342 | 52 |
} |
53 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
54 |
bool MusicDriver_ExtMidi::IsSongPlaying() |
342 | 55 |
{ |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
56 |
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
|
57 |
_midi.pid = -1; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
58 |
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
|
59 |
return _midi.pid != -1; |
342 | 60 |
} |
61 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
62 |
void MusicDriver_ExtMidi::SetVolume(byte vol) |
342 | 63 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
3721
diff
changeset
|
64 |
DEBUG(driver, 1, "extmidi: set volume not implemented"); |
0 | 65 |
} |
66 |
||
6573 | 67 |
static void DoPlay() |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
68 |
{ |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
69 |
_midi.pid = fork(); |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
70 |
switch (_midi.pid) { |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
71 |
case 0: { |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
72 |
int d; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
73 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
74 |
close(0); |
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); |
2420
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
76 |
if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) { |
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
77 |
#if defined(MIDI_ARG) |
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
78 |
execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, (char*)0); |
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
79 |
#else |
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
80 |
execlp(msf.extmidi, "extmidi", _midi.song, (char*)0); |
e885ba7ba1e2
(svn r2946) Remove redundant calls, simplify a check and terminate the argument list of execlp() as suggested by the manpage to make it correctly work on 64bit platforms
tron
parents:
2412
diff
changeset
|
81 |
#endif |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
82 |
} |
2412
67e06432921e
(svn r2938) -Fix: Exit the child of the extmidi backend with _exit() instead of exit(), because we don't want any atexit handlers - especially flushing output streams - to run, if exec() fails
tron
parents:
2303
diff
changeset
|
83 |
_exit(1); |
1608
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 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
86 |
case -1: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
3721
diff
changeset
|
87 |
DEBUG(driver, 0, "extmidi: couldn't fork: %s", strerror(errno)); |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
88 |
/* FALLTHROUGH */ |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
89 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
90 |
default: |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
91 |
_midi.song[0] = '\0'; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
92 |
break; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
93 |
} |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
94 |
} |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
95 |
|
6573 | 96 |
static void DoStop() |
1608
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 |
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
|
99 |
} |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
100 |
|
0 | 101 |
#endif /* __MORPHOS__ */ |