]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cd_win.c
use sdl-config --static-libs on Mac
[xonotic/darkplaces.git] / cd_win.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
21 // rights reserved.
22
23 #include <windows.h>
24
25 #include "quakedef.h"
26 #include "cdaudio.h"
27
28
29 extern  HWND    mainwindow;
30
31 UINT    wDeviceID;
32
33 void CDAudio_SysEject(void)
34 {
35         DWORD   dwReturn;
36
37         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL)))
38                 Con_Printf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
39 }
40
41
42 void CDAudio_SysCloseDoor(void)
43 {
44         DWORD   dwReturn;
45
46         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL)))
47                 Con_Printf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
48 }
49
50 int CDAudio_SysGetAudioDiskInfo(void)
51 {
52         DWORD                           dwReturn;
53         MCI_STATUS_PARMS        mciStatusParms;
54
55         mciStatusParms.dwItem = MCI_STATUS_READY;
56         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
57         if (dwReturn)
58         {
59                 Con_Print("CDAudio_SysGetAudioDiskInfo: drive ready test - get status failed\n");
60                 return -1;
61         }
62         if (!mciStatusParms.dwReturn)
63         {
64                 Con_Print("CDAudio_SysGetAudioDiskInfo: drive not ready\n");
65                 return -1;
66         }
67
68         mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
69         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
70         if (dwReturn)
71         {
72                 Con_Print("CDAudio_SysGetAudioDiskInfo: get tracks - status failed\n");
73                 return -1;
74         }
75         if (mciStatusParms.dwReturn < 1)
76         {
77                 Con_Print("CDAudio_SysGetAudioDiskInfo: no music tracks\n");
78                 return -1;
79         }
80
81         return mciStatusParms.dwReturn;
82 }
83
84
85 float CDAudio_SysGetVolume (void)
86 {
87         // IMPLEMENTME
88         return -1.0f;
89 }
90
91
92 void CDAudio_SysSetVolume (float volume)
93 {
94         // IMPLEMENTME
95 }
96
97
98 int CDAudio_SysPlay (qbyte track)
99 {
100         DWORD                           dwReturn;
101         MCI_PLAY_PARMS          mciPlayParms;
102         MCI_STATUS_PARMS        mciStatusParms;
103
104         // don't try to play a non-audio track
105         mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
106         mciStatusParms.dwTrack = track;
107         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
108         if (dwReturn)
109         {
110                 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
111                 return -1;
112         }
113         if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
114         {
115                 Con_Printf("CDAudio_SysPlay: track %i is not audio\n", track);
116                 return -1;
117         }
118
119         if (cdPlaying)
120                 CDAudio_Stop();
121
122         // get the length of the track to be played
123         mciStatusParms.dwItem = MCI_STATUS_LENGTH;
124         mciStatusParms.dwTrack = track;
125         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
126         if (dwReturn)
127         {
128                 Con_Printf("CDAudio_SysPlay: MCI_STATUS failed (%i)\n", dwReturn);
129                 return -1;
130         }
131
132         mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
133         mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
134         mciPlayParms.dwCallback = (DWORD)mainwindow;
135         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID) &mciPlayParms);
136         if (dwReturn)
137         {
138                 Con_Printf("CDAudio_SysPlay: MCI_PLAY failed (%i)\n", dwReturn);
139                 return -1;
140         }
141
142         return 0;
143 }
144
145
146 int CDAudio_SysStop (void)
147 {
148         DWORD   dwReturn;
149
150         if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL)))
151         {
152                 Con_Printf("MCI_STOP failed (%i)\n", dwReturn);
153                 return -1;
154         }
155         return 0;
156 }
157
158 int CDAudio_SysPause (void)
159 {
160         DWORD                           dwReturn;
161         MCI_GENERIC_PARMS       mciGenericParms;
162
163         mciGenericParms.dwCallback = (DWORD)mainwindow;
164         if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID) &mciGenericParms)))
165         {
166                 Con_Printf("MCI_PAUSE failed (%i)\n", dwReturn);
167                 return -1;
168         }
169         return 0;
170 }
171
172
173 int CDAudio_SysResume (void)
174 {
175         DWORD                   dwReturn;
176         MCI_PLAY_PARMS  mciPlayParms;
177
178         mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
179         mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
180         mciPlayParms.dwCallback = (DWORD)mainwindow;
181         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms);
182         if (dwReturn)
183         {
184                 Con_Printf("CDAudio_SysResume: MCI_PLAY failed (%i)\n", dwReturn);
185                 return -1;
186         }
187         return 0;       
188 }
189
190 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
191 {
192         if (lParam != (LPARAM)wDeviceID)
193                 return 1;
194
195         switch (wParam)
196         {
197                 case MCI_NOTIFY_SUCCESSFUL:
198                         if (cdPlaying)
199                         {
200                                 cdPlaying = false;
201                                 if (cdPlayLooping)
202                                         CDAudio_Play(cdPlayTrack, true);
203                         }
204                         break;
205
206                 case MCI_NOTIFY_ABORTED:
207                 case MCI_NOTIFY_SUPERSEDED:
208                         break;
209
210                 case MCI_NOTIFY_FAILURE:
211                         Con_Print("MCI_NOTIFY_FAILURE\n");
212                         CDAudio_Stop ();
213                         cdValid = false;
214                         break;
215
216                 default:
217                         Con_Printf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
218                         return 1;
219         }
220
221         return 0;
222 }
223
224
225 int CDAudio_SysUpdate (void)
226 {
227         return 0;
228 }
229
230 void CDAudio_SysInit (void)
231 {
232 }
233
234 int CDAudio_SysStartup (void)
235 {
236         DWORD   dwReturn;
237         MCI_OPEN_PARMS  mciOpenParms;
238         MCI_SET_PARMS   mciSetParms;
239
240         mciOpenParms.lpstrDeviceType = "cdaudio";
241         if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms)))
242         {
243                 Con_Printf("CDAudio_SysStartup: MCI_OPEN failed (%i)\n", dwReturn);
244                 return -1;
245         }
246         wDeviceID = mciOpenParms.wDeviceID;
247
248         // Set the time format to track/minute/second/frame (TMSF).
249         mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
250         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms)))
251         {
252                 Con_Printf("CDAudio_SysStartup: MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
253                 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD)NULL);
254                 return -1;
255         }
256
257         return 0;
258 }
259
260 void CDAudio_SysShutdown (void)
261 {
262         if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD)NULL))
263                 Con_Print("CDAudio_SysShutdown: MCI_CLOSE failed\n");
264 }