mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
Minor cd_sdl.c cleanups from uhexen2. Reorganized cdaudio volume
handling. If volume is 0, don't bother advancing and pause. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@351 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
d0ae9d2d65
commit
f4b0b373cb
1 changed files with 33 additions and 33 deletions
|
@ -108,14 +108,12 @@ void CDAudio_Play(byte track, qboolean looping)
|
||||||
{
|
{
|
||||||
if (playTrack == track)
|
if (playTrack == track)
|
||||||
return;
|
return;
|
||||||
CDAudio_Stop ();
|
CDAudio_Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_CDPlay(cd_handle, cd_handle->track[track-1].offset, cd_handle->track[track-1].length) == -1)
|
if (SDL_CDPlay(cd_handle, cd_handle->track[track-1].offset, cd_handle->track[track-1].length) == -1)
|
||||||
{
|
{
|
||||||
// ok, check for status now
|
|
||||||
int cd_status = SDL_CDStatus(cd_handle);
|
int cd_status = SDL_CDStatus(cd_handle);
|
||||||
|
|
||||||
if (cd_status > 0)
|
if (cd_status > 0)
|
||||||
Con_Printf ("CDAudio_Play: Unable to play %d: %s\n", track, SDL_GetError ());
|
Con_Printf ("CDAudio_Play: Unable to play %d: %s\n", track, SDL_GetError ());
|
||||||
return;
|
return;
|
||||||
|
@ -137,7 +135,7 @@ void CDAudio_Play(byte track, qboolean looping)
|
||||||
endOfTrack += 2.0;
|
endOfTrack += 2.0;
|
||||||
pausetime = -1.0;
|
pausetime = -1.0;
|
||||||
|
|
||||||
if (!hw_vol_works && bgmvolume.value == 0.0)
|
if (bgmvolume.value == 0) /* don't bother advancing */
|
||||||
CDAudio_Pause ();
|
CDAudio_Pause ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,12 +267,12 @@ static void CD_f (void)
|
||||||
|
|
||||||
if (Q_strcasecmp(command, "remap") == 0)
|
if (Q_strcasecmp(command, "remap") == 0)
|
||||||
{
|
{
|
||||||
ret = Cmd_Argc () - 2;
|
ret = Cmd_Argc() - 2;
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
{
|
{
|
||||||
for (n = 1; n < 100; n++)
|
for (n = 1; n < 100; n++)
|
||||||
if (remap[n] != n)
|
if (remap[n] != n)
|
||||||
Con_Printf (" %u -> %u\n", n, remap[n]);
|
Con_Printf(" %u -> %u\n", n, remap[n]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (n = 1; n <= ret; n++)
|
for (n = 1; n <= ret; n++)
|
||||||
|
@ -284,7 +282,7 @@ static void CD_f (void)
|
||||||
|
|
||||||
if (!cdValid)
|
if (!cdValid)
|
||||||
{
|
{
|
||||||
CDAudio_GetAudioDiskInfo ();
|
CDAudio_GetAudioDiskInfo();
|
||||||
if (!cdValid)
|
if (!cdValid)
|
||||||
{
|
{
|
||||||
Con_Printf("No CD in player.\n");
|
Con_Printf("No CD in player.\n");
|
||||||
|
@ -359,9 +357,9 @@ static void CD_f (void)
|
||||||
Con_Printf ("%u tracks\n", cd_handle->numtracks);
|
Con_Printf ("%u tracks\n", cd_handle->numtracks);
|
||||||
|
|
||||||
if (playing)
|
if (playing)
|
||||||
Con_Printf ("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
|
Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
|
||||||
else if (wasPlaying)
|
else if (wasPlaying)
|
||||||
Con_Printf ("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
|
Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
|
||||||
|
|
||||||
if (playing || wasPlaying)
|
if (playing || wasPlaying)
|
||||||
{
|
{
|
||||||
|
@ -373,7 +371,7 @@ static void CD_f (void)
|
||||||
current_min, current_sec, current_frame * 60 / CD_FPS,
|
current_min, current_sec, current_frame * 60 / CD_FPS,
|
||||||
length_min, length_sec, length_frame * 60 / CD_FPS);
|
length_min, length_sec, length_frame * 60 / CD_FPS);
|
||||||
}
|
}
|
||||||
Con_Printf ("Volume is %f\n", bgmvolume.value);
|
Con_Printf("Volume is %f\n", bgmvolume.value);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -394,30 +392,28 @@ static qboolean CD_SetVolume (void *unused)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qboolean CDAudio_SetVolume (cvar_t *var)
|
static qboolean CDAudio_SetVolume (float value)
|
||||||
{
|
{
|
||||||
if (!cd_handle || !enabled)
|
if (!cd_handle || !enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (var->value < 0.0)
|
old_cdvolume = value;
|
||||||
Cvar_SetValue (var->name, 0.0);
|
|
||||||
else if (var->value > 1.0)
|
if (value == 0.0f)
|
||||||
Cvar_SetValue (var->name, 1.0);
|
CDAudio_Pause ();
|
||||||
old_cdvolume = var->value;
|
else
|
||||||
if (hw_vol_works)
|
CDAudio_Resume();
|
||||||
|
|
||||||
|
if (!hw_vol_works)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* FIXME: write proper code in here when SDL
|
/* FIXME: write proper code in here when SDL
|
||||||
supports cdrom volume control some day. */
|
supports cdrom volume control some day. */
|
||||||
return CD_SetVolume (NULL);
|
return CD_SetVolume (NULL);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (old_cdvolume == 0.0)
|
|
||||||
CDAudio_Pause ();
|
|
||||||
else
|
|
||||||
CDAudio_Resume();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDAudio_Update(void)
|
void CDAudio_Update(void)
|
||||||
|
@ -428,7 +424,13 @@ void CDAudio_Update(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (old_cdvolume != bgmvolume.value)
|
if (old_cdvolume != bgmvolume.value)
|
||||||
CDAudio_SetVolume (&bgmvolume);
|
{
|
||||||
|
if (bgmvolume.value < 0)
|
||||||
|
Cvar_Set ("bgmvolume", "0.0");
|
||||||
|
else if (bgmvolume.value > 1)
|
||||||
|
Cvar_Set ("bgmvolume", "1.0");
|
||||||
|
CDAudio_SetVolume (bgmvolume.value);
|
||||||
|
}
|
||||||
|
|
||||||
if (playing && realtime > endOfTrack)
|
if (playing && realtime > endOfTrack)
|
||||||
{
|
{
|
||||||
|
@ -554,7 +556,7 @@ int CDAudio_Init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cd_dev == -1)
|
if (cd_dev == -1)
|
||||||
cd_dev = 0; // default drive
|
cd_dev = 0; /* default drive */
|
||||||
|
|
||||||
cd_handle = SDL_CDOpen(cd_dev);
|
cd_handle = SDL_CDOpen(cd_dev);
|
||||||
if (!cd_handle)
|
if (!cd_handle)
|
||||||
|
@ -579,10 +581,9 @@ int CDAudio_Init(void)
|
||||||
|
|
||||||
Cmd_AddCommand ("cd", CD_f);
|
Cmd_AddCommand ("cd", CD_f);
|
||||||
|
|
||||||
// cd hardware volume: no SDL support at present.
|
hw_vol_works = CD_GetVolume (NULL); /* no SDL support at present. */
|
||||||
hw_vol_works = CD_GetVolume (NULL);
|
|
||||||
if (hw_vol_works)
|
if (hw_vol_works)
|
||||||
hw_vol_works = CDAudio_SetVolume (&bgmvolume);
|
hw_vol_works = CDAudio_SetVolume (bgmvolume.value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -592,9 +593,8 @@ void CDAudio_Shutdown(void)
|
||||||
if (!cd_handle)
|
if (!cd_handle)
|
||||||
return;
|
return;
|
||||||
CDAudio_Stop();
|
CDAudio_Stop();
|
||||||
// cd hardware volume: no SDL support at present.
|
if (hw_vol_works)
|
||||||
// if (hw_vol_works)
|
CD_SetVolume (NULL); /* no SDL support at present. */
|
||||||
// CD_SetVolume (NULL);
|
|
||||||
SDL_CDClose(cd_handle);
|
SDL_CDClose(cd_handle);
|
||||||
cd_handle = NULL;
|
cd_handle = NULL;
|
||||||
cd_dev = -1;
|
cd_dev = -1;
|
||||||
|
|
Loading…
Reference in a new issue