2004-01-20 06:58:42 +00:00
|
|
|
/*
|
|
|
|
cd_ogg.c
|
|
|
|
|
|
|
|
ogg music support
|
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2004 Andrew Pilley
|
|
|
|
Copyright (C) 2004 Bill Currie <taniwha@quakeforge.net>
|
|
|
|
Copyright (C) 2004 Jeff Teunissen <deek@quakeforge.net>
|
2004-01-20 06:58:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "QF/cdaudio.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
2004-02-07 05:35:15 +00:00
|
|
|
#include "QF/dstring.h"
|
2021-03-21 07:13:03 +00:00
|
|
|
#include "QF/plist.h"
|
2004-01-20 06:58:42 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/quakeio.h"
|
|
|
|
#include "QF/sound.h"
|
2004-02-07 05:35:15 +00:00
|
|
|
#include "QF/sys.h"
|
2004-02-07 04:47:38 +00:00
|
|
|
#include "QF/va.h"
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/general.h"
|
|
|
|
#include "QF/plugin/cd.h"
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
/* Generic plugin structures */
|
2004-01-20 06:58:42 +00:00
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
static general_funcs_t plugin_info_general_funcs;
|
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
/* global status variables. */
|
2004-02-06 15:16:50 +00:00
|
|
|
static qboolean playing = false;
|
|
|
|
static qboolean wasPlaying = false;
|
|
|
|
static qboolean mus_enabled = false;
|
2004-02-07 05:35:15 +00:00
|
|
|
static qboolean ogglistvalid = false;
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
/* sound resources */
|
2004-01-21 02:52:12 +00:00
|
|
|
static channel_t *cd_channel;
|
2004-02-07 05:35:15 +00:00
|
|
|
static plitem_t *tracklist = NULL; // parsed tracklist, dictionary format
|
2007-05-06 11:50:49 +00:00
|
|
|
static plitem_t *play_list; // string or array of strings
|
|
|
|
static int play_pos = -1; // position in play_list (0 for string)
|
|
|
|
// -1 = invalid (both)
|
2004-02-06 05:44:54 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static float bgmvolume;
|
|
|
|
static cvar_t bgmvolume_cvar = {
|
|
|
|
.name = "bgmvolume",
|
|
|
|
.description =
|
|
|
|
"Volume of CD music",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &bgmvolume },
|
|
|
|
};
|
|
|
|
static char *mus_ogglist;
|
|
|
|
static cvar_t mus_ogglist_cvar = {
|
|
|
|
.name = "mus_ogglist",
|
|
|
|
.description =
|
|
|
|
"filename of track to music file map",
|
|
|
|
.default_value = "tracklist.cfg",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = 0, .value = &mus_ogglist },
|
|
|
|
};
|
2004-01-20 06:58:42 +00:00
|
|
|
|
|
|
|
|
2004-01-21 19:35:17 +00:00
|
|
|
static void
|
|
|
|
set_volume (void)
|
|
|
|
{
|
2022-06-03 06:20:41 +00:00
|
|
|
if (cd_channel) {
|
|
|
|
S_ChannelSetVolume (cd_channel, bgmvolume);
|
2004-01-21 19:35:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_CloseDoor (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
I_OGGMus_Eject (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
/* stop playback of music */
|
|
|
|
static void
|
|
|
|
I_OGGMus_Stop (void)
|
|
|
|
{
|
2004-02-06 15:16:50 +00:00
|
|
|
if (!tracklist || !mus_enabled || !playing)
|
2004-02-06 05:44:54 +00:00
|
|
|
return;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
playing = false;
|
2004-02-06 15:16:50 +00:00
|
|
|
wasPlaying = false;
|
2004-02-06 05:44:54 +00:00
|
|
|
|
2007-03-18 12:54:59 +00:00
|
|
|
if (cd_channel) {
|
2022-06-03 06:20:41 +00:00
|
|
|
S_ChannelFree (cd_channel);
|
2007-03-18 12:54:59 +00:00
|
|
|
cd_channel = NULL;
|
2004-02-06 05:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
I_OGGMus_Shutdown (void)
|
|
|
|
{
|
2004-02-06 15:16:50 +00:00
|
|
|
if (tracklist) {
|
2004-02-06 05:44:54 +00:00
|
|
|
I_OGGMus_Stop ();
|
|
|
|
PL_Free (tracklist);
|
|
|
|
tracklist = NULL;
|
|
|
|
}
|
|
|
|
mus_enabled = false;
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
/* we've opened the trackmap file from the quake resources
|
|
|
|
* go through it, and make ourselves a tracklist map */
|
|
|
|
static int
|
2004-02-06 05:44:54 +00:00
|
|
|
Load_Tracklist (void)
|
2004-01-20 06:58:42 +00:00
|
|
|
{
|
2004-02-07 04:47:38 +00:00
|
|
|
QFile *oggfile = NULL;
|
|
|
|
char *buffile = NULL;
|
2014-01-23 02:57:57 +00:00
|
|
|
int size;
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
/* kill off the old tracklist, and make sure we're not playing anything */
|
|
|
|
I_OGGMus_Shutdown ();
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
ogglistvalid = false;
|
2004-02-06 05:44:54 +00:00
|
|
|
mus_enabled = false;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (!mus_ogglist || strequal (mus_ogglist, "none")) {
|
2004-02-07 05:35:15 +00:00
|
|
|
return -1; // bail if we don't have a valid filename
|
2004-02-06 05:44:54 +00:00
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
oggfile = QFS_FOpenFile (mus_ogglist);
|
2014-01-23 02:57:57 +00:00
|
|
|
if (!oggfile) {
|
2004-02-06 05:44:54 +00:00
|
|
|
Sys_Printf ("Mus_OggInit: open of file \"%s\" failed\n",
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
mus_ogglist);
|
2004-02-06 05:44:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
if (!oggfile) {
|
2004-01-20 06:58:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rewind the stream */
|
|
|
|
Qseek (oggfile, 0, SEEK_SET);
|
2004-02-06 15:16:50 +00:00
|
|
|
size = Qfilesize (oggfile);
|
2004-02-06 05:44:54 +00:00
|
|
|
buffile = calloc (size+10, sizeof (char));
|
2004-01-20 06:58:42 +00:00
|
|
|
Qread (oggfile, buffile, size);
|
2004-02-06 15:16:50 +00:00
|
|
|
|
2021-03-21 10:56:17 +00:00
|
|
|
PL_Free (tracklist);
|
2021-02-09 00:57:07 +00:00
|
|
|
tracklist = PL_GetPropertyList (buffile, 0);
|
2010-08-20 03:58:37 +00:00
|
|
|
if (!tracklist || PL_Type (tracklist) != QFDictionary) {
|
2004-01-20 06:58:42 +00:00
|
|
|
Sys_Printf ("Malformed or empty tracklist file. check mus_ogglist\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-02-06 05:44:54 +00:00
|
|
|
free (buffile);
|
|
|
|
Qclose (oggfile);
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
ogglistvalid = true;
|
|
|
|
mus_enabled = true;
|
2004-01-20 06:58:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-06 11:50:49 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_SetPlayList (int track)
|
|
|
|
{
|
2021-01-31 07:01:20 +00:00
|
|
|
const char *trackstring = va (0, "%i", track);
|
2007-05-06 11:50:49 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
play_list = PL_ObjectForKey (tracklist, trackstring);
|
|
|
|
if (!play_list) {
|
|
|
|
Sys_Printf ("No Track entry for track #%d.\n", track);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 03:58:37 +00:00
|
|
|
if (PL_Type (play_list) == QFString)
|
2007-05-06 11:50:49 +00:00
|
|
|
return;
|
2010-08-20 03:58:37 +00:00
|
|
|
if (PL_Type (play_list) != QFArray) {
|
2007-05-06 11:50:49 +00:00
|
|
|
Sys_Printf ("Track entry for track #%d not string or array.\n", track);
|
|
|
|
play_list = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < PL_A_NumObjects (play_list); i++) {
|
|
|
|
plitem_t *item = PL_ObjectAtIndex (play_list, i);
|
2010-08-20 03:58:37 +00:00
|
|
|
if (!item || PL_Type (item) != QFString) {
|
2007-05-06 11:50:49 +00:00
|
|
|
Sys_Printf ("Bad subtract %d in track %d.\n", i, track);
|
|
|
|
play_list = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
I_OGGMus_PlayNext (int looping)
|
|
|
|
{
|
|
|
|
const char *track;
|
2022-06-03 06:20:41 +00:00
|
|
|
sfx_t *sfx;
|
2007-05-06 11:50:49 +00:00
|
|
|
|
|
|
|
if (!play_list)
|
|
|
|
return;
|
2010-08-20 03:58:37 +00:00
|
|
|
if (PL_Type (play_list) == QFString) {
|
2007-05-06 11:50:49 +00:00
|
|
|
track = PL_String (play_list);
|
|
|
|
play_pos = 0;
|
|
|
|
} else {
|
|
|
|
play_pos++;
|
|
|
|
if (play_pos >= PL_A_NumObjects (play_list))
|
|
|
|
play_pos = 0;
|
|
|
|
track = PL_String (PL_ObjectAtIndex (play_list, play_pos));
|
|
|
|
looping = 0;
|
|
|
|
}
|
2010-08-05 07:23:06 +00:00
|
|
|
|
2007-05-06 11:50:49 +00:00
|
|
|
if (cd_channel) {
|
2022-06-03 06:20:41 +00:00
|
|
|
S_ChannelFree (cd_channel);
|
2007-05-06 11:50:49 +00:00
|
|
|
cd_channel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cd_channel = S_AllocChannel ()))
|
|
|
|
return;
|
|
|
|
|
2022-06-03 06:20:41 +00:00
|
|
|
if (!(sfx = S_LoadSound (track)) || !S_ChannelSetSfx (cd_channel, sfx)) {
|
|
|
|
S_ChannelFree (cd_channel);
|
2007-05-21 21:40:59 +00:00
|
|
|
cd_channel = 0;
|
2007-05-06 11:50:49 +00:00
|
|
|
return;
|
2007-05-21 21:40:59 +00:00
|
|
|
}
|
2022-06-03 06:20:41 +00:00
|
|
|
S_ChannelSetLooping (cd_channel, looping ? 1 : -1);
|
2007-05-06 11:50:49 +00:00
|
|
|
set_volume ();
|
2022-06-03 06:20:41 +00:00
|
|
|
Sys_Printf ("Playing: %s.\n", track);
|
2007-05-06 11:50:49 +00:00
|
|
|
|
|
|
|
playing = true;
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_Pause (void)
|
|
|
|
{
|
2004-02-06 15:16:50 +00:00
|
|
|
if (!tracklist || !mus_enabled || !playing)
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-03-27 06:15:57 +00:00
|
|
|
if (cd_channel)
|
2022-06-03 06:20:41 +00:00
|
|
|
S_ChannelSetPaused (cd_channel, 1);
|
2004-02-06 05:44:54 +00:00
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
wasPlaying = playing;
|
|
|
|
playing = false;
|
|
|
|
}
|
|
|
|
|
2004-02-07 06:18:56 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_Resume (void)
|
|
|
|
{
|
|
|
|
if (!tracklist || !mus_enabled || !wasPlaying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
set_volume ();
|
2022-06-03 06:20:41 +00:00
|
|
|
S_ChannelSetPaused (cd_channel, 0);
|
2004-02-07 06:18:56 +00:00
|
|
|
wasPlaying = false;
|
|
|
|
playing = true;
|
|
|
|
}
|
|
|
|
|
2007-05-06 11:50:49 +00:00
|
|
|
/* start playing, if we've got a play_list.
|
2004-01-20 06:58:42 +00:00
|
|
|
* cry if we can't find a file to play */
|
|
|
|
static void
|
|
|
|
I_OGGMus_Play (int track, qboolean looping)
|
|
|
|
{
|
|
|
|
/* alrighty. grab the list, map track to filename. grab filename from data
|
|
|
|
resources, attach sound to play, loop. */
|
2004-01-28 10:07:31 +00:00
|
|
|
|
2004-02-07 04:48:36 +00:00
|
|
|
if (!tracklist || !mus_enabled)
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
|
2004-02-08 02:39:44 +00:00
|
|
|
if (playing)
|
|
|
|
I_OGGMus_Stop ();
|
|
|
|
|
2010-11-20 05:32:27 +00:00
|
|
|
if (!track)
|
|
|
|
return;
|
2007-05-06 11:50:49 +00:00
|
|
|
I_OGGMus_SetPlayList (track);
|
|
|
|
I_OGGMus_PlayNext (looping);
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
2004-02-07 05:46:43 +00:00
|
|
|
/* print out the current track map, in numerical order. */
|
2004-01-20 06:58:42 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_Info (void)
|
|
|
|
{
|
2004-02-08 02:39:44 +00:00
|
|
|
int count = 0, iter = 0, keycount = 0;
|
2004-02-07 05:46:43 +00:00
|
|
|
const char *trackstring;
|
2004-02-08 02:39:44 +00:00
|
|
|
plitem_t *currenttrack = NULL;
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
if (!tracklist) {
|
|
|
|
Sys_Printf ("\n" "No Tracklist\n" "------------\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-02-08 02:39:44 +00:00
|
|
|
if (!(keycount = PL_D_NumKeys (tracklist)))
|
2004-02-06 15:16:50 +00:00
|
|
|
return;
|
2004-02-07 05:35:15 +00:00
|
|
|
|
2004-02-06 15:16:50 +00:00
|
|
|
Sys_Printf ("\n" "Tracklist loaded from file:\n%s\n"
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
"---------------------------\n", mus_ogglist);
|
2004-02-06 15:16:50 +00:00
|
|
|
|
2004-02-07 05:46:43 +00:00
|
|
|
/* loop, and count up the Highest key number. */
|
2004-02-08 02:39:44 +00:00
|
|
|
for (iter = 1, count = 0; count < keycount && iter <= 99 ; iter++) {
|
2021-01-31 07:01:20 +00:00
|
|
|
trackstring = va (0, "%i", iter);
|
2004-02-07 05:56:49 +00:00
|
|
|
if (!(currenttrack = PL_ObjectForKey (tracklist, trackstring))) {
|
2004-02-07 05:46:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-02-08 02:39:44 +00:00
|
|
|
|
2010-08-20 03:58:37 +00:00
|
|
|
Sys_Printf (" %s - %s\n", trackstring, PL_String (currenttrack));
|
2004-02-07 07:50:11 +00:00
|
|
|
count++;
|
2004-02-07 05:46:43 +00:00
|
|
|
}
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
I_OGG_f (void)
|
|
|
|
{
|
|
|
|
const char *command;
|
|
|
|
|
|
|
|
if (Cmd_Argc () < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
command = Cmd_Argv (1);
|
|
|
|
|
2004-01-28 10:07:31 +00:00
|
|
|
if (!cd_channel) {
|
|
|
|
Sys_Printf ("OGGMus: Don't have a channel.\n");
|
|
|
|
mus_enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
if (strequal (command, "on")) {
|
|
|
|
mus_enabled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "off")) {
|
|
|
|
if (playing)
|
|
|
|
I_OGGMus_Stop ();
|
|
|
|
mus_enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "reset")) {
|
2004-02-06 05:44:54 +00:00
|
|
|
Load_Tracklist ();
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "remap")) {
|
|
|
|
Sys_Printf ("OGGMus: remap does nothing.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "close")) {
|
|
|
|
I_OGGMus_CloseDoor ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tracklist) {
|
2004-02-06 05:44:54 +00:00
|
|
|
Load_Tracklist ();
|
2004-01-20 06:58:42 +00:00
|
|
|
if (!tracklist) {
|
|
|
|
Sys_Printf ("Can't initialize tracklist.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "play")) {
|
2004-02-07 06:09:06 +00:00
|
|
|
I_OGGMus_Play (atoi (Cmd_Argv (2)), false);
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "loop")) {
|
2004-02-07 06:09:06 +00:00
|
|
|
I_OGGMus_Play (atoi (Cmd_Argv (2)), true);
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "stop")) {
|
|
|
|
I_OGGMus_Stop ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "pause")) {
|
2004-02-07 06:09:06 +00:00
|
|
|
I_OGGMus_Pause ();
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "resume")) {
|
2004-02-07 06:09:06 +00:00
|
|
|
I_OGGMus_Resume ();
|
2004-01-20 06:58:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "eject")) {
|
|
|
|
if (playing)
|
|
|
|
I_OGGMus_Stop ();
|
|
|
|
I_OGGMus_Eject ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strequal (command, "info")) {
|
|
|
|
I_OGGMus_Info ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
I_OGGMus_Update (void)
|
|
|
|
{
|
2022-06-03 06:20:41 +00:00
|
|
|
if (!cd_channel || S_ChannelGetState (cd_channel) > chan_done)
|
2007-05-06 11:50:49 +00:00
|
|
|
return;
|
2010-01-13 06:42:26 +00:00
|
|
|
// will get here only when multi-tracked
|
2007-05-06 11:50:49 +00:00
|
|
|
I_OGGMus_Stop ();
|
|
|
|
I_OGGMus_PlayNext (0);
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called when the mus_ogglist cvar is changed */
|
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Mus_OggChange (void *data, const cvar_t *cvar)
|
2004-01-20 06:58:42 +00:00
|
|
|
{
|
2004-02-06 05:44:54 +00:00
|
|
|
Load_Tracklist ();
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* change volume on sound object */
|
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Mus_VolChange (void *data, const cvar_t *bgmvolume)
|
2004-01-20 06:58:42 +00:00
|
|
|
{
|
2004-01-21 19:35:17 +00:00
|
|
|
set_volume ();
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
2004-02-03 03:01:06 +00:00
|
|
|
static void
|
2022-06-04 07:06:04 +00:00
|
|
|
Mus_gamedir (int phase, void *data)
|
2004-02-03 03:01:06 +00:00
|
|
|
{
|
2016-10-24 15:10:30 +00:00
|
|
|
if (phase)
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Load_Tracklist ();
|
2004-02-03 03:01:06 +00:00
|
|
|
}
|
|
|
|
|
2004-01-20 06:58:42 +00:00
|
|
|
static void
|
|
|
|
I_OGGMus_Init (void)
|
|
|
|
{
|
|
|
|
/* check list file cvar, open list file, create map, close file. */
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&mus_ogglist_cvar, Mus_OggChange, 0);
|
|
|
|
Cvar_Register (&bgmvolume_cvar, Mus_VolChange, 0);
|
2022-06-04 07:06:04 +00:00
|
|
|
QFS_GamedirCallback (Mus_gamedir, 0);
|
2004-01-20 06:58:42 +00:00
|
|
|
}
|
|
|
|
|
2004-01-20 08:34:57 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
|
|
|
I_OGGMus_Init,
|
|
|
|
I_OGGMus_Shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static cd_funcs_t plugin_info_cd_funcs = {
|
2021-06-26 06:43:17 +00:00
|
|
|
0,
|
2004-01-20 08:34:57 +00:00
|
|
|
I_OGG_f,
|
|
|
|
I_OGGMus_Pause,
|
|
|
|
I_OGGMus_Play,
|
|
|
|
I_OGGMus_Resume,
|
|
|
|
I_OGGMus_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",
|
|
|
|
"OGG Music output\n",
|
2004-02-07 05:35:15 +00:00
|
|
|
"Copyright (C) 2004 Andrew Pilley\n"
|
|
|
|
"Copyright (C) 2004 Members of the QuakeForge Project\n"
|
|
|
|
"See the file \"AUTHORS\" for more information.\n",
|
2004-01-20 08:34:57 +00:00
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
2004-01-20 06:58:42 +00:00
|
|
|
|
2004-01-20 08:34:57 +00:00
|
|
|
PLUGIN_INFO (cd, file)
|
|
|
|
{
|
2004-01-20 06:58:42 +00:00
|
|
|
return &plugin_info;
|
|
|
|
}
|