Converted music files to XML

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4741 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-02-16 01:18:40 +00:00
parent 11b0f5b226
commit b9af327a29
2 changed files with 80 additions and 15 deletions

View File

@@ -24,17 +24,16 @@
#include "audio/music_ogg.hpp"
#include "config/user_config.hpp"
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
#include "io/file_manager.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/string_utils.hpp"
MusicInformation::MusicInformation(const std::string& filename)
MusicInformation::MusicInformation(const std::string& filename) throw (std::runtime_error)
{
m_title = "";
m_composer = "";
m_numLoops = LOOP_FOREVER;
//m_numLoops = LOOP_FOREVER;
m_normal_filename = "";
m_fast_filename = "";
m_normal_music = NULL;
@@ -45,7 +44,7 @@ MusicInformation::MusicInformation(const std::string& filename)
m_gain = 1.0f;
m_adjustedGain = 1.0f;
if(StringUtils::getExtension(filename)!="music")
if (StringUtils::getExtension(filename) != "music")
{
// Create information just from ogg file
// -------------------------------------
@@ -57,6 +56,70 @@ MusicInformation::MusicInformation(const std::string& filename)
// Otherwise read config file
// --------------------------
XMLNode* root = file_manager->createXMLTree(filename);
if (!root)
{
std::cerr << "Could not read music XML file " << filename.c_str() << std::endl;
throw std::runtime_error("Can open music XML file");
}
const int amount = root->getNumNodes();
for (int i=0; i<amount; i++)
{
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 '<title value=' attribute is mandatory in the music XML file!\n");
throw std::runtime_error("Incomplete or corrupt music XML file");
return;
}
}
else if (node->getName() == "composer")
{
if (node->get("value", &m_composer) == 0)
{
fprintf(stderr, "/!\\ The '<composer value=' attribute is mandatory in the music XML file!\n");
throw std::runtime_error("Incomplete or corrupt music XML file");
return;
}
}
else if (node->getName() == "file")
{
if (node->get("value", &m_normal_filename) == 0)
{
fprintf(stderr, "/!\\ The '<file value=' attribute is mandatory in the music XML file!\n");
throw std::runtime_error("Incomplete or corrupt music XML file");
return;
}
}
else if (node->getName() == "gain")
{
node->get("gain", &m_gain);
}
else
{
std::cerr << "Unknown node in music XML file : " << node->getName().c_str() << std::endl;
throw std::runtime_error("Unknown node in music XML file");
}
}// nend for
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;
/*
lisp::Parser parser;
const lisp::Lisp* const ROOT = parser.parse(filename);
@@ -85,18 +148,18 @@ MusicInformation::MusicInformation(const std::string& filename)
LISP->getVector("tracks", m_all_tracks );
LISP->get ("gain", m_gain );
m_adjustedGain = m_gain;
*/
// 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;
// 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;
// Get the path from the filename and add it to the ogg filename
if(m_fast_filename!="")
if (m_fast_filename != "")
{
m_fast_filename=path+"/"+m_fast_filename;
m_fast_filename = path + "/" + m_fast_filename;
}
delete ROOT;
} // MusicInformation

View File

@@ -21,6 +21,7 @@
#define HEADER_MUSIC_INFORMATION_HPP
#include <string>
#include <stdexcept>
#include <vector>
class Music;
@@ -33,7 +34,8 @@ private:
std::string m_normal_filename;
std::string m_fast_filename;
std::vector<std::string> m_all_tracks;
int m_numLoops;
//int m_numLoops;
/** If faster music is enabled at all (either separate file or using
* the pitch shift approach). */
bool m_enable_fast;
@@ -54,12 +56,12 @@ private:
float m_time_since_faster;
public:
MusicInformation (const std::string& filename);
MusicInformation (const std::string& filename) throw (std::runtime_error);
const std::string& getComposer () const {return m_composer; }
const std::string& getTitle () const {return m_title; }
const std::string& getNormalFilename() const {return m_normal_filename; }
const std::string& getFastFilename () const {return m_fast_filename; }
int getNumLoops () const {return m_numLoops; }
//int getNumLoops () const {return m_numLoops; }
float getFasterTime () const {return m_faster_time; }
float getMaxPitch () const {return m_max_pitch; }
void addMusicToTracks ();