src/music/win32_m.cpp
author glx
Fri, 07 Dec 2007 17:42:15 +0000
changeset 8026 a188ea8201ce
parent 7623 2841df003253
child 8693 530c3ebc5a61
permissions -rw-r--r--
(svn r11586) -Fix: make another widget 'accessor' function const when it should be const.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     3
#include "../stdafx.h"
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     4
#include "win32_m.h"
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
     5
#include <windows.h>
2189
5cdc11ffeaa4 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     6
#include <mmsystem.h>
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
     7
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
     8
static struct {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
     9
	bool stop_song;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    10
	bool terminate;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    11
	bool playing;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    12
	int new_vol;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    13
	HANDLE wait_obj;
7514
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
    14
	HANDLE thread;
2458
dbaf5dffbb28 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2434
diff changeset
    15
	UINT_PTR devid;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    16
	char start_song[260];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    17
} _midi;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    18
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    19
static FMusicDriver_Win32 iFMusicDriver_Win32;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    20
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    21
void MusicDriver_Win32::PlaySong(const char *filename)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    22
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    23
	strcpy(_midi.start_song, filename);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    24
	_midi.playing = true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    25
	_midi.stop_song = false;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    26
	SetEvent(_midi.wait_obj);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    27
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    28
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    29
void MusicDriver_Win32::StopSong()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    30
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    31
	if (_midi.playing) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    32
		_midi.stop_song = true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    33
		_midi.start_song[0] = '\0';
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    34
		SetEvent(_midi.wait_obj);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    35
	}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    36
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    37
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    38
bool MusicDriver_Win32::IsSongPlaying()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    39
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    40
	return _midi.playing;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    41
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    42
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
    43
void MusicDriver_Win32::SetVolume(byte vol)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    44
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    45
	_midi.new_vol = vol;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    46
	SetEvent(_midi.wait_obj);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    47
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    48
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2458
diff changeset
    49
static MCIERROR CDECL MidiSendCommand(const char* cmd, ...)
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2458
diff changeset
    50
{
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    51
	va_list va;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    52
	char buf[512];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    53
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    54
	va_start(va, cmd);
6124
9f822ae6c086 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 5584
diff changeset
    55
	vsnprintf(buf, lengthof(buf), cmd, va);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    56
	va_end(va);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    57
	return mciSendStringA(buf, NULL, 0, 0);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    58
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    59
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    60
static bool MidiIntPlaySong(const char *filename)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    61
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    62
	MidiSendCommand("close all");
6124
9f822ae6c086 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 5584
diff changeset
    63
	if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0) return false;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    64
6124
9f822ae6c086 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 5584
diff changeset
    65
	return MidiSendCommand("play song from 0") == 0;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    66
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    67
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6124
diff changeset
    68
static void MidiIntStopSong()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    69
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    70
	MidiSendCommand("close all");
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    71
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    72
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    73
static void MidiIntSetVolume(int vol)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    74
{
2458
dbaf5dffbb28 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2434
diff changeset
    75
	DWORD v = (vol * 65535 / 127);
2434
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
    76
	midiOutSetVolume((HMIDIOUT)_midi.devid, v + (v << 16));
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    77
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    78
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6124
diff changeset
    79
static bool MidiIntIsSongPlaying()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    80
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    81
	char buf[16];
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    82
	mciSendStringA("status song mode", buf, sizeof(buf), 0);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    83
	return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    84
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    85
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    86
static DWORD WINAPI MidiThread(LPVOID arg)
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    87
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    88
	do {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    89
		char *s;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    90
		int vol;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    91
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    92
		vol = _midi.new_vol;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    93
		if (vol != -1) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    94
			_midi.new_vol = -1;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    95
			MidiIntSetVolume(vol);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    96
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    97
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    98
		s = _midi.start_song;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
    99
		if (s[0] != '\0') {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   100
			_midi.playing = MidiIntPlaySong(s);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   101
			s[0] = '\0';
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   102
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   103
			// Delay somewhat in case we don't manage to play.
7514
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   104
			if (!_midi.playing) WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 5000);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   105
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   106
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   107
		if (_midi.stop_song && _midi.playing) {
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   108
			_midi.stop_song = false;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   109
			_midi.playing = false;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   110
			MidiIntStopSong();
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   111
		}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   112
6124
9f822ae6c086 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 5584
diff changeset
   113
		if (_midi.playing && !MidiIntIsSongPlaying()) _midi.playing = false;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   114
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   115
		WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   116
	} while (!_midi.terminate);
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   117
7514
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   118
	MidiIntStopSong();
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   119
	return 0;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   120
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   121
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
   122
const char *MusicDriver_Win32::Start(const char * const *parm)
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   123
{
2434
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   124
	MIDIOUTCAPS midicaps;
2458
dbaf5dffbb28 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2434
diff changeset
   125
	UINT nbdev;
dbaf5dffbb28 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2434
diff changeset
   126
	UINT_PTR dev;
2212
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   127
	char buf[16];
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   128
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   129
	mciSendStringA("capability sequencer has audio", buf, lengthof(buf), 0);
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   130
	if (strcmp(buf, "true") != 0) return "MCI sequencer can't play audio";
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   131
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   132
	memset(&_midi, 0, sizeof(_midi));
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   133
	_midi.new_vol = -1;
2212
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   134
2434
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   135
	/* Get midi device */
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   136
	_midi.devid = MIDI_MAPPER;
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   137
	for (dev = 0, nbdev = midiOutGetNumDevs(); dev < nbdev; dev++) {
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   138
		if (midiOutGetDevCaps(dev, &midicaps, sizeof(midicaps)) == 0 && (midicaps.dwSupport & MIDICAPS_VOLUME)) {
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   139
			_midi.devid = dev;
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   140
			break;
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   141
		}
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   142
	}
1134a371ebdd (svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents: 2212
diff changeset
   143
7514
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   144
	if (NULL == (_midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL))) return "Failed to create event";
7623
2841df003253 (svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents: 7514
diff changeset
   145
2841df003253 (svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents: 7514
diff changeset
   146
	/* The lpThreadId parameter of CreateThread (the last parameter)
2841df003253 (svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents: 7514
diff changeset
   147
	 * may NOT be NULL on Windows 95, 98 and ME. */
2841df003253 (svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents: 7514
diff changeset
   148
	DWORD threadId;
2841df003253 (svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents: 7514
diff changeset
   149
	if (NULL == (_midi.thread = CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId))) return "Failed to create thread";
2212
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   150
60a01ae79e03 (svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents: 2189
diff changeset
   151
	return NULL;
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   152
}
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   153
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6247
diff changeset
   154
void MusicDriver_Win32::Stop()
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   155
{
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   156
	_midi.terminate = true;
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   157
	SetEvent(_midi.wait_obj);
7514
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   158
	WaitForMultipleObjects(1, &_midi.thread, true, INFINITE);
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   159
	CloseHandle(_midi.wait_obj);
ac7aac471204 (svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents: 7170
diff changeset
   160
	CloseHandle(_midi.thread);
2174
24d868f1c576 (svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff changeset
   161
}