Back to index

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

#include <music_information.hpp>

Collaboration diagram for MusicInformation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MusicInformation (const std::string &filename)
const std::string & getComposer () const
const std::string & getTitle () const
const std::string & getNormalFilename () const
const std::string & getFastFilename () const
int getNumLoops () const
float getFasterTime () const
float getMaxPitch () const
void addMusicToTracks ()
void update (float dt)
void startMusic ()
void stopMusic ()
void pauseMusic ()
void resumeMusic ()
void switchToFastMusic ()

Private Types

enum  { SOUND_NORMAL, SOUND_FADING, SOUND_FASTER, SOUND_FAST }

Private Attributes

std::string m_composer
std::string m_title
std::string m_normal_filename
std::string m_fast_filename
std::vector< std::string > m_all_tracks
int m_numLoops
float m_faster_time
float m_max_pitch
Musicm_normal_music
Musicm_fast_music
enum MusicInformation:: { ... }  m_mode
float m_time_since_faster

Static Private Attributes

static const int LOOP_FOREVER = -1

Detailed Description

Definition at line 27 of file music_information.hpp.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
SOUND_NORMAL 
SOUND_FADING 
SOUND_FASTER 
SOUND_FAST 

Definition at line 42 of file music_information.hpp.

         {SOUND_NORMAL,                        // normal music is played
          SOUND_FADING,                        // normal music fading out, faster fading in
          SOUND_FASTER,                        // change pitch of normal music
          SOUND_FAST}                          // playing faster music or max pitch reached

Constructor & Destructor Documentation

MusicInformation::MusicInformation ( const std::string &  filename)

Definition at line 37 of file music_information.cpp.

{
    m_title           = "";
    m_composer        = "";
    m_numLoops        = LOOP_FOREVER;
    m_normal_filename = "";
    m_fast_filename   = "";
    m_normal_music    = NULL;
    m_fast_music      = NULL;
    m_faster_time     = 1.0f;
    m_max_pitch       = 0.1f;

    if(StringUtils::extension(filename)!="music")
    {
        // Create information just from ogg file
        // -------------------------------------
        m_title           = StringUtils::without_extension(StringUtils::basename(filename));
        m_normal_filename = filename;
        return;
    }
   

    // Otherwise read config file
    // --------------------------
    lisp::Parser parser;
    const lisp::Lisp* const ROOT = parser.parse(filename);

    const lisp::Lisp* const LISP = ROOT->getLisp("music-information");
    if(!LISP)
    {
        delete ROOT;
        char msg[MAX_ERROR_MESSAGE_LENGTH];
        snprintf(msg, sizeof(msg), 
                 "Couldn't load music information '%s': no music-information node.",
                 filename.c_str());
        throw std::runtime_error(msg);
    }
    LISP->get      ("title",       m_title          );
    LISP->get      ("composer",    m_composer       );
    LISP->get      ("loop",        m_numLoops       );
    LISP->get      ("music",       m_normal_filename);
    LISP->get      ("fast-music",  m_fast_filename  );
    // m_faster_time is used for twice: either as time to fade in faster music
    // (if available), or the time to increase the pitch (if no faster music 
    // is available). We allow each .music file to use any of the two names. 
    // LISP->get doesn't change the value if the item is not found.
    LISP->get      ("fade-time",   m_faster_time    );
    LISP->get      ("faster-time", m_faster_time    );
    LISP->get      ("max-pitch",   m_max_pitch      );
    LISP->getVector("tracks",      m_all_tracks     );

    // Get the path from the filename and add it to the ogg filename
    std::string path=StringUtils::path(filename);
    m_normal_filename=path+"/"+m_normal_filename;

    // Get the path from the filename and add it to the ogg filename
    if(m_fast_filename!="")
    {
        m_fast_filename=path+"/"+m_fast_filename;
    }

    delete ROOT;

}   // MusicInformation

Here is the call graph for this function:


Member Function Documentation

Definition at line 103 of file music_information.cpp.

{
    for(int i=0; i<(int)m_all_tracks.size(); i++)
    {
        Track* track=track_manager->getTrack(m_all_tracks[i]);
        if(track) track->addMusic(this);
    }
}   // addMusicToTracks

Here is the call graph for this function:

const std::string& MusicInformation::getComposer ( ) const [inline]

Definition at line 51 of file music_information.hpp.

{return m_composer;        }

Here is the caller graph for this function:

float MusicInformation::getFasterTime ( ) const [inline]

Definition at line 56 of file music_information.hpp.

{return m_faster_time;     }
const std::string& MusicInformation::getFastFilename ( ) const [inline]

Definition at line 54 of file music_information.hpp.

{return m_fast_filename;   }
float MusicInformation::getMaxPitch ( ) const [inline]

Definition at line 57 of file music_information.hpp.

{return m_max_pitch;       }
const std::string& MusicInformation::getNormalFilename ( ) const [inline]

Definition at line 53 of file music_information.hpp.

{return m_normal_filename; }
int MusicInformation::getNumLoops ( ) const [inline]

Definition at line 55 of file music_information.hpp.

{return m_numLoops;        }
const std::string& MusicInformation::getTitle ( ) const [inline]

