OpenTTD Source 20260711-master-g3fb3006dff
MusicSystem Struct Reference

Data Structures

struct  PlaylistEntry

Public Types

typedef std::vector< PlaylistEntryPlaylist

Public Member Functions

void BuildPlaylists ()
 Rebuild all playlists for the current music set.
void ChangePlaylist (PlaylistChoice pl)
 Switch to another playlist, or reload the current one.
void ChangeMusicSet (const std::string &set_name)
 Change to named music set, and reset playback.
void Shuffle ()
 Enable shuffle mode.
void Unshuffle ()
 Disable shuffle mode.
void Play ()
 Start/restart playback at current song.
void Stop ()
 Stop playback and set flag that we don't intend to play music.
void Next ()
 Skip to next track.
void Prev ()
 Skip to previous track.
void CheckStatus ()
 Check that music is playing if it should, and that appropriate playlist is active for game/main menu.
bool IsPlaying () const
 Is the player getting music right now?
bool IsShuffle () const
 Is shuffle mode enabled?
PlaylistEntry GetCurrentSong () const
 Return the current song, or a dummy if none.
bool IsCustomPlaylist () const
 Is one of the custom playlists selected?
void PlaylistAdd (size_t song_index)
 Append a song to a custom playlist.
void PlaylistRemove (size_t song_index)
 Remove a song from a custom playlist.
void PlaylistClear ()
 Remove all songs from the current custom playlist.

Data Fields

Playlist active_playlist {}
 current play order of songs, including any shuffle
Playlist music_set {}
 all songs in current music set, in set order
PlaylistChoice selected_playlist {}

Private Member Functions

uint GetSetIndex ()
 Get set index from current playlist position.
void SetPositionBySetIndex (uint set_index)
 Set playlist position by set index.
void ChangePlaylistPosition (int ofs)
 Change playlist position pointer by the given offset, making sure to keep it within valid range.
void SaveCustomPlaylist (PlaylistChoice pl)
 Save a custom playlist to settings after modification.

Private Attributes

int playlist_position = 0
EnumIndexArray< Playlist, PlaylistChoice, PlaylistChoice::Endstandard_playlists {}

Detailed Description

Definition at line 40 of file music_gui.cpp.

Member Typedef Documentation

◆ Playlist

typedef std::vector<PlaylistEntry> MusicSystem::Playlist

Definition at line 48 of file music_gui.cpp.

Member Function Documentation

◆ BuildPlaylists()

void MusicSystem::BuildPlaylists ( )

Rebuild all playlists for the current music set.

Definition at line 92 of file music_gui.cpp.

References _settings_client, All, Custom1, Custom2, BaseMedia< MusicSet >::GetUsedSet(), music_set, NUM_SONGS_AVAILABLE, NUM_SONGS_CLASS, NUM_SONGS_PLAYLIST, OldStyle, ThemeOnly, and to_underlying().

Referenced by ChangeMusicSet().

◆ ChangeMusicSet()

void MusicSystem::ChangeMusicSet ( const std::string & set_name)

Change to named music set, and reset playback.

Parameters
set_nameName of music set to select

Definition at line 159 of file music_gui.cpp.

References BuildPlaylists(), ChangePlaylist(), GameOptions, BaseMusic::ini_set, InvalidateWindowData(), and BaseMedia< MusicSet >::SetSetByName().

◆ ChangePlaylist()

void MusicSystem::ChangePlaylist ( PlaylistChoice pl)

Switch to another playlist, or reload the current one.

Parameters
plPlaylist to select

Definition at line 136 of file music_gui.cpp.

References _settings_client, active_playlist, All, InvalidateWindowData(), Menu, Play(), Shuffle(), and ThemeOnly.

Referenced by ChangeMusicSet(), CheckStatus(), and PlaylistClear().

◆ ChangePlaylistPosition()

void MusicSystem::ChangePlaylistPosition ( int ofs)
private

Change playlist position pointer by the given offset, making sure to keep it within valid range.

If the playlist is empty, position is always set to 0.

Parameters
ofsAmount to move playlist position by.

Definition at line 414 of file music_gui.cpp.

References active_playlist.

Referenced by Next(), Play(), and Prev().

◆ CheckStatus()

void MusicSystem::CheckStatus ( )

Check that music is playing if it should, and that appropriate playlist is active for game/main menu.

Definition at line 274 of file music_gui.cpp.

References _settings_client, active_playlist, ChangePlaylist(), MusicDriver::GetInstance(), IsPlaying(), Menu, Next(), and ThemeOnly.

◆ GetCurrentSong()

MusicSystem::PlaylistEntry MusicSystem::GetCurrentSong ( ) const

Return the current song, or a dummy if none.

Returns
The currently playing song.

Definition at line 307 of file music_gui.cpp.

References active_playlist, BaseMedia< MusicSet >::GetUsedSet(), and IsPlaying().

◆ GetSetIndex()

uint MusicSystem::GetSetIndex ( )
private

Get set index from current playlist position.

Returns
current set index, or UINT_MAX if nothing is selected.

Definition at line 186 of file music_gui.cpp.

References active_playlist.

Referenced by Shuffle(), and Unshuffle().

◆ IsCustomPlaylist()

bool MusicSystem::IsCustomPlaylist ( ) const

Is one of the custom playlists selected?

Returns
true iff one of the custom playlists is selected.

