From e97c486c7771d5d0685dc54a95e0bca67dca5f79 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 30 Aug 2010 23:21:06 +0000 Subject: [PATCH] 1) Fixed .music XML files and reading code to be more in line with our 'standard' way of using xml files. 2) Some code cleanup. 3) Added support for specifying tracks in .music files again. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5832 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/audio/music_information.cpp | 109 +++++++++++++------------------- src/audio/music_information.hpp | 2 +- 2 files changed, 44 insertions(+), 67 deletions(-) diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index 694fa9470..64391833f 100644 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -43,7 +43,7 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt m_faster_time = 1.0f; m_max_pitch = 0.1f; m_gain = 1.0f; - m_adjustedGain = 1.0f; + m_adjusted_gain = 1.0f; if (StringUtils::getExtension(filename) != "music") { @@ -53,74 +53,52 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt m_normal_filename = filename; return; } - // Otherwise read config file // -------------------------- - XMLNode* root = file_manager->createXMLTree(filename); if (!root) { - throw std::runtime_error("Can open music XML file"); + std::ostringstream msg; + msg << "Could not open music XML file '"<getNumNodes(); - for (int i=0; igetName()!="music") { - const XMLNode* node = root->getNode(i); - - if (node->getName() == "music") - { - // outer node, ignore - } - else if (node->getName() == "title") - { - if (node->get("value", &m_title) == 0) - { - fprintf(stderr, "/!\\ The 'get("title", &m_title)) + { + fprintf(stderr, + "The 'title' attribute is missing in the music XML file '%s'!\n", + filename.c_str()); + throw std::runtime_error("Incomplete or corrupt music XML file"); + return; + } + if(!root->get("composer", &m_composer)) + { + fprintf(stderr, + "The 'composer' attribute is missing in the music XML file '%s'!\n", + filename.c_str()); + throw std::runtime_error("Incomplete or corrupt music XML file"); + return; + } + if(!root->get("file", &m_normal_filename)) + { + fprintf(stderr, + "The 'file' attribute is mandatory in the music XML file '%s'!\n", + filename.c_str()); + throw std::runtime_error("Incomplete or corrupt music XML file"); + return; + } + root->get("gain", &m_adjusted_gain); + root->get("tracks", &m_all_tracks ); + root->get("fast", &m_enable_fast ); + root->get("fast-filename", &m_fast_filename); delete root; - //TODO: not implemented back (is this useful in any way?) - // LISP->getVector("tracks", m_all_tracks ); - - //TODO: not implemented back (is this used in any way?) - m_enable_fast = false; - // Get the path from the filename and add it to the ogg filename std::string path = StringUtils::getPath(filename); m_normal_filename = path + "/" + m_normal_filename; @@ -131,7 +109,6 @@ MusicInformation::MusicInformation(const std::string& filename) throw (std::runt m_fast_filename = path + "/" + m_fast_filename; } - } // MusicInformation //----------------------------------------------------------------------------- @@ -151,7 +128,7 @@ void MusicInformation::startMusic() m_mode = SOUND_NORMAL; std::cout << "startMusic : m_normal_filename=<" << m_normal_filename.c_str() << ">, gain=" - << m_adjustedGain << "\n"; + << m_adjusted_gain << "\n"; if (m_normal_filename== "") return; @@ -173,7 +150,7 @@ void MusicInformation::startMusic() m_normal_filename.c_str()); return; } - m_normal_music->volumeMusic(m_adjustedGain); + m_normal_music->volumeMusic(m_adjusted_gain); m_normal_music->playMusic(); // Then (if available) load the music for the last track @@ -201,7 +178,7 @@ void MusicInformation::startMusic() m_fast_filename.c_str()); return; } - m_fast_music->volumeMusic(m_adjustedGain); + m_fast_music->volumeMusic(m_adjusted_gain); } // startMusic //----------------------------------------------------------------------------- @@ -289,9 +266,9 @@ void MusicInformation::volumeMusic(float gain) { // printf("Setting master volume %f\n", gain); - m_adjustedGain = m_gain * gain; - if (m_normal_music != NULL) m_normal_music->volumeMusic(m_adjustedGain); - if (m_fast_music != NULL) m_fast_music->volumeMusic(m_adjustedGain); + m_adjusted_gain = m_gain * gain; + if (m_normal_music != NULL) m_normal_music->volumeMusic(m_adjusted_gain); + if (m_fast_music != NULL) m_fast_music->volumeMusic(m_adjusted_gain); } // volumeMusic //----------------------------------------------------------------------------- diff --git a/src/audio/music_information.hpp b/src/audio/music_information.hpp index 2dfd5cf61..b39044f45 100644 --- a/src/audio/music_information.hpp +++ b/src/audio/music_information.hpp @@ -47,7 +47,7 @@ private: bool m_enable_fast; float m_gain; - float m_adjustedGain; + float m_adjusted_gain; /** Either time for fading faster music in, or time to change pitch */ float m_faster_time;