|
From: Lasse Kärkkäi. <tr...@us...> - 2010-08-01 16:37:32
|
Module: performous
Branch: songwriter
Commit: 7edccbfa1805a9fa686ee01432af6144bb447dba
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Aug 1 17:30:07 2010 +0300
Added songwriter template for psymin
---
game/screen_sing.cc | 2 ++
game/songwriter.cc | 32 ++++++++++++++++++++++++++++++++
game/songwriter.hh | 5 +++++
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index dd822f3..cc526ef 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -11,6 +11,7 @@
#include "guitargraph.hh"
#include "glutil.hh"
#include "i18n.hh"
+#include "songwriter.hh"
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
@@ -263,6 +264,7 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_F4) dispInFlash(++config["audio/round-trip"]);
if (key == SDLK_F5) dispInFlash(--config["audio/controller_delay"]);
if (key == SDLK_F6) dispInFlash(++config["audio/controller_delay"]);
+ if (key == SDLK_z) writeToFile(*m_song, boost::filesystem::path(m_song->path) / "songwriter-test");
bool seekback = false;
if (m_song->danceTracks.empty()) { // Seeking backwards is currently not permitted for dance songs
diff --git a/game/songwriter.cc b/game/songwriter.cc
new file mode 100644
index 0000000..10e11db
--- /dev/null
+++ b/game/songwriter.cc
@@ -0,0 +1,32 @@
+#include "songwriter.hh"
+#include <fstream>
+#include <iostream>
+
+void writeMid(Song const& s, boost::filesystem::path const& filename) {
+ std::ofstream f(filename.string().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.vocals.notes;
+ std::cout << notes.size() << std::endl;
+ for (unsigned int i = 0; i < notes.size(); ++i) {
+ Note const& n = notes[i];
+ buf[0] = 0xFF;
+ buf[1] = n.note; // MIDI note value
+ // Others are n.begin, n.end, n.type etc. (see notes.hh)
+ f.write(buf, 1024);
+ }
+}
+
+void writeIni(Song const& s, boost::filesystem::path const& filename) {
+ std::ofstream f(filename.string().c_str(), std::ios::binary);
+ f << "[song]\n";
+ f << "title=" << s.title << '\n';
+ // ...
+}
+
+void writeToFile(Song const& s, boost::filesystem::path const& path) {
+ create_directory(path);
+ writeIni(s, path / "song.ini");
+ writeMid(s, path / "notes.mid");
+}
+
diff --git a/game/songwriter.hh b/game/songwriter.hh
new file mode 100644
index 0000000..75eb171
--- /dev/null
+++ b/game/songwriter.hh
@@ -0,0 +1,5 @@
+#include "song.hh"
+#include <boost/filesystem.hpp>
+
+void writeToFile(Song const& s, boost::filesystem::path const& path);
+
|