RingRacers/src/music.h
James R 39f46a0f20 Replace music handling
(This commit does not compile. Sound test and tunes
command code needs to be ported after this.)

This is a big one. Here's the rundown:

The old music system was very direct, much of the time
just a proxy to the real sound API in i_sound.h.

You could change the music on command, but there wasn't
a consistent way to prevent some music from playing over
others. P_RestoreMusic is one example of needing to
address this problem. The jingles system was intended as
another solution. Furthermore, sound test (Stereo) has its
own needs.

I am removing all of that. Music handling in general is
now a very deliberate system, kind of similar to jingles.

In the new system, "tunes" are registered. The tune stores
info such as whether it should loop or fade out. Most of
the configuration is intended to be initialized only ONCE.
Tunes can be mapped to an actual music lump. They can be
remapped at any time too.

Tunes are also configured with a priority number. This
determines which tune is heard, if multiple are supposed
to be playing at a time. You can even tell a tune how long
it should play, so it's unnecessary to track this with
bespoke timers.
2023-08-06 17:31:45 -07:00

148 lines
3.8 KiB
C

// DR ROBOTNIK'S RING RACERS
//-----------------------------------------------------------------------------
// Copyright (C) 2023 by Kart Krew.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
//
// A brief description of "tunes".
//
// Tunes are how the game identifies music. A tune may be
// remapped to any music lump. For example, the "level" tune
// represents the level music, but the actual song that plays
// is different between levels.
//
// Tunes store info, such as for how long they will play (in
// the case of "invinc" and "grow"), or whether they fade in
// or out and for how long they fade.
//
// Tunes are given a priority. Only the highest priority tune
// is heard, even if the others haven't ended. Tunes with the
// same priority are sorted by picking the last one that begun
// playing.
//
#ifndef MUSIC_H
#define MUSIC_H
#include "doomtype.h"
#ifdef __cplusplus
extern "C" {
#endif
//
// Get the currently playing tune.
//
// Returns the song name for the currently playing tune.
// Returns empty string if no tune is playing.
const char *Music_CurrentSong(void);
// Returns the id of the currently playing tune. Returns empty
// string if no tune is playing.
const char *Music_CurrentId(void);
//
// Actions that take effect immediately.
//
// Begin playing a tune, duration is infinite. If the tune was
// already playing, this resets its current position (seeks
// back to the start.)
void Music_Play(const char *id);
// Postpone the end of this tune until N tics from now. The
// tune should already be playing before calling this.
void Music_DelayEnd(const char *id, tic_t duration);
// Stop playing a tune.
void Music_Stop(const char *id);
void Music_StopAll(void);
// Pause a tune. This effectively extends its duration,
// relative to game time. Unpausing will resume the tune
// exactly where it left off.
void Music_Pause(const char *id);
void Music_UnPause(const char *id);
void Music_PauseAll(void);
void Music_UnPauseAll(void);
//
// Change properties. May be called before calling Music_Play.
// These take effect on the next tick.
//
// Seek to a specific time in the tune.
void Music_Seek(const char *id, tic_t set);
// Remap a tune to another song. Use the lump name, with the
// 'O_' at the beginning removed. song is case insensitive.
void Music_Remap(const char *id, const char *song);
// Set whether a tune should loop.
void Music_Loop(const char *id, boolean loop);
//
// Query properties.
//
// Returns true if the tune is configured to loop.
boolean Music_CanLoop(const char *id);
// Returns true if the tune does not play indefinitely, i.e.
// has a limited duration.
boolean Music_CanEnd(const char *id);
// Returns true if the tune is playing. This does not
// necessarily mean it is audible, because it has to be at the
// highest priority to be heard.
boolean Music_Playing(const char *id);
// Returns true if the tune is paused.
boolean Music_Paused(const char *id);
// Returns the number of tics elapsed since the start of the
// tune.
tic_t Music_Elapsed(const char *id);
// Returns the number of tics remaining until the tune ends.
tic_t Music_DurationLeft(const char *id);
// Returns the total duration of the tune, in tics.
tic_t Music_TotalDuration(const char *id);
// Returns the song name mapped to a tune.
const char *Music_Song(const char *id);
//
// Low level program state.
//
// Loads certain data structures used for the lifetime of the
// program. Only needs to be called once, before any other
// functions.
void Music_Init(void);
// Call this every tic to update the music.
void Music_Tick(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MUSIC_H