OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MusicFileSDL Class Reference

#include <C4MusicFile.h>

Inheritance diagram for C4MusicFileSDL:
[legend]
Collaboration diagram for C4MusicFileSDL:
[legend]

Public Member Functions

 C4MusicFileSDL ()
 
 ~C4MusicFileSDL () override
 
bool Play (bool loop=false, double max_resume_time=0.0) override
 
void Stop (int fadeout_ms=0) override
 
void CheckIfPlaying () override
 
void SetVolume (int) override
 
virtual bool Init (const char *strFile)
 
virtual bool HasCategory (const char *szcat) const
 
virtual double GetRemainingTime ()
 
virtual bool HasResumePos () const
 
virtual void ClearResumePos ()
 
virtual C4TimeMilliseconds GetLastInterruptionTime () const
 
virtual StdStrBuf GetDebugInfo () const
 
bool IsLooping () const
 
bool HasBeenAnnounced () const
 
void Announce ()
 

Public Attributes

char FileName [_MAX_FNAME+1]
 
C4MusicFilepNext {nullptr}
 
int LastPlayed {-1}
 
bool NoPlay {false}
 
bool loop {false}
 
bool announced {false}
 

Protected Member Functions

bool ExtractFile ()
 
bool RemTempFile ()
 

Protected Attributes

char * Data
 
Mix_MusicMusic
 
bool SongExtracted {false}
 

Detailed Description

Definition at line 71 of file C4MusicFile.h.

Constructor & Destructor Documentation

C4MusicFileSDL::C4MusicFileSDL ( )

Definition at line 73 of file C4MusicFile.cpp.

73  :
74  Data(nullptr),
75  Music(nullptr)
76 {
77 }
Mix_Music * Music
Definition: C4MusicFile.h:82
C4MusicFileSDL::~C4MusicFileSDL ( )
override

Definition at line 79 of file C4MusicFile.cpp.

References Stop().

80 {
81  Stop();
82 }
void Stop(int fadeout_ms=0) override

Here is the call graph for this function:

Member Function Documentation

void C4MusicFile::Announce ( )
inherited

Definition at line 40 of file C4MusicFile.cpp.

References C4MusicFile::announced, C4MusicFile::FileName, GetFilename(), LoadResStr(), and LogF().

Referenced by C4MusicSystem::Play().

