Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Types | Private Member Functions | Private Attributes
SoundManager Class Reference

#include <sound_manager.hpp>

Collaboration diagram for SoundManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SoundManager ()
virtual ~SoundManager ()
void playSfx (unsigned int id)
void startMusic (MusicInformation *mi)
void stopMusic ()
void update (float dt)
void pauseMusic ()
void resumeMusic ()
void switchToFastMusic ()
MusicInformationgetCurrentMusic ()
MusicInformationgetMusicInformation (const std::string &filename)
void loadMusicFromOneDir (const std::string &dir)
void addMusicToTracks ()

Private Types

typedef std::vector< SFX * > SFXsType

Private Member Functions

void loadMusicInformation ()

Private Attributes

SFXsType m_sfxs
MusicInformationm_current_music
bool m_initialized
std::map< std::string,
MusicInformation * > 
m_allMusic

Detailed Description

Definition at line 40 of file sound_manager.hpp.


Member Typedef Documentation

typedef std::vector<SFX*> SoundManager::SFXsType [private]

Definition at line 44 of file sound_manager.hpp.


Constructor & Destructor Documentation

Definition at line 46 of file sound_manager.cpp.

                           : m_sfxs(NUM_SOUNDS)
{
    m_current_music= NULL;
    if(alutInit(0, NULL) == AL_TRUE)  // init OpenAL sound system
        m_initialized = true;
    else
    {
        fprintf(stderr, "WARNING: Could not initialize the ALUT based sound.\n");
        m_initialized = false;
    }

    alGetError(); //Called here to clear any non-important errors found

    if (m_initialized)
    {
        // must be in sync with enumSoundSFX
        m_sfxs[SOUND_UGH          ] = new SFXImpl("ugh.wav");
        m_sfxs[SOUND_WINNER       ] = new SFXImpl("radio/grandprix_winner.wav");
        m_sfxs[SOUND_GRAB         ] = new SFXImpl("tintagel/grab_collectable.wav");
        m_sfxs[SOUND_CRASH        ] = new SFXImpl("tintagel/crash.wav");
        m_sfxs[SOUND_SHOT         ] = new SFXImpl("radio/shot.wav");
        m_sfxs[SOUND_EXPLOSION    ] = new SFXImpl("explosion.wav");
        m_sfxs[SOUND_BZZT         ] = new SFXImpl("bzzt.wav");
        m_sfxs[SOUND_BEEP         ] = new SFXImpl("radio/horn.wav");
        m_sfxs[SOUND_USE_ANVIL    ] = new SFXImpl("radio/slap.wav");
        m_sfxs[SOUND_USE_PARACHUTE] = new SFXImpl("radio/squeaky.wav");
        m_sfxs[SOUND_WEE          ] = new SFXImpl("wee.wav"); 
        m_sfxs[SOUND_BACK_MENU    ] = new SFXImpl("tintagel/deselect_option.wav");
        m_sfxs[SOUND_SELECT_MENU  ] = new SFXImpl("tintagel/select_option.wav"); 
        m_sfxs[SOUND_MOVE_MENU    ] = new SFXImpl("tintagel/move_option.wav");
        m_sfxs[SOUND_FULL         ] = new SFXImpl("tintagel/energy_bar_full.wav");
        m_sfxs[SOUND_PRESTART     ] = new SFXImpl("tintagel/pre_start_race.wav");
        m_sfxs[SOUND_START        ] = new SFXImpl("tintagel/start_race.wav");
        m_sfxs[SOUND_MISSILE_LOCK ] = new SFXImpl("radio/radarping.wav");
    }

    loadMusicInformation();
}  // SoundManager

Here is the call graph for this function:

Definition at line 86 of file sound_manager.cpp.

{
    // SFX cleanup
    for(SFXsType::iterator it= m_sfxs.begin(); it != m_sfxs.end(); it++)
    {
        delete *it;
    }
    m_sfxs.empty();

    if(m_initialized)
    {
        alutExit();
    }
}   // ~SoundManager

Member Function Documentation

Definition at line 127 of file sound_manager.cpp.

{
    for(std::map<std::string,MusicInformation*>::iterator i=m_allMusic.begin();
                                                          i!=m_allMusic.end(); i++)
    {
        if(!i->second) 
        {
            fprintf(stderr, "Can't find music file '%s' - ignored.\n",
                    i->first.c_str());
            continue;
        }
        i->second->addMusicToTracks();
    }
}   // addMusicToTracks

Here is the caller graph for this function:

Definition at line 71 of file sound_manager.hpp.

{return m_current_music; }    

Here is the caller graph for this function:

MusicInformation * SoundManager::getMusicInformation ( const std::string &  filename)

Definition at line 143 of file sound_manager.cpp.

{
    if(filename=="")
    {
        return NULL;
    }
    const std::string basename = StringUtils::basename(filename);
    MusicInformation* mi = m_allMusic[basename];
    if(!mi)
    {
        mi = new MusicInformation(filename);
        m_allMusic[basename] = mi;
    }
    return mi;
}   // SoundManager

Here is the call graph for this function:

Here is the caller graph for this function:

void SoundManager::loadMusicFromOneDir ( const std::string &  dir)

Definition at line 114 of file sound_manager.cpp.

{
    std::set<std::string> files;
    file_manager->listFiles(files, dir, /*is_full_path*/ true,
                            /*make_full_path*/ true);
    for(std::set<std::string>::iterator i = files.begin(); i != files.end(); ++i)
    {
        if(StringUtils::extension(*i)!="music") continue;
        m_allMusic[StringUtils::basename(*i)] = new MusicInformation(*i);
    }   // for i
} // loadMusicFromOneDir

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 102 of file sound_manager.cpp.

{
    // Load music files from data/music, and dirs defined in SUPERTUXKART_MUSIC_PATH
    std::vector<std::string> allMusicDirs=file_manager->getMusicDirs();
    for(std::vector<std::string>::iterator dir=allMusicDirs.begin();
                                           dir!=allMusicDirs.end(); dir++)
    {
        loadMusicFromOneDir(*dir);
    }   // for dir
}   // loadMusicInformation

Here is the call graph for this function:

Here is the caller graph for this function:

void SoundManager::pauseMusic ( ) [inline]

Definition at line 65 of file sound_manager.hpp.

Here is the call graph for this function:

void SoundManager::playSfx ( unsigned int  id)

Definition at line 159 of file sound_manager.cpp.

{
    if(!user_config->doSFX() || !m_initialized) return;

    assert(id>=0 && id<m_sfxs.size() && m_sfxs[id]);
    m_sfxs[id]->play();

}   // playSfx

Here is the call graph for this function:

Here is the caller graph for this function:

void SoundManager::resumeMusic ( ) [inline]

Definition at line 67 of file sound_manager.hpp.

Here is the call graph for this function:

Definition at line 169 of file sound_manager.cpp.

{
    m_current_music = mi;
    
    if(!mi || !user_config->doMusic() || !m_initialized) return;
    
    mi->startMusic();
}   // startMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 179 of file sound_manager.cpp.

{
    if(m_current_music) m_current_music->stopMusic();
}   // stopMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file sound_manager.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void SoundManager::update ( float  dt) [inline]

Definition at line 63 of file sound_manager.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::map<std::string, MusicInformation*> SoundManager::m_allMusic [private]

Definition at line 53 of file sound_manager.hpp.

Definition at line 47 of file sound_manager.hpp.

Definition at line 49 of file sound_manager.hpp.

Definition at line 46 of file sound_manager.hpp.


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