author | rubidium |
Sat, 07 Jul 2007 09:20:52 +0000 | |
branch | noai |
changeset 9631 | 8a2d1c2ceb88 |
parent 6573 | 7624f942237f |
child 6872 | 1c4a4a609f85 |
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 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
19 |
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi; |
0 | 20 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
21 |
const char* MusicDriver_ExtMidi::Start(const char* const * parm) |
342 | 22 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
23 |
this->song[0] = '\0'; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
24 |
this->pid = -1; |
342 | 25 |
return NULL; |
0 | 26 |
} |
27 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
28 |
void MusicDriver_ExtMidi::Stop() |
342 | 29 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
30 |
this->song[0] = '\0'; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
31 |
this->DoStop(); |
0 | 32 |
} |
33 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
34 |
void MusicDriver_ExtMidi::PlaySong(const char* filename) |
342 | 35 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
36 |
ttd_strlcpy(this->song, filename, lengthof(this->song)); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
37 |
this->DoStop(); |
342 | 38 |
} |
39 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
40 |
void MusicDriver_ExtMidi::StopSong() |
342 | 41 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
42 |
this->song[0] = '\0'; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
43 |
this->DoStop(); |
342 | 44 |
} |
45 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
46 |
bool MusicDriver_ExtMidi::IsSongPlaying() |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
47 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
48 |
if (this->pid != -1 && waitpid(this->pid, NULL, WNOHANG) == this->pid) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
49 |
this->pid = -1; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
50 |
if (this->pid == -1 && this->song[0] != '\0') this->DoPlay(); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
51 |
return this->pid != -1; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
52 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
53 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
54 |
void MusicDriver_ExtMidi::SetVolume(byte vol) |
342 | 55 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
3721
diff
changeset
|
56 |
DEBUG(driver, 1, "extmidi: set volume not implemented"); |
0 | 57 |
} |
58 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
59 |
void MusicDriver_ExtMidi::DoPlay() |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
60 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
61 |
this->pid = fork(); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
62 |
switch (this->pid) { |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
63 |
case 0: { |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
64 |
int d; |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
65 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
66 |
close(0); |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
#if defined(MIDI_ARG) |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
70 |
execlp(msf.extmidi, "extmidi", MIDI_ARG, this->song, (char*)0); |
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
|
71 |
#else |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
72 |
execlp(msf.extmidi, "extmidi", this->song, (char*)0); |
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
|
73 |
#endif |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
74 |
} |
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
|
75 |
_exit(1); |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
76 |
} |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
77 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
78 |
case -1: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
3721
diff
changeset
|
79 |
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
|
80 |
/* FALLTHROUGH */ |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
81 |
|
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
82 |
default: |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
83 |
this->song[0] = '\0'; |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
84 |
break; |
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 |
} |
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
87 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
88 |
void MusicDriver_ExtMidi::DoStop() |
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
89 |
{ |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
6573
diff
changeset
|
90 |
if (this->pid != -1) kill(this->pid, SIGTERM); |
1608
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 |
|
0 | 93 |
#endif /* __MORPHOS__ */ |