OpenTTD Source 20241224-master-gf74b0cf984
MusicSystem Struct Reference

Data Structures

struct  PlaylistEntry
 

Public Types

enum  PlaylistChoices {
  PLCH_ALLMUSIC , PLCH_OLDSTYLE , PLCH_NEWSTYLE , PLCH_EZYSTREET ,
  PLCH_CUSTOM1 , PLCH_CUSTOM2 , PLCH_THEMEONLY , PLCH_MAX
}
 
typedef std::vector< PlaylistEntryPlaylist
 

Public Member Functions

void BuildPlaylists ()
 Rebuild all playlists for the current music set.
 
void ChangePlaylist (PlaylistChoices 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 displayed_playlist
 current playlist as displayed in GUI, never in shuffled order
 
Playlist music_set
 all songs in current music set, in set order
 
PlaylistChoices 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 (PlaylistChoices pl)
 Save a custom playlist to settings after modification.
 

Private Attributes

int playlist_position
 
Playlist standard_playlists [PLCH_MAX]
 

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 Enumeration Documentation

◆ PlaylistChoices

enum MusicSystem::PlaylistChoices

Definition at line 50 of file music_gui.cpp.

Member Function Documentation

◆ BuildPlaylists()

void MusicSystem::BuildPlaylists ( )

◆ 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 172 of file music_gui.cpp.

References BuildPlaylists(), ChangePlaylist(), BaseMusic::ini_set, InvalidateWindowData(), BaseMedia< MusicSet >::SetSetByName(), WC_GAME_OPTIONS, WC_MUSIC_TRACK_SELECTION, WC_MUSIC_WINDOW, and WN_GAME_OPTIONS_GAME_OPTIONS.

Referenced by ChangeMusicSet().

◆ ChangePlaylist()

void MusicSystem::ChangePlaylist ( PlaylistChoices  pl)

◆ 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 287 of file music_gui.cpp.

References _settings_client, active_playlist, ChangePlaylist(), MusicDriver::GetInstance(), IsPlaying(), ClientSettings::music, Next(), and MusicSettings::playlist.

Referenced by MusicLoop().

◆ GetCurrentSong()

MusicSystem::PlaylistEntry MusicSystem::GetCurrentSong ( ) const

Return the current song, or a dummy if none.

Definition at line 311 of file music_gui.cpp.

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

Referenced by MusicWindow::DrawWidget().

◆ 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 199 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?

Definition at line 318 of file music_gui.cpp.

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

◆ IsPlaying()

bool MusicSystem::IsPlaying ( ) const

Is the player getting music right now?

Definition at line 299 of file music_gui.cpp.

References _settings_client, active_playlist, ClientSettings::music, and MusicSettings::playing.

Referenced by CheckStatus(), MusicWindow::DrawWidget(), GetCurrentSong(), PlaylistAdd(), and PlaylistRemove().

◆ IsShuffle()

bool MusicSystem::IsShuffle ( ) const

Is shuffle mode enabled?

Definition at line 305 of file music_gui.cpp.

References _settings_client, ClientSettings::music, and MusicSettings::shuffle.

Referenced by MusicWindow::OnClick(), and PlaylistAdd().

◆ Next()

void MusicSystem::Next ( )

◆ 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 328 of file music_gui.cpp.

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

Referenced by MusicTrackSelectionWindow::OnClick().

◆ 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().

Referenced by MusicTrackSelectionWindow::OnClick().

◆ 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 367 of file music_gui.cpp.

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

Referenced by MusicTrackSelectionWindow::OnClick().

◆ Prev()

void MusicSystem::Prev ( )

◆ SaveCustomPlaylist()

void MusicSystem::SaveCustomPlaylist ( PlaylistChoices  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, MusicSettings::custom_1, MusicSettings::custom_2, MemSetT(), ClientSettings::music, 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 189 of file music_gui.cpp.

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

Referenced by Shuffle(), and Unshuffle().

◆ Shuffle()

◆ Stop()

void MusicSystem::Stop ( )

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

Definition at line 260 of file music_gui.cpp.

References _settings_client, MusicDriver::GetInstance(), InvalidateWindowData(), ClientSettings::music, MusicSettings::playing, MusicDriver::StopSong(), and WC_MUSIC_WINDOW.

Referenced by MusicWindow::OnClick().

◆ Unshuffle()

Field Documentation

◆ active_playlist

Playlist MusicSystem::active_playlist

◆ displayed_playlist

Playlist MusicSystem::displayed_playlist

current playlist as displayed in GUI, never in shuffled order

Definition at line 62 of file music_gui.cpp.

Referenced by ChangePlaylist(), PlaylistAdd(), PlaylistRemove(), Shuffle(), and Unshuffle().

◆ music_set

Playlist MusicSystem::music_set

◆ playlist_position

int MusicSystem::playlist_position
private

Definition at line 93 of file music_gui.cpp.

◆ selected_playlist

PlaylistChoices MusicSystem::selected_playlist

Definition at line 65 of file music_gui.cpp.

◆ standard_playlists

Playlist MusicSystem::standard_playlists[PLCH_MAX]
private

Definition at line 97 of file music_gui.cpp.


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