Files
VVVVVV/desktop_version/src/Music.h
T
Nyako c02f8e004c Load an unlimited amount of loose music (#1171)
* Load an unlimited amount of loose music

Binary blobs can now store 128 tracks, and music can now be read from
loose files. Unfortunately, the two cannot be used together -- loose
music can still only use 16 tracks. This commit attempts to fix that,
allowing for music playback by filename.

* Rework music track loading

The current "loose songs" system does not load files from custom
assets. This is from the #412 PR, and is NOT the "extra loose songs"
system that this PR implements, but they both work in the same area so
I decided to squash both of these bugs at once (plus, it helped clean
up the code and make a saner system, so...)

This commit also allows "loose music" to override music stored in the
`vvvvvvmusic.vvv` binary blob. When reading a blob, it will first check
if a loose file exists at the current path it's trying to find a track
at; if it exists, it will load that instead. If the blob does not
exist, the system will try to locate all expected built-in tracks
directly from the assets folder instead of doing that during blob
loading.

The `play` command has some safety removed due to an old exploit which
needs to be kept -- `music(5b)` should play track 5. This is used in
many levels and cannot be broken; unfortunately this means that we no
longer get the nice error when a song fails to be played, but that's
better than breaking a large amount of levels.

This commit does NOT address loading a "extra" loose track overtop of
a custom blob track, because with the current tooling, and the way it
will most likely continue to work in the future, every single custom
track in blobs have a completely empty path. If someone decides to
modify their blob in a hex editor or makes their own tooling, this
issue may show up again, but that is a problem which can and probably
should be addressed at a later date. The required code to solve such a
problem would be far more than what this PR should address, and for a
situation so unlikely, it's easy enough to just avoid adding the same
custom song twice, one in a music file, and one loose, because if
you're making a level, you're probably going to use one or the other.

* Fix mentioned issues from review
2026-05-06 19:03:05 -04:00

142 lines
3.1 KiB
C++

#ifndef MUSIC_H
#define MUSIC_H
#include "BinaryBlob.h"
#define musicroom(rx, ry) ((rx) + ((ry) * 20))
/* The amount of "space" for the scale of the user-set volume. */
#define USER_VOLUME_MAX 256
/* It is advised that USER_VOLUME_MAX be divisible by this. */
#define USER_VOLUME_STEP 32
enum
{
Music_PATHCOMPLETE = 0,
Music_PUSHINGONWARDS = 1,
Music_POSITIVEFORCE = 2,
Music_POTENTIALFORANYTHING = 3,
Music_PASSIONFOREXPLORING = 4,
Music_PAUSE = 5,
Music_PRESENTINGVVVVVV = 6,
Music_PLENARY = 7,
Music_PREDESTINEDFATE = 8,
Music_POSITIVEFORCEREVERSED = 9,
Music_POPULARPOTPOURRI = 10,
Music_PIPEDREAM = 11,
Music_PRESSURECOOKER = 12,
Music_PACEDENERGY = 13,
Music_PIERCINGTHESKY = 14,
Music_PREDESTINEDFATEREMIX = 15
};
enum
{
Sound_FLIP = 0,
Sound_UNFLIP = 1,
Sound_CRY = 2,
Sound_TRINKET = 3,
Sound_COIN = 4,
Sound_CHECKPOINT = 5,
Sound_CRUMBLE = 6,
Sound_DISAPPEAR = 7,
Sound_GRAVITYLINE = 8,
Sound_FLASH = 9,
Sound_TELEPORT = 10,
Sound_VIRIDIAN = 11,
Sound_VERDIGRIS = 12,
Sound_VICTORIA = 13,
Sound_VITELLARY = 14,
Sound_VIOLET = 15,
Sound_VERMILION = 16,
Sound_TERMINALTOUCH = 17,
Sound_GAMESAVED = 18,
Sound_ALARM = 19,
Sound_TERMINALTEXT = 20,
Sound_COUNTDOWN = 21,
Sound_GO = 22,
Sound_DESTROY = 23,
Sound_COMBINE = 24,
Sound_NEWRECORD = 25,
Sound_TROPHY = 26,
Sound_RESCUE = 27
};
class musicclass
{
public:
musicclass(void);
void init(void);
void destroy(void);
void set_music_volume(int volume);
void set_sound_volume(int volume);
bool play(int t);
bool playid(const char* id);
bool idexists(const char* id);
bool isextra(int t);
const char* getid(int t);
void resume(void);
void resumefade(const int fadein_ms);
void pause(void);
void haltdasmusik(void);
void haltdasmusik(bool from_fade);
void silencedasmusik(void);
void fadeMusicVolumeIn(int ms);
void fadeMusicVolumeOut(const int fadeout_ms);
void fadeout(const bool quick_fade_ = true);
void fadein(void);
void processmusicfadein(void);
void processmusicfadeout(void);
void processmusic(void);
void niceplay(int t);
void changemusicarea(int x, int y);
int currentsong;
int haltedsong;
bool playef(int t);
bool playefid(const char* id);
bool soundidexists(const char* id);
bool soundisextra(int t);
const char* getsoundid(int t);
void pauseef(void);
void resumeef(void);
bool halted(void);
void updatemutestate(void);
bool safeToProcessMusic;
int nicechange; // -1 if no song queued
bool nicefade;
bool m_doFadeInVol;
bool m_doFadeOutVol;
int controlVolume;
/* 0..USER_VOLUME_MAX */
int user_music_volume;
int user_sound_volume;
bool quick_fade;
// MMMMMM mod settings
bool mmmmmm;
bool usingmmmmmm;
binaryBlob pppppp_blob;
binaryBlob mmmmmm_blob;
int num_pppppp_tracks;
int num_mmmmmm_tracks;
};
#ifndef MUSIC_DEFINITION
extern musicclass music;
#endif
#endif /* MUSIC_H */