author | truelight |
Thu, 12 Aug 2004 17:49:16 +0000 | |
changeset 26 | 4c08274a29dc |
parent 8 | 9ab81ef450f2 |
child 49 | 8dd4b23924c1 |
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" |
|
32 |
#include "sound.h" |
|
33 |
#include "hal.h" |
|
34 |
||
35 |
static char * DMusicMidiStart(char **parm); |
|
36 |
static void DMusicMidiStop(); |
|
37 |
static void DMusicMidiPlaySong(const char *filename); |
|
38 |
static void DMusicMidiStopSong(); |
|
39 |
static bool DMusicMidiIsSongPlaying(); |
|
40 |
static void DMusicMidiSetVolume(byte vol); |
|
41 |
||
42 |
const HalMusicDriver _dmusic_midi_driver = { |
|
43 |
DMusicMidiStart, |
|
44 |
DMusicMidiStop, |
|
45 |
DMusicMidiPlaySong, |
|
46 |
DMusicMidiStopSong, |
|
47 |
DMusicMidiIsSongPlaying, |
|
48 |
DMusicMidiSetVolume, |
|
49 |
}; |
|
50 |
||
51 |
extern bool LoadMIDI (char *directory, char *filename); |
|
52 |
extern bool InitDirectMusic (void); |
|
53 |
extern void ReleaseSegment (void); |
|
54 |
extern void ShutdownDirectMusic (void); |
|
55 |
extern bool LoadMIDI (char *directory, char *filename); |
|
56 |
extern void PlaySegment (void); |
|
57 |
extern void StopSegment (void); |
|
58 |
extern bool IsSegmentPlaying (void); |
|
59 |
extern void SetVolume (long); |
|
60 |
||
61 |
bool seeking = false; |
|
62 |
||
63 |
static char * DMusicMidiStart(char **parm) |
|
64 |
{ |
|
65 |
InitDirectMusic(); |
|
66 |
return 0; |
|
67 |
} |
|
68 |
||
69 |
static void DMusicMidiStop() |
|
70 |
{ |
|
71 |
StopSegment(); |
|
72 |
} |
|
73 |
||
74 |
static void DMusicMidiPlaySong(const char *filename) |
|
75 |
{ |
|
76 |
char *pos; |
|
77 |
char dir[MAX_PATH]; |
|
78 |
char file[MAX_PATH]; |
|
79 |
||
80 |
// split full path into directory and file components |
|
81 |
ttd_strlcpy(dir, filename, MAX_PATH); |
|
82 |
pos = strrchr(dir, '\\') + 1; |
|
83 |
ttd_strlcpy(file, pos, MAX_PATH); |
|
84 |
//strchr(file, ' ')[0] = 0; |
|
85 |
*pos = 0; |
|
86 |
||
87 |
LoadMIDI(dir, file); |
|
88 |
PlaySegment(); |
|
89 |
seeking = true; |
|
90 |
} |
|
91 |
||
92 |
static void DMusicMidiStopSong() |
|
93 |
{ |
|
94 |
StopSegment(); |
|
95 |
} |
|
96 |
||
97 |
static bool DMusicMidiIsSongPlaying() |
|
98 |
{ |
|
99 |
if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a |
|
100 |
return(true); // short delay before playing actually |
|
101 |
// starts. OpenTTD makes no provision for |
|
102 |
if (IsSegmentPlaying() == 1) // this. |
|
103 |
seeking = false; |
|
104 |
||
105 |
||
106 |
return(IsSegmentPlaying()); |
|
107 |
} |
|
108 |
||
109 |
static void DMusicMidiSetVolume(byte vol) |
|
110 |
{ |
|
111 |
SetVolume(vol); |
|
112 |
} |
|
113 |
||
8
9ab81ef450f2
(svn r9) Fixed a couple of warnings and minor coding issues
dominik
parents:
0
diff
changeset
|
114 |
#endif |