truelight@0: /********************************************************************* truelight@0: * OpenTTD: An Open Source Transport Tycoon Deluxe clone * truelight@0: * Copyright (c) 2002-2004 OpenTTD Developers. All Rights Reserved. * truelight@0: * * truelight@0: * Web site: http://openttd.sourceforge.net/ * truelight@0: *********************************************************************/ truelight@0: truelight@0: /* truelight@0: * This program is free software; you can redistribute it and/or modify truelight@0: * it under the terms of the GNU General Public License as published by truelight@0: * the Free Software Foundation; either version 2 of the License, or truelight@0: * (at your option) any later version. truelight@0: * truelight@0: * This program is distributed in the hope that it will be useful, truelight@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of truelight@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the truelight@0: * GNU General Public License for more details. truelight@0: * truelight@0: * You should have received a copy of the GNU General Public License truelight@0: * along with this program; if not, write to the Free Software truelight@0: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. truelight@0: */ truelight@0: truelight@0: /* DirectMusic driver for Win32 */ truelight@0: /* Based on dxmci from TTDPatch */ truelight@0: truelight@0: #include "stdafx.h" truelight@0: truelight@0: #ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT truelight@0: truelight@0: #include "ttd.h" truelight@0: #include "sound.h" truelight@0: #include "hal.h" truelight@0: truelight@0: static char * DMusicMidiStart(char **parm); tron@1117: static void DMusicMidiStop(void); truelight@0: static void DMusicMidiPlaySong(const char *filename); tron@1117: static void DMusicMidiStopSong(void); tron@1117: static bool DMusicMidiIsSongPlaying(void); truelight@0: static void DMusicMidiSetVolume(byte vol); truelight@0: truelight@0: const HalMusicDriver _dmusic_midi_driver = { truelight@0: DMusicMidiStart, truelight@0: DMusicMidiStop, truelight@0: DMusicMidiPlaySong, truelight@0: DMusicMidiStopSong, truelight@0: DMusicMidiIsSongPlaying, truelight@0: DMusicMidiSetVolume, truelight@0: }; truelight@0: truelight@0: extern bool LoadMIDI (char *directory, char *filename); truelight@0: extern bool InitDirectMusic (void); truelight@0: extern void ReleaseSegment (void); truelight@0: extern void ShutdownDirectMusic (void); truelight@0: extern bool LoadMIDI (char *directory, char *filename); truelight@0: extern void PlaySegment (void); truelight@0: extern void StopSegment (void); truelight@0: extern bool IsSegmentPlaying (void); truelight@0: extern void SetVolume (long); truelight@0: truelight@0: bool seeking = false; truelight@0: truelight@0: static char * DMusicMidiStart(char **parm) truelight@0: { darkvater@49: if (InitDirectMusic() == true) darkvater@49: return(0); darkvater@223: darkvater@223: return("Unable to initialize DirectMusic"); truelight@0: } truelight@0: tron@1117: static void DMusicMidiStop(void) truelight@0: { truelight@0: StopSegment(); truelight@0: } truelight@0: truelight@0: static void DMusicMidiPlaySong(const char *filename) truelight@0: { truelight@0: char *pos; truelight@0: char dir[MAX_PATH]; truelight@0: char file[MAX_PATH]; truelight@0: truelight@0: // split full path into directory and file components truelight@0: ttd_strlcpy(dir, filename, MAX_PATH); truelight@0: pos = strrchr(dir, '\\') + 1; truelight@0: ttd_strlcpy(file, pos, MAX_PATH); truelight@0: //strchr(file, ' ')[0] = 0; truelight@0: *pos = 0; truelight@0: truelight@0: LoadMIDI(dir, file); truelight@0: PlaySegment(); truelight@0: seeking = true; truelight@0: } truelight@0: tron@1117: static void DMusicMidiStopSong(void) truelight@0: { truelight@0: StopSegment(); truelight@0: } truelight@0: tron@1117: static bool DMusicMidiIsSongPlaying(void) truelight@0: { truelight@0: if ((IsSegmentPlaying() == 0) && (seeking == true)) // Not the nicest code, but there is a truelight@0: return(true); // short delay before playing actually truelight@0: // starts. OpenTTD makes no provision for truelight@0: if (IsSegmentPlaying() == 1) // this. truelight@0: seeking = false; truelight@0: truelight@0: truelight@0: return(IsSegmentPlaying()); truelight@0: } truelight@0: truelight@0: static void DMusicMidiSetVolume(byte vol) truelight@0: { truelight@0: SetVolume(vol); truelight@0: } truelight@0: darkvater@223: #endif /* WIN32_ENABLE_DIRECTMUSIC_SUPPORT */