Definition at line 317 of file music_gui.cpp.

References Custom1, and Custom2.

Referenced by PlaylistAdd(), PlaylistClear(), and PlaylistRemove().

◆ IsPlaying()

bool MusicSystem::IsPlaying ( ) const

Is the player getting music right now?

Returns
true iff a song is playing.

Definition at line 289 of file music_gui.cpp.

References _settings_client, and active_playlist.

Referenced by CheckStatus(), GetCurrentSong(), PlaylistAdd(), and PlaylistRemove().

◆ IsShuffle()

bool MusicSystem::IsShuffle ( ) const

Is shuffle mode enabled?

Returns
true iff shuffling is enabled.

Definition at line 298 of file music_gui.cpp.

References _settings_client.

Referenced by PlaylistAdd(), and PlaylistRemove().

◆ Next()

void MusicSystem::Next ( )

Skip to next track.

Definition at line 256 of file music_gui.cpp.

References _settings_client, ChangePlaylistPosition(), InvalidateWindowData(), and Play().

Referenced by CheckStatus().

◆ Play()

◆ PlaylistAdd()

void MusicSystem::PlaylistAdd ( size_t song_index)

Append a song to a custom playlist.

Always adds to the currently active playlist.

Parameters
song_indexIndex of song in the current music set to add

Definition at line 327 of file music_gui.cpp.

References active_playlist, InvalidateWindowData(), IsCustomPlaylist(), IsPlaying(), IsShuffle(), music_set, NUM_SONGS_PLAYLIST, Play(), and SaveCustomPlaylist().

◆ PlaylistClear()

void MusicSystem::PlaylistClear ( )

Remove all songs from the current custom playlist.

Effectively stops playback too.

Definition at line 399 of file music_gui.cpp.

References ChangePlaylist(), IsCustomPlaylist(), and SaveCustomPlaylist().

◆ PlaylistRemove()

void MusicSystem::PlaylistRemove ( size_t song_index)

Remove a song from a custom playlist.

Parameters
song_indexIndex in the custom playlist to remove.

Definition at line 365 of file music_gui.cpp.

References active_playlist, MusicSongInfo::cat_index, MusicSongInfo::filename, InvalidateWindowData(), IsCustomPlaylist(), IsPlaying(), IsShuffle(), Play(), and SaveCustomPlaylist().

◆ Prev()

void MusicSystem::Prev ( )

Skip to previous track.

Definition at line 265 of file music_gui.cpp.

References _settings_client, ChangePlaylistPosition(), InvalidateWindowData(), and Play().

◆ SaveCustomPlaylist()

void MusicSystem::SaveCustomPlaylist ( PlaylistChoice pl)
private

Save a custom playlist to settings after modification.

Parameters
plPlaylist to store back

Definition at line 429 of file music_gui.cpp.

References _settings_client, Custom1, Custom2, and NUM_SONGS_PLAYLIST.

Referenced by PlaylistAdd(), PlaylistClear(), and PlaylistRemove().

◆ SetPositionBySetIndex()

void MusicSystem::SetPositionBySetIndex ( uint set_index)
private

Set playlist position by set index.

Parameters
set_indexSet index to select.

Definition at line 176 of file music_gui.cpp.

References active_playlist, and MusicSystem::PlaylistEntry::set_index.

Referenced by Shuffle(), and Unshuffle().

◆ Shuffle()

void MusicSystem::Shuffle ( )

Enable shuffle mode.

Definition at line 196 of file music_gui.cpp.

References _settings_client, active_playlist, GetSetIndex(), InvalidateWindowData(), and SetPositionBySetIndex().

Referenced by ChangePlaylist().

◆ Stop()

void MusicSystem::Stop ( )

Stop playback and set flag that we don't intend to play music.

Definition at line 247 of file music_gui.cpp.

References _settings_client, MusicDriver::GetInstance(), InvalidateWindowData(), and MusicDriver::StopSong().

◆ Unshuffle()

void MusicSystem::Unshuffle ( )

Disable shuffle mode.

Definition at line 215 of file music_gui.cpp.

References _settings_client, active_playlist, GetSetIndex(), InvalidateWindowData(), and SetPositionBySetIndex().

Field Documentation

◆ active_playlist

Playlist MusicSystem::active_playlist {}

current play order of songs, including any shuffle

Definition at line 50 of file music_gui.cpp.

Referenced by ChangePlaylist(), ChangePlaylistPosition(), CheckStatus(), GetCurrentSong(), GetSetIndex(), IsPlaying(), Play(), PlaylistAdd(), PlaylistRemove(), SetPositionBySetIndex(), Shuffle(), and Unshuffle().

◆ music_set

Playlist MusicSystem::music_set {}

all songs in current music set, in set order

Definition at line 51 of file music_gui.cpp.

Referenced by BuildPlaylists(), and PlaylistAdd().

◆ playlist_position

int MusicSystem::playlist_position = 0
private

Definition at line 81 of file music_gui.cpp.

◆ selected_playlist

PlaylistChoice MusicSystem::selected_playlist {}

Definition at line 53 of file music_gui.cpp.

◆ standard_playlists

EnumIndexArray<Playlist, PlaylistChoice, PlaylistChoice::End> MusicSystem::standard_playlists {}
private

Definition at line 85 of file music_gui.cpp.


The documentation for this struct was generated from the following file: