OpenTTD Source: src/base_media_music.h Source File

OpenTTD Source 15.0-RC2

base_media_music.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD 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, version 2.
4 * OpenTTD 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.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef BASE_MEDIA_MUSIC_H
11#define BASE_MEDIA_MUSIC_H
12
13#include "base_media_base.h"
14
16 static const uint NUM_SONGS_CLASS = 10;
18 static const uint NUM_SONG_CLASSES = 3;
20 static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS;
21
23 static const uint NUM_SONGS_PLAYLIST = 32;
24
25/* Functions to read DOS music CAT files, similar to but not quite the same as sound effect CAT files */
26std::optional<std::string> GetMusicCatEntryName(const std::string &filename, size_t entrynum);
27std::optional<std::vector<uint8_t>> GetMusicCatEntryData(const std::string &filename, size_t entrynum);
28
29 enum MusicTrackType : uint8_t {
30 MTT_STANDARDMIDI,
31 MTT_MPSMIDI,
32};
33
35 struct MusicSongInfo {
36 std::string songname;
37 std::string filename;
38 int cat_index;
39 int override_start;
40 int override_end;
41 uint8_t tracknr;
42 MusicTrackType filetype;
43 bool loop;
44};
45
46 template <> struct BaseSetTraits<struct MusicSet> {
47 static constexpr size_t num_files = NUM_SONGS_AVAILABLE;
48 static constexpr bool search_in_tars = false;
49 static constexpr std::string_view set_type = "music";
50};
51
53 struct MusicSet : BaseSet<MusicSet> {
55 MusicSongInfo songinfo[NUM_SONGS_AVAILABLE];
57 uint8_t num_available = 0;
58
59 bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename);
60};
61
63 class BaseMusic : public BaseMedia<MusicSet> {
64public:
66 static inline std::string ini_set;
67};
68
69#endif /* BASE_MEDIA_MUSIC_H */
base_media_base.h
Generic functions for replacing base data (graphics, sounds).
GetMusicCatEntryName
std::optional< std::string > GetMusicCatEntryName(const std::string &filename, size_t entrynum)
Read the name of a music CAT file entry.
Definition music.cpp:26
NUM_SONG_CLASSES
static const uint NUM_SONG_CLASSES
Number of classes for songs.
Definition base_media_music.h:18
NUM_SONGS_AVAILABLE
static const uint NUM_SONGS_AVAILABLE
Maximum number of songs in the full playlist; theme song + the classes.
Definition base_media_music.h:20
NUM_SONGS_CLASS
static const uint NUM_SONGS_CLASS
Maximum number of songs in the 'class' playlists.
Definition base_media_music.h:16
NUM_SONGS_PLAYLIST
static const uint NUM_SONGS_PLAYLIST
Maximum number of songs in the (custom) playlist.
Definition base_media_music.h:23
GetMusicCatEntryData
std::optional< std::vector< uint8_t > > GetMusicCatEntryData(const std::string &filename, size_t entrynum)
Read the full data of a music CAT file entry.
Definition music.cpp:50
MusicTrackType
MusicTrackType
Definition base_media_music.h:29
MTT_MPSMIDI
@ MTT_MPSMIDI
MPS GM driver MIDI format (contained in a CAT file)
Definition base_media_music.h:31
MTT_STANDARDMIDI
@ MTT_STANDARDMIDI
Standard MIDI file.
Definition base_media_music.h:30
BaseMedia
Base for all base media (graphics, sounds)
Definition base_media_base.h:163
BaseMusic
All data/functions related with replacing the base music.
Definition base_media_music.h:63
BaseMusic::ini_set
static std::string ini_set
The set as saved in the config file.
Definition base_media_music.h:66
BaseSetTraits
Defines the traits of a BaseSet type.
Definition base_media_base.h:43
BaseSet
Information about a single base set.
Definition base_media_base.h:50
IniFile
Ini file that supports both loading and saving.
Definition ini_type.h:86
MusicSet
All data of a music set.
Definition base_media_music.h:53
MusicSet::songinfo
MusicSongInfo songinfo[NUM_SONGS_AVAILABLE]
Data about individual songs in set.
Definition base_media_music.h:55
MusicSet::num_available
uint8_t num_available
Number of valid songs in set.
Definition base_media_music.h:57
MusicSongInfo
Metadata about a music track.
Definition base_media_music.h:35
MusicSongInfo::filetype
MusicTrackType filetype
decoder required for song file
Definition base_media_music.h:42
MusicSongInfo::songname
std::string songname
name of song displayed in UI
Definition base_media_music.h:36
MusicSongInfo::tracknr
uint8_t tracknr
track number of song displayed in UI
Definition base_media_music.h:41
MusicSongInfo::filename
std::string filename
file on disk containing song (when used in MusicSet class)
Definition base_media_music.h:37
MusicSongInfo::override_start
int override_start
MIDI ticks to skip over in beginning.
Definition base_media_music.h:39
MusicSongInfo::loop
bool loop
song should play in a tight loop if possible, never ending
Definition base_media_music.h:43
MusicSongInfo::cat_index
int cat_index
entry index in CAT file, for filetype==MTT_MPSMIDI
Definition base_media_music.h:38
MusicSongInfo::override_end
int override_end
MIDI tick to end the song at (0 if no override)
Definition base_media_music.h:40