41 {
42  LogF(LoadResStr("IDS_PRC_PLAYMUSIC"), GetFilename(FileName));
43  announced = true;
44 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool announced
Definition: C4MusicFile.h:39
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:34

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MusicFileSDL::CheckIfPlaying ( )
overridevirtual

Implements C4MusicFile.

Definition at line 160 of file C4MusicFile.cpp.

References Application, C4Application::MusicSystem, and C4MusicSystem::NotifySuccess().

161 {
162  if (!Mix_PlayingMusic())
164 }
C4Application Application
Definition: C4Globals.cpp:44
C4MusicSystem MusicSystem
Definition: C4Application.h:41

Here is the call graph for this function:

virtual void C4MusicFile::ClearResumePos ( )
inlinevirtualinherited

Definition at line 49 of file C4MusicFile.h.

49 { }
bool C4MusicFile::ExtractFile ( )
protectedinherited

Definition at line 46 of file C4MusicFile.cpp.

References C4Config::AtTempPath(), C4CFN_TempMusic2, C4Group_CopyItem(), Config, C4MusicFile::FileName, and C4MusicFile::SongExtracted.

Referenced by Play().

47 {
48  // safety
49  if (SongExtracted) return true;
50  // extract entry
52  // ok
53  SongExtracted = true;
54  return true;
55 }
C4Config Config
Definition: C4Config.cpp:833
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
#define C4CFN_TempMusic2
Definition: C4Components.h:152
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
bool SongExtracted
Definition: C4MusicFile.h:65
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:34

Here is the call graph for this function:

Here is the caller graph for this function:

virtual StdStrBuf C4MusicFile::GetDebugInfo ( ) const
inlinevirtualinherited

Definition at line 52 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

52 { return StdStrBuf(FileName); }
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:34

Here is the caller graph for this function:

virtual C4TimeMilliseconds C4MusicFile::GetLastInterruptionTime ( ) const
inlinevirtualinherited

Definition at line 50 of file C4MusicFile.h.

virtual double C4MusicFile::GetRemainingTime ( )
inlinevirtualinherited

Definition at line 47 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

47 { return 0.0; }

Here is the caller graph for this function:

bool C4MusicFile::HasBeenAnnounced ( ) const
inlineinherited

Definition at line 56 of file C4MusicFile.h.

References C4MusicFile::announced.

Referenced by C4MusicSystem::Play().

56 { return announced; }
bool announced
Definition: C4MusicFile.h:39

Here is the caller graph for this function:

virtual bool C4MusicFile::HasCategory ( const char *  szcat) const
inlinevirtualinherited

Definition at line 46 of file C4MusicFile.h.

Referenced by C4MusicSystem::SetPlayList().

46 { return false; }

Here is the caller graph for this function:

virtual bool C4MusicFile::HasResumePos ( ) const
inlinevirtualinherited

Definition at line 48 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

48 { return false; }

Here is the caller graph for this function:

bool C4MusicFile::Init ( const char *  strFile)
virtualinherited

Definition at line 66 of file C4MusicFile.cpp.

References C4MusicFile::FileName, and SCopy().

Referenced by C4MusicSystem::Load().

67 {
68  SCopy(szFile, FileName);
69  return true;
70 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:34

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MusicFile::IsLooping ( ) const
inlineinherited

Definition at line 54 of file C4MusicFile.h.

References C4MusicFile::loop.

Referenced by C4MusicSystem::Play().

54 { return loop; }

Here is the caller graph for this function:

bool C4MusicFileSDL::Play ( bool  loop = false,
double  max_resume_time = 0.0 
)
overridevirtual

Implements C4MusicFile.

Definition at line 84 of file C4MusicFile.cpp.

References C4Config::AtTempPath(), C4CFN_TempMusic2, C4Group_ReadFile(), Config, Data, C4MusicFile::ExtractFile(), FileExists(), C4MusicFile::FileName, LogF(), Music, and C4MusicFile::SongExtracted.

85 {
86  const SDL_version * link_version = Mix_Linked_Version();
87  if (link_version->major < 1
88  || (link_version->major == 1 && link_version->minor < 2)
89  || (link_version->major == 1 && link_version->minor == 2 && link_version->patch < 7))
90  {
91  // Check existance and try extracting it
92  if (!FileExists(FileName)) if (!ExtractFile())
93  // Doesn't exist - or file is corrupt
94  {
95  LogF("Error reading %s", FileName);
96  return false;
97  }
98  // Load
100  // Load failed
101  if (!Music)
102  {
103  LogF("SDL_mixer: %s", SDL_GetError());
104  return false;
105  }
106  // Play Song
107  if (Mix_PlayMusic(Music, loop? -1 : 1) == -1)
108  {
109  LogF("SDL_mixer: %s", SDL_GetError());
110  return false;
111  }
112  }
113  else
114  {
115  // Load Song
116  // Fixme: Try loading this from the group incrementally for less lag
117  size_t filesize;
118  if (!C4Group_ReadFile(FileName, &Data, &filesize))
119  {
120  LogF("Error reading %s", FileName);
121  return false;
122  }
123  // Mix_FreeMusic frees the RWop
124  Music = Mix_LoadMUS_RW(SDL_RWFromConstMem(Data, filesize), 1);
125  if (!Music)
126  {
127  LogF("SDL_mixer: %s", SDL_GetError());
128  return false;
129  }
130  if (Mix_PlayMusic(Music, loop? -1 : 1) == -1)
131  {
132  LogF("SDL_mixer: %s", SDL_GetError());
133  return false;
134  }
135  }
136  return true;
137 }
C4Config Config
Definition: C4Config.cpp:833
bool ExtractFile()
Definition: C4MusicFile.cpp:46
bool FileExists(const char *szFileName)
#define C4CFN_TempMusic2
Definition: C4Components.h:152
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
bool C4Group_ReadFile(const char *szFile, char **pData, size_t *iSize)
Definition: C4Group.cpp:366
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
bool SongExtracted
Definition: C4MusicFile.h:65
Mix_Music * Music
Definition: C4MusicFile.h:82
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:34

Here is the call graph for this function:

bool C4MusicFile::RemTempFile ( )
protectedinherited

Definition at line 57 of file C4MusicFile.cpp.

References C4Config::AtTempPath(), C4CFN_TempMusic2, Config, EraseFile(), and C4MusicFile::SongExtracted.

Referenced by Stop().

58 {
59  if (!SongExtracted) return true;
60  // delete it
62  SongExtracted = false;
63  return true;
64 }
C4Config Config
Definition: C4Config.cpp:833
bool EraseFile(const char *szFileName)
#define C4CFN_TempMusic2
Definition: C4Components.h:152
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
bool SongExtracted
Definition: C4MusicFile.h:65

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MusicFileSDL::SetVolume ( int  iLevel)
overridevirtual

Implements C4MusicFile.

Definition at line 166 of file C4MusicFile.cpp.

167 {
168  Mix_VolumeMusic((int) ((iLevel * MIX_MAX_VOLUME) / 100));
169 }
void C4MusicFileSDL::Stop ( int  fadeout_ms = 0)
overridevirtual

Implements C4MusicFile.

Definition at line 139 of file C4MusicFile.cpp.

References Data, Music, and C4MusicFile::RemTempFile().

Referenced by ~C4MusicFileSDL().

140 {
141  if (fadeout_ms && Music)
142  {
143  // Don't really stop yet
144  Mix_FadeOutMusic(fadeout_ms);
145  return;
146  }
147  if (Music)
148  {
149  Mix_FreeMusic(Music);
150  Music = nullptr;
151  }
152  RemTempFile();
153  if (Data)
154  {
155  delete[] Data;
156  Data = nullptr;
157  }
158 }
bool RemTempFile()
Definition: C4MusicFile.cpp:57
Mix_Music * Music
Definition: C4MusicFile.h:82

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4MusicFile::announced {false}
inherited

Definition at line 39 of file C4MusicFile.h.

Referenced by C4MusicFile::Announce(), and C4MusicFile::HasBeenAnnounced().

char* C4MusicFileSDL::Data
protected

Definition at line 81 of file C4MusicFile.h.

Referenced by Play(), and Stop().

char C4MusicFile::FileName[_MAX_FNAME+1]
inherited
int C4MusicFile::LastPlayed {-1}
inherited

Definition at line 36 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

bool C4MusicFile::loop {false}
inherited

Definition at line 38 of file C4MusicFile.h.

Referenced by C4MusicFile::IsLooping().

Mix_Music* C4MusicFileSDL::Music
protected

Definition at line 82 of file C4MusicFile.h.

Referenced by Play(), and Stop().

bool C4MusicFile::NoPlay {false}
inherited

Definition at line 37 of file C4MusicFile.h.

Referenced by C4MusicSystem::SetPlayList().

bool C4MusicFile::SongExtracted {false}
protectedinherited

Definition at line 65 of file C4MusicFile.h.

Referenced by C4MusicFile::ExtractFile(), Play(), and C4MusicFile::RemTempFile().


The documentation for this class was generated from the following files: