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 ()
 
bool Play (bool loop=false, double max_resume_time=0.0)
 
void Stop (int fadeout_ms=0)
 
void CheckIfPlaying ()
 
void SetVolume (int)
 
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
 
int LastPlayed
 
bool NoPlay
 
bool loop
 
bool announced
 

Protected Member Functions

bool ExtractFile ()
 
bool RemTempFile ()
 

Protected Attributes

char * Data
 
Mix_MusicMusic
 
bool SongExtracted
 

Detailed Description

Definition at line 73 of file C4MusicFile.h.

Constructor & Destructor Documentation

C4MusicFileSDL::C4MusicFileSDL ( )

Definition at line 74 of file C4MusicFile.cpp.

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

Definition at line 80 of file C4MusicFile.cpp.

References Stop().

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

Here is the call graph for this function:

Member Function Documentation

void C4MusicFile::Announce ( )
inherited

Definition at line 41 of file C4MusicFile.cpp.

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

Referenced by C4MusicSystem::Play().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MusicFileSDL::CheckIfPlaying ( )
virtual

Implements C4MusicFile.

Definition at line 161 of file C4MusicFile.cpp.

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

162 {
163  if (!Mix_PlayingMusic())
165 }
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 51 of file C4MusicFile.h.

51 { }
bool C4MusicFile::ExtractFile ( )
protectedinherited

Definition at line 47 of file C4MusicFile.cpp.

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

Referenced by Play().

48 {
49  // safety
50  if (SongExtracted) return true;
51  // extract entry
53  // ok
54  SongExtracted = true;
55  return true;
56 }
C4Config Config
Definition: C4Config.cpp:837
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:544
bool SongExtracted
Definition: C4MusicFile.h:67
char FileName[_MAX_FNAME+1]
Definition: C4MusicFile.h:36

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 54 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

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

Here is the caller graph for this function:

virtual C4TimeMilliseconds C4MusicFile::GetLastInterruptionTime ( ) const
inlinevirtualinherited

Definition at line 52 of file C4MusicFile.h.

virtual double C4MusicFile::GetRemainingTime ( )
inlinevirtualinherited

Definition at line 49 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

49 { return 0.0; }

Here is the caller graph for this function:

bool C4MusicFile::HasBeenAnnounced ( ) const
inlineinherited

Definition at line 58 of file C4MusicFile.h.

References C4MusicFile::announced.

Referenced by C4MusicSystem::Play().

58 { return announced; }
bool announced
Definition: C4MusicFile.h:41

Here is the caller graph for this function:

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

Definition at line 48 of file C4MusicFile.h.

Referenced by C4MusicSystem::SetPlayList().

48 { return false; }

Here is the caller graph for this function:

virtual bool C4MusicFile::HasResumePos ( ) const
inlinevirtualinherited

Definition at line 50 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

50 { return false; }

Here is the caller graph for this function:

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

Definition at line 67 of file C4MusicFile.cpp.

References C4MusicFile::FileName, and SCopy().

Referenced by C4MusicSystem::Load().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MusicFile::IsLooping ( ) const
inlineinherited

Definition at line 56 of file C4MusicFile.h.

References C4MusicFile::loop.

Referenced by C4MusicSystem::Play().

56 { return loop; }

Here is the caller graph for this function:

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

Implements C4MusicFile.

Definition at line 85 of file C4MusicFile.cpp.

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

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

Here is the call graph for this function:

bool C4MusicFile::RemTempFile ( )
protectedinherited

Definition at line 58 of file C4MusicFile.cpp.

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

Referenced by Stop().

59 {
60  if (!SongExtracted) return true;
61  // delete it
63  SongExtracted = false;
64  return true;
65 }
C4Config Config
Definition: C4Config.cpp:837
bool EraseFile(const char *szFilename)
Definition: StdFile.cpp:495
#define C4CFN_TempMusic2
Definition: C4Components.h:152
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:544
bool SongExtracted
Definition: C4MusicFile.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MusicFileSDL::SetVolume ( int  iLevel)
virtual

Implements C4MusicFile.

Definition at line 167 of file C4MusicFile.cpp.

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

Implements C4MusicFile.

Definition at line 140 of file C4MusicFile.cpp.

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

Referenced by ~C4MusicFileSDL().

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

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4MusicFile::announced
inherited

Definition at line 41 of file C4MusicFile.h.

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

char* C4MusicFileSDL::Data
protected

Definition at line 83 of file C4MusicFile.h.

Referenced by Play(), and Stop().

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

Definition at line 38 of file C4MusicFile.h.

Referenced by C4MusicSystem::Play().

bool C4MusicFile::loop
inherited

Definition at line 40 of file C4MusicFile.h.

Referenced by C4MusicFile::IsLooping().

Mix_Music* C4MusicFileSDL::Music
protected

Definition at line 84 of file C4MusicFile.h.

Referenced by Play(), and Stop().

bool C4MusicFile::NoPlay
inherited

Definition at line 39 of file C4MusicFile.h.

Referenced by C4MusicSystem::SetPlayList().

bool C4MusicFile::SongExtracted
protectedinherited

Definition at line 67 of file C4MusicFile.h.

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


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