#include #include "project.h" namespace Ember { Project::Project(boost::filesystem::path projectFilePath) : m_path(projectFilePath), m_name(), m_bitsPerChannel(8), m_audioSampleRate(48000), m_rootItem(projectFilePath.parent_path(), nullptr, this) { } boost::filesystem::path Project::path() const { return m_path; } std::string Project::name() const { return m_name; } int Project::bitsPerChannel() const { return m_bitsPerChannel; } int Project::audioSampleRate() const { return m_audioSampleRate; } ProjectItem& Project::rootItem() { return m_rootItem; } void Project::setName(const std::string &name) { m_name = name; } void Project::setBitsPerChannel(int bitsPerChannel) { m_bitsPerChannel = bitsPerChannel; } void Project::setAudioSampleRate(int audioSampleRate) { m_audioSampleRate = audioSampleRate; } void Project::load() { pugi::xml_document doc; if (!doc.load_file(m_path.c_str())) { // TODO: proper error handlign throw 0; } pugi::xml_node root = doc.document_element(); // Get name pugi::xml_attribute attr; if ((attr = root.attribute("name"))) m_name = attr.as_string(); // Get other properties if ((attr = root.attribute("bitsPerChannel"))) m_bitsPerChannel = attr.as_int(); if ((attr = root.attribute("audioSampleRate"))) m_audioSampleRate = attr.as_int(); } void Project::save() { pugi::xml_document doc; doc.append_child(pugi::node_declaration); auto proj = doc.append_child("project"); proj.append_attribute("name").set_value(m_name.c_str()); proj.append_attribute("bitsPerChannel").set_value(m_bitsPerChannel); proj.append_attribute("audioSampleRate").set_value(m_audioSampleRate); doc.save_file(m_path.string().c_str()); } }