📄 cd_win.pas
字号:
if (dwReturn <> 0) then
begin
Com_DPrintf('CDAudio: MCI_PLAY failed (%d)'#10, [dwReturn]);
exit;
end;
playing := true;
end;
procedure CD_f; cdecl;
const
pscLooping: PChar = 'looping';
pscPlaying: PChar = 'playing';
var
command, DisplayMes: PChar;
ret, n: Integer;
begin
if (Cmd_Argc < 2) then
Exit;
command := Cmd_Argv(1);
{ TODO: if (Q_strcasecmp(command, 'on') == 0) }
if (StrComp(command, 'on') = 0) then
begin
enabled := true;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, 'off') == 0) }
if (StrComp(command, 'off') = 0) then
begin
if playing then
CDAudio_Stop;
enabled := false;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "reset") == 0) }
if (StrComp(command, 'reset') = 0) then
begin
enabled := true;
if playing then
CDAudio_Stop();
for n := 0 to 99 do
remap[n] := n;
CDAudio_GetAudioDiskInfo;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "remap") == 0) }
if (StrComp(command, 'remap') = 0) then
begin
ret := Cmd_Argc - 2;
if (ret <= 0) then
begin
for n := 1 to 99 do
if (remap[n] <> n) then
Com_Printf(' %u -> %u'#10, [n, remap[n]]);
Exit;
end;
for n := 1 to (ret - 1) do
remap[n] := StrToInt(Cmd_Argv (n + 1));
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "close") == 0) }
if (StrComp(command, 'close') = 0) then
begin
CDAudio_CloseDoor;
Exit;
end;
if (NOT cdValid) then
begin
CDAudio_GetAudioDiskInfo;
if (NOT cdValid) then
begin
Com_Printf('No CD in player.'#10, []);
Exit;
end;
end;
{ TODO: if (Q_strcasecmp(command, "play") == 0) }
if (StrComp(command, 'play') = 0) then
begin
CDAudio_Play(StrToInt(Cmd_Argv(2)), false);
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "loop") == 0) }
if (StrComp(command, 'loop') = 0) then
begin
CDAudio_Play(StrToInt(Cmd_Argv(2)), true);
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "stop") == 0) }
if (StrComp(command, 'stop') = 0) then
begin
CDAudio_Stop;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "pause") == 0) }
if (StrComp(command, 'pause') = 0) then
begin
CDAudio_Pause;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "resume") == 0) }
if (StrComp(command, 'resume') = 0) then
begin
CDAudio_Resume;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "eject") == 0) }
if (StrComp(command, 'eject') = 0) then
begin
if (playing) then
CDAudio_Stop;
CDAudio_Eject;
cdValid := false;
Exit;
end;
{ TODO: if (Q_strcasecmp(command, "info") == 0) }
if (StrComp(command, 'info') = 0) then
begin
Com_Printf('%u tracks'#10, [maxTrack]);
if (playing) then begin
if playLooping then
DisplayMes := pscLooping
else DisplayMes := pscPlaying;
Com_Printf('Currently %s track %u'#10, [DisplayMes, playTrack]);
end else if (wasPlaying) then
begin
if playLooping then
DisplayMes := pscLooping
else DisplayMes := pscPlaying;
Com_Printf('Paused %s track %u'#10, [DisplayMes, playTrack]);
end;
end;
end;
function CDAudio_MessageHandler(hWin: HWND; uMsg: Cardinal; wParam: WPARAM; lParam: LPARAM): Integer;
begin
if (lParam <> Integer(wDeviceID)) then
begin
Result := 1;
Exit;
end;
case wParam of
MCI_NOTIFY_SUCCESSFUL: begin
if playing then
begin
playing := false;
if playLooping then
begin
{ if the track has played the given number of times,
go to the ambient track }
Inc(loopcounter);
if (loopcounter >= cd_loopcount.value) then
CDAudio_Play2(Round(cd_looptrack.value), true)
else
CDAudio_Play2(playTrack, true);
end;
end;
end;
MCI_NOTIFY_ABORTED, MCI_NOTIFY_SUPERSEDED: begin
{ Do Nothing - especially not default }
end;
MCI_NOTIFY_FAILURE: begin
Com_DPrintf('MCI_NOTIFY_FAILURE'#10, []);
CDAudio_Stop;
cdValid := false;
end;
else
Com_DPrintf('Unexpected MM_MCINOTIFY type (%d)'#10, [wParam]);
Result := 1;
Exit;
end;
Result := 0;
end;
procedure CDAudio_Update;
begin
if (cd_nocd.value <> Integer(NOT enabled)) then
begin
if (cd_nocd.value <> 0) then
begin
CDAudio_Stop;
enabled := false;
end
else
begin
enabled := true;
CDAudio_Resume;
end;
end;
end;
function CDAudio_Init: Integer;
var
dwReturn: DWORD;
mciOpenParms: MCI_OPEN_PARMS;
mciSetParms: MCI_SET_PARMS;
n: Integer;
begin
Result := -1;
cd_nocd := Cvar_Get('cd_nocd', '0', CVAR_ARCHIVE);
cd_loopcount := Cvar_Get('cd_loopcount', '4', 0);
cd_looptrack := Cvar_Get('cd_looptrack', '11', 0);
if (cd_nocd.value <> 0) then
Exit;
mciOpenParms.lpstrDeviceType := 'cdaudio';
dwReturn := mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE OR MCI_OPEN_SHAREABLE, dword(@mciOpenParms));
if (dwReturn <> 0) then
begin
Com_Printf('CDAudio_Init: MCI_OPEN failed (%d)'#10, [dwReturn]);
Exit;
end;
wDeviceID := mciOpenParms.wDeviceID;
{ Set the time format to track/minute/second/frame (TMSF). }
mciSetParms.dwTimeFormat := MCI_FORMAT_TMSF;
dwReturn := mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, dword(@mciSetParms));
if (dwReturn <> 0) then
begin
Com_Printf('MCI_SET_TIME_FORMAT failed (%d)'#10, [dwReturn]);
mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
Exit;
end;
for n := 0 to 99 do
remap[n] := n;
initialized := true;
enabled := true;
if CDAudio_GetAudioDiskInfo <> 0 then
begin
// Com_Printf('CDAudio_Init: No CD in player.'#10);
cdValid := false;
enabled := false;
end;
Cmd_AddCommand('cd', CD_f);
Com_Printf('CD Audio Initialized'#10, []);
Result := 0;
end;
procedure CDAudio_Shutdown;
begin
if (NOT initialized) then
Exit;
CDAudio_Stop;
if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, 0) <> 0) then
Com_DPrintf('CDAudio_Shutdown: MCI_CLOSE failed'#10, []);
end;
(* ===========
CDAudio_Activate
Called when the main window gains or loses focus.
The window have been destroyed and recreated
between a deactivate and an activate.
=========== *)
procedure CDAudio_Activate(active: qboolean);
begin
if active then
CDAudio_Resume
else
CDAudio_Pause;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -