|
From: Tapio V. <aa...@us...> - 2011-01-12 19:58:19
|
Module: editor
Branch: master
Commit: 223adc8ab367bd7b4c14cb4c7f70a5b21d590555
Author: Tapio Vierros <tap...@gm...>
Date: Wed Jan 12 21:57:45 2011 +0200
Load notes from UltraStar TXT. Kind of. Partially.
* Breaks UI handling of note types
* No pitch info
* Phony seconds-to-pixels mapping
---
editorapp.cc | 23 +++++++++++++++++------
editorapp.hh | 2 ++
notegraphwidget.cc | 5 ++++-
notelabel.hh | 2 +-
notes.cc | 3 ++-
notes.hh | 3 ++-
songparser.cc | 32 ++++++++++++++++++--------------
7 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 68b61b7..193b207 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -1,5 +1,5 @@
#include <QtGui>
-#include <cstdlib>
+#include <iostream>
#include "editorapp.hh"
#include "notelabel.hh"
#include "notegraphwidget.hh"
@@ -50,7 +50,7 @@ void EditorApp::updateNoteInfo(NoteLabel *note)
ui.valNoteDuration->setText(QString::number(note->width()));
ui.valNote->setText(QString::number(note->y() / NoteGraphWidget::noteYStep));
ui.cmbNoteType->setEnabled(true);
- ui.cmbNoteType->setCurrentIndex(note->note().type);
+ // FIXME: ui.cmbNoteType->setCurrentIndex(note->note().type);
ui.chkFloating->setEnabled(true);
ui.chkFloating->setChecked(note->isFloating());
} else {
@@ -95,7 +95,17 @@ void EditorApp::on_actionOpen_triggered()
);
if (!fileName.isNull()) {
- // TODO: Spawn a parser
+ QFileInfo finfo(fileName);
+ try {
+ song.reset(new Song(QString(finfo.path()+"/").toStdString(), finfo.fileName().toStdString()));
+ VocalTrack vt = song->getVocalTrack();
+ noteGraph->setLyrics(song->getVocalTrack().notes);
+ } catch (const std::exception& e) {
+ // TODO: Error handling
+ std::cerr << "Error loading song: " << finfo.filePath().toStdString() << std::endl;
+ std::cerr << " --> " << e.what() << std::endl;
+ }
+
}
}
@@ -142,7 +152,7 @@ void EditorApp::on_actionMusicFile_triggered()
if (!fileName.isNull()) {
ui.valMusicFile->setText(fileName);
ui.tabWidget->setCurrentIndex(1);
- // TODO: Do something the file
+ // TODO: Do something with the file
}
}
@@ -202,8 +212,9 @@ void EditorApp::on_actionAbout_triggered()
void EditorApp::on_cmbNoteType_currentIndexChanged(int index)
{
- if (noteGraph->selectedNote())
- noteGraph->selectedNote()->setType(index);
+ // FIXME: Fix this
+ //if (noteGraph->selectedNote())
+ // noteGraph->selectedNote()->setType(index);
}
void EditorApp::on_chkFloating_stateChanged(int state)
diff --git a/editorapp.hh b/editorapp.hh
index 0595dd6..d622616 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -2,6 +2,7 @@
#include "ui_editor.h"
#include "operation.hh"
+#include "song.hh"
class NoteLabel;
class NoteGraphWidget;
@@ -44,4 +45,5 @@ private:
Ui::EditorApp ui;
NoteGraphWidget* noteGraph;
OperationStack opStack;
+ QScopedPointer<Song> song;
};
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 5747ef2..42ae63f 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -91,7 +91,10 @@ void NoteGraphWidget::setLyrics(const Notes ¬es)
{
clear();
for (Notes::const_iterator it = notes.begin(); it != notes.end(); ++it) {
- m_notes.push_back(new NoteLabel(*it, this, QPoint(0, 2 * noteYStep)));
+ // TODO: Implement proper seconds-to-pixels mapping and note height thingy
+ const float sec2pix = 100;
+ m_notes.push_back(new NoteLabel(*it, this, QPoint(it->begin*sec2pix, 2 * noteYStep),
+ QSize((it->end - it->begin)*sec2pix, 0), false));
}
finalizeNewLyrics();
diff --git a/notelabel.hh b/notelabel.hh
index b36e0d0..b02bdbe 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -29,7 +29,7 @@ public:
bool isFloating() const { return m_floating; }
void setFloating(bool state) { m_floating = state; createPixmap(size()); }
- void setType(int newtype) { m_note.type = Note::Type(newtype); createPixmap(size()); }
+ void setType(Note::Type newtype) { m_note.type = Note::Type(newtype); createPixmap(size()); }
void startResizing(int dir);
void startDragging(const QPoint& point);
diff --git a/notes.cc b/notes.cc
index d846de2..ba98255 100644
--- a/notes.cc
+++ b/notes.cc
@@ -60,7 +60,8 @@ double Note::diff(double note, double n) { return remainder(n - note, 12.0); }
std::string Note::typeString() const {
static const std::string typenames[] = { "Normal", "Bonus", "Freestyle" };
- return typenames[type];
+ return typenames[0]; // FIXME: Handle notetypes properly
+ //return typenames[type];
}
diff --git a/notes.hh b/notes.hh
index abf5d77..601808f 100644
--- a/notes.hh
+++ b/notes.hh
@@ -53,7 +53,8 @@ struct Note {
double end;
double phase; ///< position within a measure, [0, 1)
/// note type
- enum Type { NORMAL = 0, GOLDEN = 1, FREESTYLE = 2, SLEEP } type;
+ enum Type { FREESTYLE = 'F', NORMAL = ':', GOLDEN = '*', SLIDE = '+', SLEEP = '-',
+ TAP = '1', HOLDBEGIN = '2', HOLDEND = '3', ROLL = '4', MINE = 'M', LIFT = 'L'} type;
int note; ///< MIDI pitch of the note (at the end for slide notes)
int notePrev; ///< MIDI pitch of the previous note (should be same as note for everything but SLIDE)
std::string syllable; ///< lyrics syllable for that note
diff --git a/songparser.cc b/songparser.cc
index 930c00a..b52724a 100644
--- a/songparser.cc
+++ b/songparser.cc
@@ -65,20 +65,7 @@ SongParser::SongParser(Song& s):
m_ss.write(&data[0], size);
}
// FIXME: convertToUTF8(m_ss, s.path + s.filename);
- // Header already parsed?
- if (s.loadStatus == Song::HEADER) {
- try {
- if (type == TXT) txtParse();
- else if (type == INI) iniParse();
- else if (type == SM) smParse();
- } catch (std::runtime_error& e) {
- throw SongParserException(e.what(), m_linenum);
- }
- finalize(); // Do some adjusting to the notes
- s.loadStatus = Song::FULL;
- return;
- }
- // Parse only header to speed up loading and conserve memory
+ // Header parsing
try {
if (type == TXT) txtParseHeader();
else if (type == INI) iniParseHeader();
@@ -112,6 +99,23 @@ SongParser::SongParser(Song& s):
}
}
s.loadStatus = Song::HEADER;
+
+ // Note: The full parser invocation below should actually be above header parsing
+ // if two-phase parsing is wanted
+
+ // Header already parsed?
+ if (s.loadStatus == Song::HEADER) {
+ try {
+ if (type == TXT) txtParse();
+ else if (type == INI) iniParse();
+ else if (type == SM) smParse();
+ } catch (std::runtime_error& e) {
+ throw SongParserException(e.what(), m_linenum);
+ }
+ finalize(); // Do some adjusting to the notes
+ s.loadStatus = Song::FULL;
+ return; // FIXME: Header-only parsing is disabled
+ }
}
|