1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2021, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17// Handles song list and music playback.
18
19#pragma once
20
21#include <C4AudioSystem.h>
22#include <C4Group.h>
23
24#include <cstdint>
25#include <list>
26#include <memory>
27#include <optional>
28#include <string>
29
30class C4MusicSystem
31{
32public:
33 C4MusicSystem();
34 C4MusicSystem(const C4MusicSystem &) = delete;
35 C4MusicSystem(C4MusicSystem &&) = delete;
36 C4MusicSystem &operator=(const C4MusicSystem &) = delete;
37 ~C4MusicSystem() { Stop(); }
38
39 void Execute();
40 /* Does nothing if user did not enable music for current mode (frontend/game).
41 Otherwise start playing. If already playing, stop and restart. */
42 void Play(const char *songname = nullptr, bool loop = false);
43 void PlayFrontendMusic();
44 void PlayScenarioMusic(C4Group &);
45 long SetPlayList(const char *playlist);
46 void Stop(int fadeoutMS = 0);
47 bool ToggleOnOff(bool changeConfig = true);
48 void UpdateVolume();
49
50private:
51 struct Song
52 {
53 const std::string name;
54 bool enabled = false;
55
56 Song() = delete;
57 Song(const std::string &name) : name{name} {}
58 Song(const Song &) = delete;
59 Song(Song &&) = delete;
60 Song &operator=(const Song &) = delete;
61 ~Song() = default;
62 };
63
64 std::list<Song> songs;
65 const Song *mostRecentlyPlayed{};
66
67 // Valid when a song is currently playing
68 std::unique_ptr<const char[]> playingFileContents;
69 std::unique_ptr<C4AudioSystem::MusicFile> playingFile;
70
71 // Returns a reference to the "music enabled" config entry of the current game mode
72 static bool &GetCfgMusicEnabled();
73
74 void ClearPlayingSong();
75 void ClearSongs();
76 const Song *FindSong(const std::string &name) const;
77 void LoadDir(const char *path);
78 void LoadMoreMusic();
79};
80