author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9111 | 48ce04029fe4 |
child 10201 | 4c181fbe8f2a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8700
diff
changeset
|
3 |
/** @file win32_m.cpp Music playback for Windows. */ |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8700
diff
changeset
|
4 |
|
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
|
5 |
#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
|
6 |
#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
|
7 |
#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
|
8 |
#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
|
9 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
10 |
static struct { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
11 |
bool stop_song; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
12 |
bool terminate; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
13 |
bool playing; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
14 |
int new_vol; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
15 |
HANDLE wait_obj; |
7514
ac7aac471204
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents:
7170
diff
changeset
|
16 |
HANDLE thread; |
2458
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2434
diff
changeset
|
17 |
UINT_PTR devid; |
8693
530c3ebc5a61
(svn r12366) -Codechange: use MAX_PATH instead hardcoded value
glx
parents:
7623
diff
changeset
|
18 |
char start_song[MAX_PATH]; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
19 |
} _midi; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
20 |
|
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
|
21 |
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
|
22 |
|
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
|
23 |
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
|
24 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
25 |
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
|
26 |
_midi.playing = true; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
27 |
_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
|
28 |
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
|
29 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
30 |
|
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
|
31 |
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
|
32 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
33 |
if (_midi.playing) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
34 |
_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
|
35 |
_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
|
36 |
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
|
37 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
38 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
39 |
|
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
|
40 |
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
|
41 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
42 |
return _midi.playing; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
43 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
44 |
|
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
|
45 |
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
|
46 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
47 |
_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
|
48 |
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
|
49 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
50 |
|
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
51 |
static MCIERROR CDECL MidiSendCommand(const TCHAR* cmd, ...) |
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
|
52 |
{ |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
53 |
va_list va; |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
54 |
TCHAR buf[512]; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
55 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
56 |
va_start(va, cmd); |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
57 |
_vsntprintf(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
|
58 |
va_end(va); |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
59 |
return mciSendString(buf, NULL, 0, 0); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
60 |
} |
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 |
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
|
63 |
{ |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
64 |
MidiSendCommand(_T("close all")); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
65 |
|
8700
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
66 |
if (MidiSendCommand(_T("open \"%s\" type sequencer alias song"), OTTD2FS(filename)) != 0) { |
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
67 |
/* Let's try the "short name" */ |
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
68 |
TCHAR buf[MAX_PATH]; |
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
69 |
if (GetShortPathName(OTTD2FS(filename), buf, MAX_PATH) == 0) return false; |
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
70 |
if (MidiSendCommand(_T("open \"%s\" type sequencer alias song"), buf) != 0) return false; |
df3adf076096
(svn r12373) -Fix [FS#1849]: win32 music driver fails if path is too long (128 chars is too much for mci it seems), so retry using the short path name (8.3 style) if available
glx
parents:
8699
diff
changeset
|
71 |
} |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
72 |
|
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
73 |
return MidiSendCommand(_T("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
|
74 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
75 |
|
6247 | 76 |
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
|
77 |
{ |
8699
831349476467
(svn r12372) -Fix: win32 music driver fails if path contains non-latin chars
glx
parents:
8693
diff
changeset
|
78 |
MidiSendCommand(_T("close all")); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
79 |
} |
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 |
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
|
82 |
{ |
2458
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2434
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
86 |
|
6247 | 87 |
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
|
88 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
89 |
char buf[16]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
93 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
94 |
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
|
95 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
96 |
do { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
97 |
char *s; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
98 |
int vol; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
99 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
100 |
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
|
101 |
if (vol != -1) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
102 |
_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
|
103 |
MidiIntSetVolume(vol); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
104 |
} |
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 |
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
|
107 |
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
|
108 |
_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
|
109 |
s[0] = '\0'; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
110 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
111 |
// 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
|
112 |
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
|
113 |
} |
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 |
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
|
116 |
_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
|
117 |
_midi.playing = false; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
118 |
MidiIntStopSong(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
119 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
120 |
|
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
|
121 |
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
|
122 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
123 |
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
|
124 |
} while (!_midi.terminate); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
125 |
|
7514
ac7aac471204
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents:
7170
diff
changeset
|
126 |
MidiIntStopSong(); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
127 |
return 0; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
128 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
129 |
|
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
|
130 |
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
|
131 |
{ |
2434
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
132 |
MIDIOUTCAPS midicaps; |
2458
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2434
diff
changeset
|
133 |
UINT nbdev; |
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2434
diff
changeset
|
134 |
UINT_PTR dev; |
2212
60a01ae79e03
(svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents:
2189
diff
changeset
|
135 |
char buf[16]; |
60a01ae79e03
(svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents:
2189
diff
changeset
|
136 |
|
60a01ae79e03
(svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents:
2189
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
140 |
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
|
141 |
_midi.new_vol = -1; |
2212
60a01ae79e03
(svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents:
2189
diff
changeset
|
142 |
|
2434
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
143 |
/* Get midi device */ |
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
144 |
_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
|
145 |
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
|
146 |
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
|
147 |
_midi.devid = dev; |
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
148 |
break; |
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
149 |
} |
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
150 |
} |
1134a371ebdd
(svn r2960) - Fix: [ 1227779 ] Fix win32 midi volume level control which didn't work (glx)
Darkvater
parents:
2212
diff
changeset
|
151 |
|
7514
ac7aac471204
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents:
7170
diff
changeset
|
152 |
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
|
153 |
|
2841df003253
(svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents:
7514
diff
changeset
|
154 |
/* 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
|
155 |
* 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
|
156 |
DWORD threadId; |
2841df003253
(svn r11154) -Fix [FS#1239]: MIDI failing to play under Windows 95, 98 and ME.
rubidium
parents:
7514
diff
changeset
|
157 |
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
|
158 |
|
60a01ae79e03
(svn r2730) -Fix: Fail if the sequencer can't play audio
tron
parents:
2189
diff
changeset
|
159 |
return NULL; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
160 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
161 |
|
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
|
162 |
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
|
163 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
164 |
_midi.terminate = true; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
165 |
SetEvent(_midi.wait_obj); |
7514
ac7aac471204
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents:
7170
diff
changeset
|
166 |
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
|
167 |
CloseHandle(_midi.wait_obj); |
ac7aac471204
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
glx
parents:
7170
diff
changeset
|
168 |
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
|
169 |
} |