summaryrefslogtreecommitdiff
path: root/w32dm.c
blob: 7c7dbbb9f7b429fa306c97fff73f8d5b8c76d49b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*********************************************************************
 * OpenTTD: An Open Source Transport Tycoon Deluxe clone             *
 * Copyright (c) 2002-2004 OpenTTD Developers. All Rights Reserved.  *
 *                                                                   *
 * Web site: http://openttd.sourceforge.net/                         *
 *********************************************************************/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* DirectMusic driver for Win32 */
/* Based on dxmci from TTDPatch */

#include "stdafx.h"

#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT

#include "ttd.h"
#include "sound.h"
#include "hal.h"

static char * DMusicMidiStart(char **parm);
static void DMusicMidiStop();
static void DMusicMidiPlaySong(const char *filename);
static void DMusicMidiStopSong();
static bool DMusicMidiIsSongPlaying();
static void DMusicMidiSetVolume(byte vol);

const HalMusicDriver _dmusic_midi_driver = {
	DMusicMidiStart,
	DMusicMidiStop,
	DMusicMidiPlaySong,
	DMusicMidiStopSong,
	DMusicMidiIsSongPlaying,
	DMusicMidiSetVolume,
};

extern bool LoadMIDI (char *directory, char *filename);
extern bool InitDirectMusic (void);
extern void ReleaseSegment (void);
extern void ShutdownDirectMusic (void);
extern bool LoadMIDI (char *directory, char *filename);
extern void PlaySegment (void);
extern void StopSegment (void);
extern bool IsSegmentPlaying (void);
extern void SetVolume (long);

bool seeking = false;

static char * DMusicMidiStart(char **parm)
{
	InitDirectMusic();
	return 0;
}

static void DMusicMidiStop()
{
	StopSegment();
}

static void DMusicMidiPlaySong(const char *filename)
{
	char *pos;
	char dir[MAX_PATH];
	char file[MAX_PATH];

	// split full path into directory and file components
	ttd_strlcpy(dir, filename, MAX_PATH);
	pos = strrchr(dir, '\\') + 1;
	ttd_strlcpy(file, pos, MAX_PATH);
	//strchr(file, ' ')[0] = 0;
	*pos = 0;

	LoadMIDI(dir, file);
	PlaySegment();
	seeking = true;
}

static void DMusicMidiStopSong()
{
	StopSegment();
}

static bool DMusicMidiIsSongPlaying()
{
	if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a
		return(true);                                   // short delay before playing actually
                                                        // starts. OpenTTD makes no provision for
	if (IsSegmentPlaying() == 1)                        // this.
		seeking = false;


	return(IsSegmentPlaying());
}

static void DMusicMidiSetVolume(byte vol)
{
	SetVolume(vol);
}

#endif