sound_music_track.cpp

Go to the documentation of this file.
00001 /* $Id: sound_music_track.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Copyright (C) 2009 - 2012 by Ignacio R. Morelle <shadowm2006@gmail.com>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 #include "sound_music_track.hpp"
00018 
00019 #include "config.hpp"
00020 #include "filesystem.hpp"
00021 #include "log.hpp"
00022 #include "serialization/string_utils.hpp"
00023 #include "util.hpp"
00024 
00025 static lg::log_domain log_audio("audio");
00026 #define ERR_AUDIO LOG_STREAM(err, log_audio)
00027 #define LOG_AUDIO LOG_STREAM(info, log_audio)
00028 
00029 namespace sound {
00030 
00031 music_track::music_track() :
00032     id_(),
00033     file_path_(),
00034     ms_before_(0),
00035     ms_after_(0),
00036     once_(false),
00037     append_(false),
00038     immediate_(false)
00039 {
00040 }
00041 
00042 music_track::music_track(const config& node) :
00043     id_(node["name"]),
00044     file_path_(),
00045     ms_before_(node["ms_before"]),
00046     ms_after_(node["ms_after"]),
00047     once_(node["play_once"].to_bool()),
00048     append_(node["append"].to_bool()),
00049     immediate_(node["immediate"].to_bool())
00050 {
00051     resolve();
00052 }
00053 
00054 music_track::music_track(const std::string& v_name) :
00055     id_(v_name),
00056     file_path_(),
00057     ms_before_(0),
00058     ms_after_(0),
00059     once_(false),
00060     append_(false),
00061     immediate_(false)
00062 {
00063     resolve();
00064 }
00065 
00066 void music_track::resolve()
00067 {
00068     if (id_.empty()) {
00069         ERR_AUDIO << "empty track filename specified\n";
00070         return;
00071     }
00072 
00073     file_path_ = get_binary_file_location("music", id_);
00074 
00075     if (file_path_.empty()) {
00076         ERR_AUDIO << "could not find track '" << id_ << "'\n";
00077         return;
00078     }
00079 
00080     LOG_AUDIO << "resolved music track '" << id_ << "' into '" << file_path_ << "'\n";
00081 }
00082 
00083 void music_track::write(config &parent_node, bool append)
00084 {
00085     config& m = parent_node.add_child("music");
00086     m["name"] = id_;
00087     m["ms_before"] = ms_before_;
00088     m["ms_after"] = ms_after_;
00089     if(append) {
00090         m["append"] = true;
00091     }
00092 }
00093 
00094 } /* end namespace sound */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs