]> icculus.org git repositories - divverent/darkplaces.git/blob - cd_win.c
added -novorbis commandline option to allow disabling ogg vorbis support even if...
[divverent/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
27
28 extern  HWND    mainwindow;
29
30 UINT    wDeviceID;
31
32 void CDAudio_SysEject(void)
33 {
34         DWORD   dwReturn;
35
36         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL)))
37                 Con_DPrintf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
38 }
39
40
41 void CDAudio_SysCloseDoor(void)
42 {
43         DWORD   dwReturn;
44
45         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL)))
46                 Con_DPrintf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
47 }
48
49 int CDAudio_SysGetAudioDiskInfo(void)
50 {
51         DWORD                           dwReturn;
52         MCI_STATUS_PARMS        mciStatusParms;
53
54         mciStatusParms.dwItem = MCI_STATUS_READY;
55         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
56         if (dwReturn)
57         {
58                 Con_DPrint("CDAudio: drive ready test - get status failed\n");
59                 return -1;
60         }
61         if (!mciStatusParms.dwReturn)
62         {
63                 Con_DPrint("CDAudio: drive not ready\n");
64                 return -1;
65         }
66
67         mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
68         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
69         if (dwReturn)
70         {
71                 Con_DPrint("CDAudio: get tracks - status failed\n");
72                 return -1;
73         }
74         if (mciStatusParms.dwReturn < 1)
75         {
76                 Con_DPrint("CDAudio: no music tracks\n");
77                 return -1;
78         }
79
80         return mciStatusParms.dwReturn;
81 }
82
83
84 float CDAudio_SysGetVolume (void)
85 {
86         // IMPLEMENTME
87         return -1.0f;
88 }
89
90
91 void CDAudio_SysSetVolume (float volume)
92 {
93         // IMPLEMENTME
94 }
95
96
97 int CDAudio_SysPlay (qbyte track)
98 {
99         DWORD                           dwReturn;
100         MCI_PLAY_PARMS          mciPlayParms;
101         MCI_STATUS_PARMS        mciStatusParms;
102
103         // don't try to play a non-audio track
104         mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
105         mciStatusParms.dwTrack = track;
106         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
107         if (dwReturn)
108         {
109                 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
110                 return -1;
111         }
112         if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO)
113         {
114                 Con_Printf("CDAudio: track %i is not audio\n", track);
115                 return -1;
116         }
117
118         if (cdPlaying)
119                 CDAudio_Stop();
120
121         // get the length of the track to be played
122         mciStatusParms.dwItem = MCI_STATUS_LENGTH;
123         mciStatusParms.dwTrack = track;
124         dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
125         if (dwReturn)
126         {
127                 Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
128                 return -1;
129         }
130
131         mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
132         mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
133         mciPlayParms.dwCallback = (DWORD)mainwindow;
134         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID) &mciPlayParms);
135         if (dwReturn)
136         {
137                 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
138                 return -1;
139         }
140
141         return 0;
142 }
143
144
145 int CDAudio_SysStop (void)
146 {
147         DWORD   dwReturn;
148
149         if ((dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL)))
150         {
151                 Con_DPrintf("MCI_STOP failed (%i)\n", dwReturn);
152                 return -1;
153         }
154         return 0;
155 }
156
157 int CDAudio_SysPause (void)
158 {
159         DWORD                           dwReturn;
160         MCI_GENERIC_PARMS       mciGenericParms;
161
162         mciGenericParms.dwCallback = (DWORD)mainwindow;
163         if ((dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID) &mciGenericParms)))
164         {
165                 Con_DPrintf("MCI_PAUSE failed (%i)\n", dwReturn);
166                 return -1;
167         }
168         return 0;
169 }
170
171
172 int CDAudio_SysResume (void)
173 {
174         DWORD                   dwReturn;
175         MCI_PLAY_PARMS  mciPlayParms;
176
177         mciPlayParms.dwFrom = MCI_MAKE_TMSF(cdPlayTrack, 0, 0, 0);
178         mciPlayParms.dwTo = MCI_MAKE_TMSF(cdPlayTrack + 1, 0, 0, 0);
179         mciPlayParms.dwCallback = (DWORD)mainwindow;
180         dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms);
181         if (dwReturn)
182         {
183                 Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
184                 return -1;
185         }
186         return 0;       
187 }
188
189 LONG CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
190 {
191         if (lParam != (LPARAM)wDeviceID)
192                 return 1;
193
194         switch (wParam)
195         {
196                 case MCI_NOTIFY_SUCCESSFUL:
197                         if (cdPlaying)
198                         {
199                                 cdPlaying = false;
200                                 if (cdPlayLooping)
201                                         CDAudio_Play(cdPlayTrack, true);
202                         }
203                         break;
204
205                 case MCI_NOTIFY_ABORTED:
206                 case MCI_NOTIFY_SUPERSEDED:
207                         break;
208
209                 case MCI_NOTIFY_FAILURE:
210                         Con_DPrint("MCI_NOTIFY_FAILURE\n");
211                         CDAudio_Stop ();
212                         cdValid = false;
213                         break;
214
215                 default:
216                         Con_DPrintf("Unexpected MM_MCINOTIFY type (%i)\n", wParam);
217                         return 1;
218         }
219
220         return 0;
221 }
222
223
224 int CDAudio_SysUpdate (void)
225 {
226         return 0;
227 }
228
229 void CDAudio_SysInit (void)
230 {
231 }
232
233 int CDAudio_SysStartup (void)
234 {
235         DWORD   dwReturn;
236         MCI_OPEN_PARMS  mciOpenParms;
237         MCI_SET_PARMS   mciSetParms;
238
239         mciOpenParms.lpstrDeviceType = "cdaudio";
240         if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms)))
241         {
242                 Con_Printf("CDAudio_Init: MCI_OPEN failed (%i)\n", dwReturn);
243                 return -1;
244         }
245         wDeviceID = mciOpenParms.wDeviceID;
246
247         // Set the time format to track/minute/second/frame (TMSF).
248         mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
249         if ((dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms)))
250         {
251                 Con_Printf("MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
252                 mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD)NULL);
253                 return -1;
254         }
255
256         return 0;
257 }
258
259 void CDAudio_SysShutdown (void)
260 {
261         if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD)NULL))
262                 Con_DPrint("CDAudio_Shutdown: MCI_CLOSE failed\n");
263 }