X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=cd_shared.c;h=aa33079dd2ea55710e50481907f3a85cb5918734;hb=4eb6393c19467e2a1e45913397aaf11380d1cd83;hp=876a0a78da7a89f494b18ea0a437ccfa060793c6;hpb=d6d1a3a746c459e53830bb1049b49a2f22b14e93;p=xonotic%2Fdarkplaces.git diff --git a/cd_shared.c b/cd_shared.c index 876a0a78..aa33079d 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "cdaudio.h" -#include "snd_main.h" +#include "sound.h" #define MAXTRACKS 256 @@ -32,7 +32,7 @@ extern void CDAudio_SysCloseDoor (void); extern int CDAudio_SysGetAudioDiskInfo (void); extern float CDAudio_SysGetVolume (void); extern void CDAudio_SysSetVolume (float volume); -extern int CDAudio_SysPlay (qbyte track); +extern int CDAudio_SysPlay (unsigned char track); extern int CDAudio_SysStop (void); extern int CDAudio_SysPause (void); extern int CDAudio_SysResume (void); @@ -42,14 +42,15 @@ extern int CDAudio_SysStartup (void); extern void CDAudio_SysShutdown (void); // used by menu to ghost CD audio slider -cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"}; +cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0","indicates if CD Audio system is active"}; static qboolean wasPlaying = false; static qboolean initialized = false; static qboolean enabled = false; static float cdvolume; -static qbyte remap[MAXTRACKS]; -static qbyte maxTrack; +typedef char filename_t[MAX_QPATH]; +static filename_t remap[MAXTRACKS]; +static unsigned char maxTrack; static int faketrack = -1; static float saved_vol = 1.0f; @@ -58,8 +59,9 @@ static float saved_vol = 1.0f; qboolean cdValid = false; qboolean cdPlaying = false; qboolean cdPlayLooping = false; -qbyte cdPlayTrack; +unsigned char cdPlayTrack; +cl_cdstate_t cd; static void CDAudio_Eject (void) { @@ -95,8 +97,9 @@ static int CDAudio_GetAudioDiskInfo (void) } -void CDAudio_Play (qbyte track, qboolean looping) +void CDAudio_Play_byName (const char *trackname, qboolean looping) { + unsigned int track; sfx_t* sfx; Host_StartVideo(); @@ -104,21 +107,47 @@ void CDAudio_Play (qbyte track, qboolean looping) if (!enabled) return; - track = remap[track]; - if (track < 1) + if(strspn(trackname, "0123456789") == strlen(trackname)) { - Con_Printf("CDAudio: Bad track number %u.\n", track); - return; + track = (unsigned char) atoi(trackname); + if(track > 0 && track < MAXTRACKS) + if(*remap[track]) + trackname = remap[track]; } + if(strspn(trackname, "0123456789") == strlen(trackname)) + { + track = (unsigned char) atoi(trackname); + if (track < 1) + { + Con_Printf("CDAudio: Bad track number %u.\n", track); + return; + } + } + else + track = 0; + if (cdPlaying && cdPlayTrack == track && faketrack == -1) return; CDAudio_Stop (); // Try playing a fake track (sound file) first - sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, false); - if (sfx == NULL || sfx->fetcher == NULL) - sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, false); + if(track >= 1) + { + sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, false); + if (sfx == NULL || !S_IsSoundPrecached (sfx)) + sfx = S_PrecacheSound (va ("cdtracks/track%03u.wav", track), false, false); + if (sfx == NULL || !S_IsSoundPrecached (sfx)) + sfx = S_PrecacheSound (va ("cdtracks/track%02u", track), false, false); + if (sfx == NULL || !S_IsSoundPrecached (sfx)) + sfx = S_PrecacheSound (va ("cdtracks/track%03u", track), false, false); + } + else + { + sfx = S_PrecacheSound (va("cdtracks/%s.wav", trackname), false, false); + if (sfx == NULL || !S_IsSoundPrecached (sfx)) + sfx = S_PrecacheSound (va("cdtracks/%s", trackname), false, false); + } if (sfx != NULL) { faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0); @@ -127,13 +156,22 @@ void CDAudio_Play (qbyte track, qboolean looping) if (looping) S_SetChannelFlag (faketrack, CHANNELFLAG_FORCELOOP, true); S_SetChannelFlag (faketrack, CHANNELFLAG_FULLVOLUME, true); - Con_Printf ("Fake CD track %u playing...\n", track); + if(track >= 1) + Con_Printf ("Fake CD track %u playing...\n", track); + else + Con_Printf ("BGM track %s playing...\n", trackname); } } // If we can't play a fake CD track, try the real one if (faketrack == -1) { + if(track < 1) + { + Con_Print("Could not load BGM track.\n"); + return; + } + if (!cdValid) { CDAudio_GetAudioDiskInfo(); @@ -162,18 +200,24 @@ void CDAudio_Play (qbyte track, qboolean looping) CDAudio_Pause (); } +void CDAudio_Play (unsigned char track, qboolean looping) +{ + char buf[20]; + dpsnprintf(buf, sizeof(buf), "%d", (int) track); + CDAudio_Play_byName(buf, looping); +} void CDAudio_Stop (void) { - if (!enabled || !cdPlaying) + if (!enabled) return; if (faketrack != -1) { - S_StopChannel (faketrack); + S_StopChannel (faketrack, true); faketrack = -1; } - else if (CDAudio_SysStop() == -1) + else if (cdPlaying && (CDAudio_SysStop() == -1)) return; wasPlaying = false; @@ -218,6 +262,9 @@ static void CD_f (void) command = Cmd_Argv (1); + if (strcasecmp(command, "remap") != 0) + Host_StartVideo(); + if (strcasecmp(command, "on") == 0) { enabled = true; @@ -238,7 +285,7 @@ static void CD_f (void) if (cdPlaying) CDAudio_Stop(); for (n = 0; n < MAXTRACKS; n++) - remap[n] = n; + *remap[n] = 0; // empty string, that is, unremapped CDAudio_GetAudioDiskInfo(); return; } @@ -249,12 +296,12 @@ static void CD_f (void) if (ret <= 0) { for (n = 1; n < MAXTRACKS; n++) - if (remap[n] != n) - Con_Printf(" %u -> %u\n", n, remap[n]); + if (*remap[n]) + Con_Printf(" %u -> %s\n", n, remap[n]); return; } for (n = 1; n <= ret; n++) - remap[n] = atoi(Cmd_Argv (n+1)); + strlcpy(remap[n], Cmd_Argv (n+1), sizeof(*remap)); return; } @@ -266,13 +313,13 @@ static void CD_f (void) if (strcasecmp(command, "play") == 0) { - CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false); + CDAudio_Play_byName(Cmd_Argv (2), false); return; } if (strcasecmp(command, "loop") == 0) { - CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true); + CDAudio_Play_byName(Cmd_Argv (2), true); return; } @@ -317,6 +364,20 @@ static void CD_f (void) Con_Printf("Volume is %f\n", cdvolume); return; } + + Con_Printf("CD commands:\n"); + Con_Printf("cd on - enables CD audio system\n"); + Con_Printf("cd off - stops and disables CD audio system\n"); + Con_Printf("cd reset - resets CD audio system (clears track remapping and re-reads disc information)"); + Con_Printf("cd remap [remap2] [remap3] [...] - chooses (possibly emulated) CD tracks to play when a map asks for a particular track, this has many uses\n"); + Con_Printf("cd close - closes CD tray\n"); + Con_Printf("cd eject - stops playing music and opens CD tray to allow you to change disc\n"); + Con_Printf("cd play - plays selected track in remapping table\n"); + Con_Printf("cd loop - plays and repeats selected track in remapping table\n"); + Con_Printf("cd stop - stops playing current CD track\n"); + Con_Printf("cd pause - pauses CD playback\n"); + Con_Printf("cd resume - unpauses CD playback\n"); + Con_Printf("cd info - prints basic disc information (number of tracks, currently playing track, volume level)\n"); } void CDAudio_SetVolume (float newvol) @@ -361,25 +422,28 @@ int CDAudio_Init (void) return -1; // COMMANDLINEOPTION: Sound: -nocdaudio disables CD audio support - if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe")) + if (COM_CheckParm("-nocdaudio")) return -1; CDAudio_SysInit(); for (i = 0; i < MAXTRACKS; i++) - remap[i] = i; + *remap[i] = 0; Cvar_RegisterVariable(&cdaudioinitialized); Cvar_SetValueQuick(&cdaudioinitialized, true); enabled = true; - Cmd_AddCommand("cd", CD_f); + Cmd_AddCommand("cd", CD_f, "execute a CD drive command (cd on/off/reset/remap/close/play/loop/stop/pause/resume/eject/info) - use cd by itself for usage"); return 0; } int CDAudio_Startup (void) { + if (COM_CheckParm("-nocdaudio")) + return -1; + CDAudio_SysStartup (); if (CDAudio_GetAudioDiskInfo())