2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* 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 */
|
|
|
|
|
2005-07-25 07:16:10 +00:00
|
|
|
#include "../stdafx.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
|
|
|
|
|
2005-07-25 07:16:10 +00:00
|
|
|
#include "../openttd.h"
|
|
|
|
#include "../string.h"
|
|
|
|
#include "../variables.h"
|
|
|
|
#include "../sound.h"
|
|
|
|
#include "dmusic.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-05 18:05:42 +00:00
|
|
|
static const char * DMusicMidiStart(const char * const *parm);
|
2005-01-23 16:33:09 +00:00
|
|
|
static void DMusicMidiStop(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
static void DMusicMidiPlaySong(const char *filename);
|
2005-01-23 16:33:09 +00:00
|
|
|
static void DMusicMidiStopSong(void);
|
|
|
|
static bool DMusicMidiIsSongPlaying(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
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);
|
|
|
|
|
2005-07-22 18:19:06 +00:00
|
|
|
static bool seeking = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-05 18:05:42 +00:00
|
|
|
static const char * DMusicMidiStart(const char * const *parm)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-22 18:19:06 +00:00
|
|
|
return InitDirectMusic() ? NULL : "Unable to initialize DirectMusic";
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-23 16:33:09 +00:00
|
|
|
static void DMusicMidiStop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
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);
|
2005-07-22 18:19:06 +00:00
|
|
|
*pos = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
LoadMIDI(dir, file);
|
|
|
|
PlaySegment();
|
|
|
|
seeking = true;
|
|
|
|
}
|
|
|
|
|
2005-01-23 16:33:09 +00:00
|
|
|
static void DMusicMidiStopSong(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
StopSegment();
|
|
|
|
}
|
|
|
|
|
2005-01-23 16:33:09 +00:00
|
|
|
static bool DMusicMidiIsSongPlaying(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-22 18:19:06 +00:00
|
|
|
/* Not the nicest code, but there is a short delay before playing actually
|
|
|
|
* starts. OpenTTD makes no provision for this. */
|
|
|
|
if (!IsSegmentPlaying() && seeking) return true;
|
|
|
|
if (IsSegmentPlaying()) seeking = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-22 18:19:06 +00:00
|
|
|
return IsSegmentPlaying();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DMusicMidiSetVolume(byte vol)
|
|
|
|
{
|
|
|
|
SetVolume(vol);
|
|
|
|
}
|
|
|
|
|
2004-09-12 22:03:14 +00:00
|
|
|
#endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */
|