<commit_before>//============================================================================
/**
 Implementation file for KeyFileMuDesc.h
 
 @author		<NAME>
 @date			20130416
 */
//============================================================================

// Guard against multiple template implementation inclusions
#ifndef KeyFileMuDesc_cpp
#define KeyFileMuDesc_cpp

// Includes
#include "KeyFileMuDesc.h"
#include "tinyxml2/tinyxml2.h"

using std::string;
using tinyxml2::XMLDocument;
using tinyxml2::XMLElement;
using tinyxml2::XMLConstHandle;

template <typename T>
KeyFileMuDesc<T>::KeyFileMuDesc(const bool inPitchSpelled)
: KeyFile(inPitchSpelled)
{
}

template <typename T>
KeyFileMuDesc<T>::KeyFileMuDesc(std::string inFileName, const bool inPitchSpelled)
: KeyFile(inPitchSpelled)
{
	open(inFileName);
}

template <typename T>
KeyFileMuDesc<T>::~KeyFileMuDesc()
{
	close();
}

template <typename T>
void KeyFileMuDesc<T>::open(const std::string& inFileName)
{
	m_TimedKeys.clear();
	m_FileHasChanged = false;
	m_FileName = inFileName;
	tinyxml2::XMLDocument theXMLFile;
	theXMLFile.LoadFile(inFileName.c_str());
	XMLElement* theXMLRoot = theXMLFile.RootElement();
    
	if (theXMLRoot)
	{
		XMLConstHandle theSegmentHandle(theXMLRoot->FirstChildElement("segment"));
		while (theSegmentHandle.ToElement())
		{
			TimedLabel<T> theCurTimedKey;
			theSegmentHandle.ToElement()->QueryDoubleAttribute("time", &theCurTimedKey.onset());
			theSegmentHandle.ToElement()->QueryDoubleAttribute("length", &theCurTimedKey.offset());
			theCurTimedKey.offset() += theCurTimedKey.onset();
			string theLabelString = theSegmentHandle.FirstChildElement("keytype").ToElement()->Attribute("value");
			theCurTimedKey.label() = T(theLabelString);
			m_TimedKeys.push_back(theCurTimedKey);
			theSegmentHandle = theSegmentHandle.NextSiblingElement();
		}
	}
    KeyFile::open(inFileName);
}

template <typename T>
void KeyFileMuDesc<T>::close()
{
	if (m_FileHasChanged)
	{
		KeyFile::close();
		//TODO: implement writing TimedMDKeySequence to MusicDescription XML file
		XMLDocument theXMLFile;
		theXMLFile.NewDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		XMLElement* theXMLRoot = theXMLFile.NewElement("musicdescription");
		theXMLRoot->SetAttribute("xmlns", "http://www.quaero.org/Music_6/1.0");
		theXMLRoot->SetAttribute("xmlns:ns1", "http://www.w3.org/2001/XMLSchema-instance");
		theXMLRoot->SetAttribute("format", "20090701A");
		theXMLRoot->SetAttribute("ns1:schemaLocation", "http://www.quaero.org/Music_6/1.0 http://recherche.ircam.fr/anasyn/quaero/quaero_ctc_6_music.xsd");
		for (KeySequence::const_iterator theKeyIt = m_TimedKeys.begin(); theKeyIt != m_TimedKeys.end(); ++theKeyIt)
		{
			XMLElement* theCurSegment = theXMLFile.NewElement("segment");
			theXMLRoot->InsertEndChild(theCurSegment);
			theCurSegment->SetAttribute("time", theKeyIt->onset());
			theCurSegment->SetAttribute("length", theKeyIt->offset() - theKeyIt->onset());
			theCurSegment->SetAttribute("sourcetrack", 0);
			XMLElement* theCurKeyType = theXMLFile.NewElement("keytype");
			theCurSegment->InsertEndChild(theCurKeyType);
			theCurKeyType->SetAttribute("value", T(theKeyIt->label()).str().c_str());
			theCurKeyType->SetAttribute("id", 1);
		}
		theXMLFile.SaveFile(m_FileName.c_str());
	}
}

#endif  // #ifndef KeyFileMuDesc_cpp
<commit_msg>Bugfix<commit_after>//============================================================================
/**
 Implementation file for KeyFileMuDesc.h
 
 @author		<NAME>
 @date			20130416
 */
//============================================================================

// Guard against multiple template implementation inclusions
#ifndef KeyFileMuDesc_cpp
#define KeyFileMuDesc_cpp

// Includes
#include "KeyFileMuDesc.h"
#include "tinyxml2/tinyxml2.h"

using std::string;
using tinyxml2::XMLDocument;
using tinyxml2::XMLElement;
using tinyxml2::XMLConstHandle;

template <typename T>
KeyFileMuDesc<T>::KeyFileMuDesc(const bool inPitchSpelled)
: KeyFile(inPitchSpelled)
{
}

template <typename T>
KeyFileMuDesc<T>::KeyFileMuDesc(std::string inFileName, const bool inPitchSpelled)
: KeyFile(inPitchSpelled)
{
	open(inFileName);
}

template <typename T>
KeyFileMuDesc<T>::~KeyFileMuDesc()
{
	close();
}

template <typename T>
void KeyFileMuDesc<T>::open(const std::string& inFileName)
{
	m_TimedKeys.clear();
	m_FileHasChanged = false;
	m_FileName = inFileName;
	tinyxml2::XMLDocument theXMLFile;
	theXMLFile.LoadFile(inFileName.c_str());
	XMLElement* theXMLRoot = theXMLFile.RootElement();
    
	if (theXMLRoot)
	{
		XMLConstHandle theSegmentHandle(theXMLRoot->FirstChildElement("segment"));
		while (theSegmentHandle.ToElement())
		{
			TimedLabel<T> theCurTimedKey;
			theSegmentHandle.ToElement()->QueryDoubleAttribute("time", &theCurTimedKey.onset());
			theSegmentHandle.ToElement()->QueryDoubleAttribute("length", &theCurTimedKey.offset());
			theCurTimedKey.offset() += theCurTimedKey.onset();
			string theLabelString = theSegmentHandle.FirstChildElement("keytype").ToElement()->Attribute("value");
			theCurTimedKey.label() = T(theLabelString);
			m_TimedKeys.push_back(theCurTimedKey);
			theSegmentHandle = theSegmentHandle.NextSiblingElement();
		}
	}
    KeyFile::open(inFileName);
}

template <typename T>
void KeyFileMuDesc<T>::close()
{
	if (m_FileHasChanged)
	{
		//TODO: implement writing TimedMDKeySequence to MusicDescription XML file
		XMLDocument theXMLFile;
		theXMLFile.NewDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		XMLElement* theXMLRoot = theXMLFile.NewElement("musicdescription");
		theXMLRoot->SetAttribute("xmlns", "http://www.quaero.org/Music_6/1.0");
		theXMLRoot->SetAttribute("xmlns:ns1", "http://www.w3.org/2001/XMLSchema-instance");
		theXMLRoot->SetAttribute("format", "20090701A");
		theXMLRoot->SetAttribute("ns1:schemaLocation", "http://www.quaero.org/Music_6/1.0 http://recherche.ircam.fr/anasyn/quaero/quaero_ctc_6_music.xsd");
		for (KeySequence::const_iterator theKeyIt = m_TimedKeys.begin(); theKeyIt != m_TimedKeys.end(); ++theKeyIt)
		{
			XMLElement* theCurSegment = theXMLFile.NewElement("segment");
			theXMLRoot->InsertEndChild(theCurSegment);
			theCurSegment->SetAttribute("time", theKeyIt->onset());
			theCurSegment->SetAttribute("length", theKeyIt->offset() - theKeyIt->onset());
			theCurSegment->SetAttribute("sourcetrack", 0);
			XMLElement* theCurKeyType = theXMLFile.NewElement("keytype");
			theCurSegment->InsertEndChild(theCurKeyType);
			theCurKeyType->SetAttribute("value", T(theKeyIt->label()).str().c_str());
			theCurKeyType->SetAttribute("id", 1);
		}
		theXMLFile.SaveFile(m_FileName.c_str());
	}
}

#endif  // #ifndef KeyFileMuDesc_cpp

{'fraction_non_alphanumeric': 0.18734063296835157, 'fraction_numerical': 0.012299385030748462, 'mean_word_length': 6.900473933649289, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 2, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '329702', 'n_tokens_mistral': 2347, 'n_tokens_neox': 2170, 'n_words': 315}