Definition at line 52 of file music_information.hpp.

{return m_title;           }

Here is the caller graph for this function:

Definition at line 235 of file music_information.cpp.

{
    if (m_normal_music != NULL) m_normal_music->pauseMusic();
    if (m_fast_music   != NULL) m_fast_music->pauseMusic();
}   // pauseMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 241 of file music_information.cpp.

{
    if (m_normal_music != NULL) m_normal_music->resumeMusic();
    if (m_fast_music   != NULL) m_fast_music->resumeMusic();
}   // resumeMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file music_information.cpp.

{
    m_time_since_faster  = 0.0f;
    m_mode               = SOUND_NORMAL;

    if (m_normal_filename== "") return;

    // First load the 'normal' music
    // -----------------------------
    if(StringUtils::extension(m_normal_filename)!="ogg")
    {
        fprintf(stderr, "WARNING: music file %s format not recognized.\n", 
                m_normal_filename.c_str());
        return;
    }
    m_normal_music = new MusicOggStream();

    if((m_normal_music->load(m_normal_filename)) == false)
    {
        delete m_normal_music;
        m_normal_music=0;
           fprintf(stderr, "WARNING: Unabled to load music %s, not supported or not found.\n", 
                m_normal_filename.c_str());
        return;
    }
    m_normal_music->playMusic();

    // Then (if available) load the music for the last track
    // -----------------------------------------------------
    if(m_fast_filename=="") 
    {
        m_fast_music = NULL;
        return;   // no fast music
    }

    if(StringUtils::extension(m_fast_filename)!="ogg")
    {
        fprintf(stderr, 
                "WARNING: music file %s format not recognized, fast music is ignored\n", 
                m_fast_filename.c_str());
        return;
    }
    m_fast_music= new MusicOggStream();

    if((m_fast_music->load(m_fast_filename)) == false)
    {
        delete m_fast_music;
        m_fast_music=0;
           fprintf(stderr, "WARNING: Unabled to load fast music %s, not supported or not found.\n", 
                m_fast_filename.c_str());
        return;
    }
}   // startMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 220 of file music_information.cpp.

{
    if (m_normal_music != NULL)  
    {
        m_normal_music->stopMusic();
        m_normal_music = NULL;
    }
    if (m_fast_music   != NULL)
    {
        m_fast_music->stopMusic();
        m_fast_music=NULL;
    }
}   // stopMusic

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 248 of file music_information.cpp.

{    
    m_time_since_faster = 0.0f;
    if(m_fast_music)
    {
        m_mode = SOUND_FADING;
        m_fast_music->playMusic();
    }
    else
    {
        // FIXME: for now this music is too annoying, 
        m_mode = SOUND_FASTER;
    }
}   // switchToFastMusic

Here is the call graph for this function:

Here is the caller graph for this function:

void MusicInformation::update ( float  dt)

Definition at line 168 of file music_information.cpp.

{
    switch(m_mode)
    {
    case SOUND_FADING: {
        if ( m_normal_music == NULL || m_fast_music == NULL ) break;

        m_time_since_faster +=dt;
        if(m_time_since_faster>=m_faster_time)
        {
            m_mode=SOUND_FAST;
            m_normal_music->stopMusic();
            m_fast_music->update();
            return;
        }
        float fraction=m_time_since_faster/m_faster_time;
        m_normal_music->updateFading(1-fraction);
        m_fast_music->updateFading(fraction);
        break;
                       }
    case SOUND_FASTER: {
        if ( m_normal_music == NULL ) break;

        m_time_since_faster +=dt;
        if(m_time_since_faster>=m_faster_time)
        {
            // Once the pitch is adjusted, just switch back to normal
            // mode. We can't switch to fast music mode, since this would
            // play m_fast_music, which isn't available.
            m_mode=SOUND_NORMAL;
            return;
        }
        float fraction=m_time_since_faster/m_faster_time;
        m_normal_music->updateFaster(fraction, m_max_pitch);

        break;
                       }
    case SOUND_NORMAL:
        if ( m_normal_music == NULL ) break;

        m_normal_music->update();
        break;
    case SOUND_FAST:
        if ( m_fast_music == NULL ) break;

        m_fast_music->update();
        break;
    }   // switch

}   // update

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const int MusicInformation::LOOP_FOREVER = -1 [static, private]

Definition at line 39 of file music_information.hpp.

std::vector<std::string> MusicInformation::m_all_tracks [private]

Definition at line 34 of file music_information.hpp.

std::string MusicInformation::m_composer [private]

Definition at line 30 of file music_information.hpp.

std::string MusicInformation::m_fast_filename [private]

Definition at line 33 of file music_information.hpp.

Definition at line 40 of file music_information.hpp.

Definition at line 36 of file music_information.hpp.

Definition at line 38 of file music_information.hpp.

enum { ... } MusicInformation::m_mode [private]
std::string MusicInformation::m_normal_filename [private]

Definition at line 32 of file music_information.hpp.

Definition at line 40 of file music_information.hpp.

Definition at line 35 of file music_information.hpp.

Definition at line 47 of file music_information.hpp.

std::string MusicInformation::m_title [private]

Definition at line 31 of file music_information.hpp.


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