| author | tron |
| Sun, 21 Aug 2005 17:32:43 +0000 | |
| changeset 2358 | f6d863c533f2 |
| parent 2303 | 559e782ebc25 |
| child 2412 | 7c89a94e1be5 |
| permissions | -rw-r--r-- |
| 2186 | 1 |
/* $Id$ */ |
2 |
||
| 0 | 3 |
#ifndef __MORPHOS__ |
|
2189
5cdc11ffeaa4
(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" |
|
5cdc11ffeaa4
(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" |
|
5cdc11ffeaa4
(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" |
|
5cdc11ffeaa4
(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" |
|
5cdc11ffeaa4
(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" |
|
5cdc11ffeaa4
(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 "extmidi.h" |
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
10 |
#include <fcntl.h> |
| 0 | 11 |
#include <sys/types.h> |
12 |
#include <sys/wait.h> |
|
13 |
#include <unistd.h> |
|
14 |
#include <signal.h> |
|
15 |
#include <sys/stat.h> |
|
16 |
#include <errno.h> |
|
17 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
18 |
static struct {
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
19 |
char song[MAX_PATH]; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
20 |
int pid; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
21 |
} _midi; |
| 0 | 22 |
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
23 |
static void DoPlay(void); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
24 |
static void DoStop(void); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
25 |
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
26 |
static const char* ExtMidiStart(const char* const * parm) |
| 342 | 27 |
{
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
28 |
_midi.song[0] = '\0'; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
29 |
_midi.pid = -1; |
| 342 | 30 |
return NULL; |
| 0 | 31 |
} |
32 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
33 |
static void ExtMidiStop(void) |
| 342 | 34 |
{
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
35 |
_midi.song[0] = '\0'; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
36 |
DoStop(); |
| 0 | 37 |
} |
38 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
39 |
static void ExtMidiPlaySong(const char* filename) |
| 342 | 40 |
{
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
41 |
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
|
42 |
DoStop(); |
| 0 | 43 |
} |
44 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
45 |
static void ExtMidiStopSong(void) |
| 342 | 46 |
{
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
47 |
_midi.song[0] = '\0'; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
48 |
DoStop(); |
| 342 | 49 |
} |
50 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
51 |
static bool ExtMidiIsPlaying(void) |
| 342 | 52 |
{
|
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
53 |
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
|
54 |
_midi.pid = -1; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
55 |
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
|
56 |
return _midi.pid != -1; |
| 342 | 57 |
} |
58 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
59 |
static void ExtMidiSetVolume(byte vol) |
| 342 | 60 |
{
|
61 |
fprintf(stderr, "extmidi: set volume not implemented\n"); |
|
| 0 | 62 |
} |
63 |
||
|
1608
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
64 |
static void DoPlay(void) |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
65 |
{
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
66 |
_midi.pid = fork(); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
67 |
switch (_midi.pid) {
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
68 |
case 0: {
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
69 |
int d; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
70 |
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
71 |
close(0); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
72 |
close(1); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
73 |
close(2); |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
74 |
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
|
75 |
if (d != -1) {
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
76 |
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
|
77 |
#if defined(MIDI_ARG) |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
78 |
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
|
79 |
#else |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
80 |
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
|
81 |
#endif |
|
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 |
} |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
84 |
exit(1); |
|
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 |
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
87 |
case -1: |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
88 |
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
|
89 |
/* FALLTHROUGH */ |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
90 |
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
91 |
default: |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
92 |
_midi.song[0] = '\0'; |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
93 |
break; |
|
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 |
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
97 |
static void DoStop(void) |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
98 |
{
|
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
99 |
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
|
100 |
} |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
101 |
|
| 0 | 102 |
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
|
103 |
ExtMidiStart, |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
104 |
ExtMidiStop, |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
105 |
ExtMidiPlaySong, |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
106 |
ExtMidiStopSong, |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
107 |
ExtMidiIsPlaying, |
|
70a3c1a6576d
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1584
diff
changeset
|
108 |
ExtMidiSetVolume, |
| 0 | 109 |
}; |
| 342 | 110 |
|
| 0 | 111 |
#endif /* __MORPHOS__ */ |