|
From: Tapio V. <aa...@us...> - 2011-01-13 17:11:10
|
Module: editor
Branch: master
Commit: 7f2131c7c08b2a8f8eba0aa902fa53512985379e
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 13 19:10:09 2011 +0200
XML exporter now writes header info (testing QtXml).
---
songwriter-ini.cc | 8 +++++---
songwriter-txt.cc | 3 ++-
songwriter-xml .cc | 38 +++++++++++++++++++++++++++++++++-----
songwriter.hh | 4 ++--
4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/songwriter-ini.cc b/songwriter-ini.cc
index b9b1cf1..1ed0021 100644
--- a/songwriter-ini.cc
+++ b/songwriter-ini.cc
@@ -4,7 +4,7 @@
void FoFMIDIWriter::writeMIDI() {
throw std::runtime_error("MIDI export is not implemented.");
- std::ofstream f((path + "notes.mid").c_str(), std::ios::binary);
+ /*std::ofstream f((path + "notes.mid").c_str(), std::ios::binary);
// FIXME: The following is just an example and doesn't actually output MID format
char buf[1024] = {};
Notes const& notes = s.getVocalTrack().notes;
@@ -15,15 +15,17 @@ void FoFMIDIWriter::writeMIDI() {
buf[1] = n.note; // MIDI note value
// Others are n.begin, n.end, n.type etc. (see notes.hh)
f.write(buf, 1024);
- }
+ }*/
}
void FoFMIDIWriter::writeINI() {
- std::ofstream f((path + "song.ini").c_str(), std::ios::binary);
+ /*
+ std::ofstream f((path.toStdString() + "song.ini").c_str(), std::ios::binary);
f << "[song]\n";
f << "name = " << s.title << std::endl;
f << "artist = " << s.artist << std::endl;
f << "genre = " << s.genre << std::endl;
f << "year = " << s.year << std::endl;
+ */
}
diff --git a/songwriter-txt.cc b/songwriter-txt.cc
index ffa6e7e..3e2455b 100644
--- a/songwriter-txt.cc
+++ b/songwriter-txt.cc
@@ -4,6 +4,7 @@
void UltraStarTXTWriter::writeTXT() {
throw std::runtime_error("TXT export is not implemented.");
+/*
std::ofstream f((path + "notes.txt").c_str(), std::ios::binary);
// FIXME: The following is just an example and doesn't actually output TXT format
char buf[1024] = {};
@@ -15,5 +16,5 @@ void UltraStarTXTWriter::writeTXT() {
buf[1] = n.note; // MIDI note value
// Others are n.begin, n.end, n.type etc. (see notes.hh)
f.write(buf, 1024);
- }
+ }*/
}
diff --git a/songwriter-xml .cc b/songwriter-xml .cc
index 71d2581..e5137c4 100644
--- a/songwriter-xml .cc
+++ b/songwriter-xml .cc
@@ -1,12 +1,39 @@
#include "songwriter.hh"
-#include <fstream>
+#include <QtXml/QDomDocument>
+#include <QTextStream>
#include <iostream>
void SingStarXMLWriter::writeXML() {
- throw std::runtime_error("XML export is not implemented.");
- // FIXME: Use QtXML
- std::ofstream f((path + "notes.xml").c_str(), std::ios::binary);
+ QDomDocument doc("");
+ QDomElement root = doc.createElement("MELODY");
+ root.setAttribute("xmlns", "http://www.singstargame.com");
+ root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ root.setAttribute("Version", "1");
+ root.setAttribute("Tempo", "120"); // FIXME!
+ root.setAttribute("FixedTempo", "Yes");
+ root.setAttribute("Resolution", "Demisemiquaver"); //?
+ root.setAttribute("Genre", QString::fromStdString(s.genre));
+ root.setAttribute("Year", QString::fromStdString(s.year));
+ root.setAttribute("xsi:schemaLocation", "http://www.singstargame.com http://15GMS-SINGSQL/xml_schema/melody.xsd");
+ root.setAttribute("m2xVersion", "060110"); //?
+ root.setAttribute("audioVersion", "2"); //?
+ doc.appendChild(root);
+
+ QDomComment artistComment = doc.createComment(QString("Artist: ") + QString::fromStdString(s.artist));
+ QDomComment titleComment = doc.createComment(QString("Title: ") + QString::fromStdString(s.title));
+ root.appendChild(artistComment);
+ root.appendChild(titleComment);
+
+ QString xml = doc.toString(4);
+
+ QFile f(path + "/notes.xml");
+ if (f.open(QFile::WriteOnly)) {
+ QTextStream out(&f);
+ out << xml;
+ } else throw std::runtime_error("Couldn't open target file notes.xml");
+
// FIXME: The following is just an example and doesn't actually output XML format
+ /*
char buf[1024] = {};
Notes const& notes = s.getVocalTrack().notes;
std::cout << notes.size() << std::endl;
@@ -16,5 +43,6 @@ void SingStarXMLWriter::writeXML() {
buf[1] = n.note; // MIDI note value
// Others are n.begin, n.end, n.type etc. (see notes.hh)
f.write(buf, 1024);
- }
+ }*/
+
}
diff --git a/songwriter.hh b/songwriter.hh
index 3d06e60..6e9ec1d 100644
--- a/songwriter.hh
+++ b/songwriter.hh
@@ -5,9 +5,9 @@
struct SongWriter
{
SongWriter(const Song& s_, const QString& path_)
- : s(s_), path(path_.toStdString()) { QDir dir; dir.mkpath(path_); }
+ : s(s_), path(path_) { QDir dir; dir.mkpath(path_); }
const Song& s;
- std::string path;
+ QString path;
};
struct SingStarXMLWriter: public SongWriter
|