src/music/win32_m.cpp
branchnoai
changeset 9826 9707ad4c9b60
parent 9704 197cb8c6ae17
child 10455 22c441f5adf9
equal deleted inserted replaced
9825:cc77111ebd85 9826:9707ad4c9b60
    11 	bool playing;
    11 	bool playing;
    12 	int new_vol;
    12 	int new_vol;
    13 	HANDLE wait_obj;
    13 	HANDLE wait_obj;
    14 	HANDLE thread;
    14 	HANDLE thread;
    15 	UINT_PTR devid;
    15 	UINT_PTR devid;
    16 	char start_song[260];
    16 	char start_song[MAX_PATH];
    17 } _midi;
    17 } _midi;
    18 
    18 
    19 static FMusicDriver_Win32 iFMusicDriver_Win32;
    19 static FMusicDriver_Win32 iFMusicDriver_Win32;
    20 
    20 
    21 void MusicDriver_Win32::PlaySong(const char *filename)
    21 void MusicDriver_Win32::PlaySong(const char *filename)
    44 {
    44 {
    45 	_midi.new_vol = vol;
    45 	_midi.new_vol = vol;
    46 	SetEvent(_midi.wait_obj);
    46 	SetEvent(_midi.wait_obj);
    47 }
    47 }
    48 
    48 
    49 static MCIERROR CDECL MidiSendCommand(const char* cmd, ...)
    49 static MCIERROR CDECL MidiSendCommand(const TCHAR* cmd, ...)
    50 {
    50 {
    51 	va_list va;
    51 	va_list va;
    52 	char buf[512];
    52 	TCHAR buf[512];
    53 
    53 
    54 	va_start(va, cmd);
    54 	va_start(va, cmd);
    55 	vsnprintf(buf, lengthof(buf), cmd, va);
    55 	_vsntprintf(buf, lengthof(buf), cmd, va);
    56 	va_end(va);
    56 	va_end(va);
    57 	return mciSendStringA(buf, NULL, 0, 0);
    57 	return mciSendString(buf, NULL, 0, 0);
    58 }
    58 }
    59 
    59 
    60 static bool MidiIntPlaySong(const char *filename)
    60 static bool MidiIntPlaySong(const char *filename)
    61 {
    61 {
    62 	MidiSendCommand("close all");
    62 	MidiSendCommand(_T("close all"));
    63 	if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0) return false;
       
    64 
    63 
    65 	return MidiSendCommand("play song from 0") == 0;
    64 	if (MidiSendCommand(_T("open \"%s\" type sequencer alias song"), OTTD2FS(filename)) != 0) {
       
    65 		/* Let's try the "short name" */
       
    66 		TCHAR buf[MAX_PATH];
       
    67 		if (GetShortPathName(OTTD2FS(filename), buf, MAX_PATH) == 0) return false;
       
    68 		if (MidiSendCommand(_T("open \"%s\" type sequencer alias song"), buf) != 0) return false;
       
    69 	}
       
    70 
       
    71 	return MidiSendCommand(_T("play song from 0")) == 0;
    66 }
    72 }
    67 
    73 
    68 static void MidiIntStopSong()
    74 static void MidiIntStopSong()
    69 {
    75 {
    70 	MidiSendCommand("close all");
    76 	MidiSendCommand(_T("close all"));
    71 }
    77 }
    72 
    78 
    73 static void MidiIntSetVolume(int vol)
    79 static void MidiIntSetVolume(int vol)
    74 {
    80 {
    75 	DWORD v = (vol * 65535 / 127);
    81 	DWORD v = (vol * 65535 / 127);