author | tron |
Fri, 22 Jul 2005 18:19:06 +0000 | |
changeset 2168 | 01b4b1c5720a |
parent 2156 | e74e800dddba |
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 |
||
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1317
diff
changeset
|
31 |
#include "openttd.h" |
1317
f382f1b439c7
(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" |
2156
e74e800dddba
(svn r2666) w32dm.c needs MAX_PATH, which gets defined in variables.h
tron
parents:
1891
diff
changeset
|
33 |
#include "variables.h" |
0 | 34 |
#include "sound.h" |
35 |
#include "hal.h" |
|
36 |
||
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1117
diff
changeset
|
37 |
static const char * DMusicMidiStart(const char * const *parm); |
1117 | 38 |
static void DMusicMidiStop(void); |
0 | 39 |
static void DMusicMidiPlaySong(const char *filename); |
1117 | 40 |
static void DMusicMidiStopSong(void); |
41 |
static bool DMusicMidiIsSongPlaying(void); |
|
0 | 42 |
static void DMusicMidiSetVolume(byte vol); |
43 |
||
44 |
const HalMusicDriver _dmusic_midi_driver = { |
|
45 |
DMusicMidiStart, |
|
46 |
DMusicMidiStop, |
|
47 |
DMusicMidiPlaySong, |
|
48 |
DMusicMidiStopSong, |
|
49 |
DMusicMidiIsSongPlaying, |
|
50 |
DMusicMidiSetVolume, |
|
51 |
}; |
|
52 |
||
53 |
extern bool LoadMIDI (char *directory, char *filename); |
|
54 |
extern bool InitDirectMusic (void); |
|
55 |
extern void ReleaseSegment (void); |
|
56 |
extern void ShutdownDirectMusic (void); |
|
57 |
extern bool LoadMIDI (char *directory, char *filename); |
|
58 |
extern void PlaySegment (void); |
|
59 |
extern void StopSegment (void); |
|
60 |
extern bool IsSegmentPlaying (void); |
|
61 |
extern void SetVolume (long); |
|
62 |
||
2168 | 63 |
static bool seeking = false; |
0 | 64 |
|
1301
313804601383
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1117
diff
changeset
|
65 |
static const char * DMusicMidiStart(const char * const *parm) |
0 | 66 |
{ |
2168 | 67 |
return InitDirectMusic() ? NULL : "Unable to initialize DirectMusic"; |
0 | 68 |
} |
69 |
||
1117 | 70 |
static void DMusicMidiStop(void) |
0 | 71 |
{ |
72 |
StopSegment(); |
|
73 |
} |
|
74 |
||
75 |
static void DMusicMidiPlaySong(const char *filename) |
|
76 |
{ |
|
77 |
char *pos; |
|
78 |
char dir[MAX_PATH]; |
|
79 |
char file[MAX_PATH]; |
|
80 |
||
81 |
// split full path into directory and file components |
|
82 |
ttd_strlcpy(dir, filename, MAX_PATH); |
|
83 |
pos = strrchr(dir, '\\') + 1; |
|
84 |
ttd_strlcpy(file, pos, MAX_PATH); |
|
2168 | 85 |
*pos = '\0'; |
0 | 86 |
|
87 |
LoadMIDI(dir, file); |
|
88 |
PlaySegment(); |
|
89 |
seeking = true; |
|
90 |
} |
|
91 |
||
1117 | 92 |
static void DMusicMidiStopSong(void) |
0 | 93 |
{ |
94 |
StopSegment(); |
|
95 |
} |
|
96 |
||
1117 | 97 |
static bool DMusicMidiIsSongPlaying(void) |
0 | 98 |
{ |
2168 | 99 |
/* Not the nicest code, but there is a short delay before playing actually |
100 |
* starts. OpenTTD makes no provision for this. */ |
|
101 |
if (!IsSegmentPlaying() && seeking) return true; |
|
102 |
if (IsSegmentPlaying()) seeking = false; |
|
0 | 103 |
|
2168 | 104 |
return IsSegmentPlaying(); |
0 | 105 |
} |
106 |
||
107 |
static void DMusicMidiSetVolume(byte vol) |
|
108 |
{ |
|
109 |
SetVolume(vol); |
|
110 |
} |
|
111 |
||
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
|
112 |
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */ |