author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1317 | 3c90086ff34f |
child 1891 | 862800791170 |
permissions | -rw-r--r-- |
0 | 1 |
/********************************************************************* |
2 |
* OpenTTD: An Open Source Transport Tycoon Deluxe clone * |
|
3 |
* Copyright (c) 2002-2004 OpenTTD Developers. All Rights Reserved. * |
|
4 |
* * |
|
5 |
* Web site: http://openttd.sourceforge.net/ * |
|
6 |
*********************************************************************/ |
|
7 |
||
8 |
/* |
|
9 |
* This program is free software; you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU General Public License as published by |
|
11 |
* the Free Software Foundation; either version 2 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
22 |
*/ |
|
23 |
||
24 |
/* DirectMusic driver for Win32 */ |
|
25 |
/* Based on dxmci from TTDPatch */ |
|
26 |
||
27 |
#include "stdafx.h" |
|
28 |
||
29 |
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT |
|
30 |
||
31 |
#include "ttd.h" |
|
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1301
diff
changeset
|
32 |
#include "string.h" |
0 | 33 |
#include "sound.h" |
34 |
#include "hal.h" |
|
35 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1117
diff
changeset
|
36 |
static const char * DMusicMidiStart(const char * const *parm); |
1117 | 37 |
static void DMusicMidiStop(void); |
0 | 38 |
static void DMusicMidiPlaySong(const char *filename); |
1117 | 39 |
static void DMusicMidiStopSong(void); |
40 |
static bool DMusicMidiIsSongPlaying(void); |
|
0 | 41 |
static void DMusicMidiSetVolume(byte vol); |
42 |
||
43 |
const HalMusicDriver _dmusic_midi_driver = { |
|
44 |
DMusicMidiStart, |
|
45 |
DMusicMidiStop, |
|
46 |
DMusicMidiPlaySong, |
|
47 |
DMusicMidiStopSong, |
|
48 |
DMusicMidiIsSongPlaying, |
|
49 |
DMusicMidiSetVolume, |
|
50 |
}; |
|
51 |
||
52 |
extern bool LoadMIDI (char *directory, char *filename); |
|
53 |
extern bool InitDirectMusic (void); |
|
54 |
extern void ReleaseSegment (void); |
|
55 |
extern void ShutdownDirectMusic (void); |
|
56 |
extern bool LoadMIDI (char *directory, char *filename); |
|
57 |
extern void PlaySegment (void); |
|
58 |
extern void StopSegment (void); |
|
59 |
extern bool IsSegmentPlaying (void); |
|
60 |
extern void SetVolume (long); |
|
61 |
||
62 |
bool seeking = false; |
|
63 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1117
diff
changeset
|
64 |
static const char * DMusicMidiStart(const char * const *parm) |
0 | 65 |
{ |
49
8dd4b23924c1
(svn r50) -Fix hopefully the win98 crashes related to music/sound (orudge)
darkvater
parents:
8
diff
changeset
|
66 |
if (InitDirectMusic() == true) |
8dd4b23924c1
(svn r50) -Fix hopefully the win98 crashes related to music/sound (orudge)
darkvater
parents:
8
diff
changeset
|
67 |
return(0); |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
56
diff
changeset
|
68 |
|
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
56
diff
changeset
|
69 |
return("Unable to initialize DirectMusic"); |
0 | 70 |
} |
71 |
||
1117 | 72 |
static void DMusicMidiStop(void) |
0 | 73 |
{ |
74 |
StopSegment(); |
|
75 |
} |
|
76 |
||
77 |
static void DMusicMidiPlaySong(const char *filename) |
|
78 |
{ |
|
79 |
char *pos; |
|
80 |
char dir[MAX_PATH]; |
|
81 |
char file[MAX_PATH]; |
|
82 |
||
83 |
// split full path into directory and file components |
|
84 |
ttd_strlcpy(dir, filename, MAX_PATH); |
|
85 |
pos = strrchr(dir, '\\') + 1; |
|
86 |
ttd_strlcpy(file, pos, MAX_PATH); |
|
87 |
//strchr(file, ' ')[0] = 0; |
|
88 |
*pos = 0; |
|
89 |
||
90 |
LoadMIDI(dir, file); |
|
91 |
PlaySegment(); |
|
92 |
seeking = true; |
|
93 |
} |
|
94 |
||
1117 | 95 |
static void DMusicMidiStopSong(void) |
0 | 96 |
{ |
97 |
StopSegment(); |
|
98 |
} |
|
99 |
||
1117 | 100 |
static bool DMusicMidiIsSongPlaying(void) |
0 | 101 |
{ |
102 |
if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a |
|
103 |
return(true); // short delay before playing actually |
|
104 |
// starts. OpenTTD makes no provision for |
|
105 |
if (IsSegmentPlaying() == 1) // this. |
|
106 |
seeking = false; |
|
107 |
||
108 |
||
109 |
return(IsSegmentPlaying()); |
|
110 |
} |
|
111 |
||
112 |
static void DMusicMidiSetVolume(byte vol) |
|
113 |
{ |
|
114 |
SetVolume(vol); |
|
115 |
} |
|
116 |
||
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
56
diff
changeset
|
117 |
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */ |