2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cd_sdl.c
|
|
|
|
|
|
|
|
SDL CD audio routines
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/cdaudio.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-06-01 22:55:33 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/sound.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/general.h"
|
|
|
|
#include "QF/plugin/cd.h"
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-08-31 00:16:31 +00:00
|
|
|
static plugin_t plugin_info;
|
|
|
|
static plugin_data_t plugin_info_data;
|
|
|
|
static plugin_funcs_t plugin_info_funcs;
|
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
static general_funcs_t plugin_info_general_funcs;
|
|
|
|
static cd_funcs_t plugin_info_cd_funcs;
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
static qboolean cdValid = false;
|
|
|
|
static qboolean initialized = false;
|
|
|
|
static qboolean enabled = true;
|
|
|
|
static qboolean playLooping = false;
|
|
|
|
|
2001-05-20 20:52:27 +00:00
|
|
|
static SDL_CD *cd_id;
|
2001-02-19 21:15:25 +00:00
|
|
|
static float cdvolume = 1.0;
|
|
|
|
|
2003-01-31 23:16:28 +00:00
|
|
|
static cvar_t *bgmvolume;
|
2001-05-20 20:52:27 +00:00
|
|
|
|
2004-02-07 05:35:15 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Eject (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDEject (cd_id))
|
2011-08-11 08:20:33 +00:00
|
|
|
Sys_MaskPrintf (SYS_SND, "Unable to eject CD-ROM tray.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause (void)
|
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
if (SDL_CDStatus (cd_id) != CD_PLAYING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDPause (cd_id))
|
2011-08-11 08:20:33 +00:00
|
|
|
Sys_MaskPrintf (SYS_SND, "CDAudio_Pause: Failed to pause track.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop (void)
|
|
|
|
{
|
|
|
|
int cdstate;
|
|
|
|
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
|
|
|
if ((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDStop (cd_id))
|
2011-08-11 08:20:33 +00:00
|
|
|
Sys_MaskPrintf (SYS_SND, "CDAudio_Stop: Failed to stop track.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-10-12 19:26:56 +00:00
|
|
|
I_CDAudio_Play (int track, qboolean looping)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
/* Initialize cd_stat to avoid warning */
|
|
|
|
/* XXX - Does this default value make sense? */
|
|
|
|
CDstatus cd_stat = CD_ERROR;
|
|
|
|
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!cdValid) {
|
2004-03-21 04:59:02 +00:00
|
|
|
cd_stat = SDL_CDStatus (cd_id);
|
|
|
|
if (!CD_INDRIVE (cd_stat) || (!cd_id->numtracks))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
cdValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((track < 1) || (track >= cd_id->numtracks)) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-01 22:55:33 +00:00
|
|
|
track--; // Convert track from person to SDL value
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cd_stat == CD_PLAYING) {
|
|
|
|
if (cd_id->cur_track == track)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_CDPlay (cd_id, cd_id->track[track].offset,
|
|
|
|
cd_id->track[track].length)) {
|
2011-08-11 08:20:33 +00:00
|
|
|
Sys_MaskPrintf (SYS_SND, "CDAudio_Play: Unable to play track: %d\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
track + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
playLooping = looping;
|
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
if (SDL_CDStatus (cd_id) != CD_PAUSED)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
if (SDL_CDResume (cd_id))
|
2012-01-20 19:58:19 +00:00
|
|
|
Sys_MaskPrintf (SYS_SND, "CDAudio_Resume: Failed to resume track.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-06-01 22:55:33 +00:00
|
|
|
if (!cd_id)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
|
|
|
SDL_CDClose (cd_id);
|
|
|
|
cd_id = NULL;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Update (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
if (bgmvolume->value != cdvolume) {
|
|
|
|
if (cdvolume) {
|
|
|
|
Cvar_SetValue (bgmvolume, 0.0);
|
2007-05-31 06:06:52 +00:00
|
|
|
I_CDAudio_Pause ();
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
|
|
|
Cvar_SetValue (bgmvolume, 1.0);
|
2007-05-31 06:06:52 +00:00
|
|
|
I_CDAudio_Resume ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
cdvolume = bgmvolume->value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (playLooping && (SDL_CDStatus (cd_id) != CD_PLAYING)
|
|
|
|
&& (SDL_CDStatus (cd_id) != CD_PAUSED))
|
2007-05-31 06:06:52 +00:00
|
|
|
I_CDAudio_Play (cd_id->cur_track + 1, true);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CD_f_DEFINED
|
2001-05-20 20:52:27 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CD_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *command;
|
2001-05-20 20:52:27 +00:00
|
|
|
int cdstate;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc () < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
command = Cmd_Argv (1);
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "on")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = true;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "off")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cd_id)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
|
|
|
if ((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "play")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), false);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "loop")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), true);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "stop")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "pause")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "resume")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "eject")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Eject ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "info")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cd_id)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%d tracks\n", cd_id->numtracks);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cdstate == CD_PLAYING)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Currently %s track %d\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing",
|
|
|
|
cd_id->cur_track + 1);
|
|
|
|
else if (cdstate == CD_PAUSED)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Paused %s track %d\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing",
|
|
|
|
cd_id->cur_track + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Init (void)
|
|
|
|
{
|
|
|
|
if (SDL_Init (SDL_INIT_CDROM) < 0) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Couldn't initialize SDL CD-AUDIO: %s\n", SDL_GetError ());
|
2001-06-01 22:55:33 +00:00
|
|
|
return; // was -1
|
|
|
|
}
|
|
|
|
cd_id = SDL_CDOpen (0);
|
|
|
|
if (!cd_id) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
|
2001-06-01 22:55:33 +00:00
|
|
|
SDL_GetError ());
|
|
|
|
return; // was -1
|
|
|
|
}
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
enabled = true;
|
|
|
|
cdValid = true;
|
|
|
|
|
|
|
|
if (!CD_INDRIVE (SDL_CDStatus (cd_id))) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: No CD in drive.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
cdValid = false;
|
|
|
|
}
|
|
|
|
if (!cd_id->numtracks) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: CD contains no audio tracks.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
cdValid = false;
|
|
|
|
}
|
2003-01-31 23:16:28 +00:00
|
|
|
|
|
|
|
bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, NULL,
|
|
|
|
"Volume of CD music");
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CD Audio Initialized.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:34:57 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
|
|
|
I_CDAudio_Init,
|
|
|
|
I_CDAudio_Shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static cd_funcs_t plugin_info_cd_funcs = {
|
|
|
|
I_CD_f,
|
|
|
|
I_CDAudio_Pause,
|
|
|
|
I_CDAudio_Play,
|
|
|
|
I_CDAudio_Resume,
|
|
|
|
I_CDAudio_Update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
|
|
|
&plugin_info_general_funcs,
|
|
|
|
0,
|
|
|
|
&plugin_info_cd_funcs,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_data_t plugin_info_data = {
|
|
|
|
&plugin_info_general_data,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_t plugin_info = {
|
|
|
|
qfp_cd,
|
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
|
|
|
"SDL CD Audio output\n",
|
2004-02-07 05:35:15 +00:00
|
|
|
"Copyright (C) 2001 contributors of the QuakeForge project\n"
|
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors\n",
|
2004-01-20 08:34:57 +00:00
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
PLUGIN_INFO (cd, sdl)
|
|
|
|
{
|
2001-06-01 22:55:33 +00:00
|
|
|
return &plugin_info;
|
|
|
|
}
|