OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MusicSystem.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2010-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Handles Music.ocg and randomly plays songs */
19 
20 #ifndef INC_C4MusicSystem
21 #define INC_C4MusicSystem
22 
23 #include "c4group/C4Group.h"
25 
27 class C4MusicFile;
28 
30 {
31  friend class C4SoundEffect;
32  friend class C4SoundInstance;
33  friend class C4SoundSystem;
34 public:
35  C4MusicSystem();
37  void Clear();
38  void ClearGame();
39  void UpdateVolume(); // compute volume from game + config data
40  void Execute(bool force_buffer_checks = false);
41  void NotifySuccess();
42  bool Init(const char * PlayList = nullptr);
43  bool InitForScenario(C4Group & hGroup);
44  bool Play(const char *szSongname = nullptr, bool fLoop = false, int fadetime_ms = 0, double max_resume_time = 0.0, bool allow_break = false);
45  bool Play(C4MusicFile *NewFile, bool fLoop, double max_resume_time);
46  bool Stop();
47  void FadeOut(int fadeout_ms);
48 
49  int SetPlayList(const char *szPlayList, bool fForceSwitch = false, int fadetime_ms = 0, double max_resume_time = 0.0);
50 
51  bool ToggleOnOff(); // keyboard callback
52 
53 protected:
54  // song list
57 
58  // play
60  int Volume; bool Loop;
61 
62  // fading between two songs
65 
66  // Wait time until next song
67  bool is_waiting;
69 
70  void LoadDir(const char *szPath); // load some music files (by wildcard / directory)
71  void Load(const char *szFile); // load a music file
72  void LoadMoreMusic(); // load music file names from MoreMusic.txt
73  void ClearSongs();
74 
75  bool GrpContainsMusic(C4Group &rGrp); // return whether this group contains music files
76 
77  bool ScheduleWaitTime();
78 
79  // SDL_mixer / OpenAL
81  bool InitializeMOD();
82  void DeinitializeMOD();
83 #if AUDIO_TK == AUDIO_TK_OPENAL
84 private:
85  ALCdevice* alcDevice;
86  ALCcontext* alcContext;
87 public:
88  void SelectContext();
89  ALCcontext *GetContext() const { return alcContext; }
90  ALCdevice *GetDevice() const { return alcDevice; }
91 #endif
92 public:
93  inline bool IsMODInitialized() {return MODInitialized;}
94 
95 private:
96  // scenario-defined music level
97  int32_t game_music_level;
98  // current play list
99  StdCopyStrBuf playlist;
100  bool playlist_valid;
101  // Set to nonzero to allow pauses between songs
102  int32_t music_break_min, music_break_max, music_break_chance;
103  // Maximum time (in seconds) last position in a song is remembered until it would just be restarted from the beginning
104  int32_t music_max_position_memory;
105 
106  static const int32_t DefaultMusicBreak;
107  static const int32_t DefaultMusicBreakChance;
108  static const int32_t DefaultMusicMaxPositionMemory;
109 
110 public:
111  void CompileFunc(class StdCompiler *comp);
112 
113  void SetMusicBreakMin(int32_t val) { music_break_min = std::max<int32_t>(val, 0); }
114  void SetMusicBreakMax(int32_t val) { music_break_max = std::max<int32_t>(val, 0); }
115  void SetMusicBreakChance(int32_t val) { music_break_chance = Clamp<int32_t>(val, 0, 100); }
116  void SetMusicMaxPositionMemory(int32_t val) { music_max_position_memory = val; }
117  int32_t SetGameMusicLevel(int32_t val);
118 };
119 
120 
121 // --- helper stuff --- //
122 
124 
125 class C4MusicFileInfoNode // We need this for the MoreMusic.txt stuff
126 {
127 public:
128  C4MusicFileInfoNode() { next=nullptr; str=nullptr; };
129  ~C4MusicFileInfoNode() { if (str) delete [] str; }
130  char* str;
133 };
134 
135 MusicType GetMusicFileTypeByExtension(const char* ext);
136 
137 #endif
void Execute(bool force_buffer_checks=false)
C4MusicFileInfoNode * next
void SetMusicBreakMax(int32_t val)
void SetMusicBreakMin(int32_t val)
C4MusicFile * FadeMusicFile
Definition: C4MusicSystem.h:63
void SelectContext()
bool Init(const char *PlayList=nullptr)
int SetPlayList(const char *szPlayList, bool fForceSwitch=false, int fadetime_ms=0, double max_resume_time=0.0)
void SetMusicBreakChance(int32_t val)
void LoadDir(const char *szPath)
MusicType
void Load(const char *szFile)
bool ScheduleWaitTime()
C4TimeMilliseconds wait_time_end
Definition: C4MusicSystem.h:68
C4TimeMilliseconds FadeTimeEnd
Definition: C4MusicSystem.h:64
void SetMusicMaxPositionMemory(int32_t val)
bool InitForScenario(C4Group &hGroup)
ALCdevice * GetDevice() const
Definition: C4MusicSystem.h:90
void FadeOut(int fadeout_ms)
int32_t SetGameMusicLevel(int32_t val)
C4TimeMilliseconds FadeTimeStart
Definition: C4MusicSystem.h:64
void DeinitializeMOD()
void CompileFunc(class StdCompiler *comp)
ALCcontext * GetContext() const
Definition: C4MusicSystem.h:89
MusicType GetMusicFileTypeByExtension(const char *ext)
bool GrpContainsMusic(C4Group &rGrp)
C4MusicFile * Songs
Definition: C4MusicSystem.h:55
C4MusicFile * upcoming_music_file
Definition: C4MusicSystem.h:63
bool InitializeMOD()
bool IsMODInitialized()
Definition: C4MusicSystem.h:93
C4MusicFile * PlayMusicFile
Definition: C4MusicSystem.h:59
bool Play(const char *szSongname=nullptr, bool fLoop=false, int fadetime_ms=0, double max_resume_time=0.0, bool allow_break=false)