summaryrefslogtreecommitdiffstats
path: root/src/gui/dialogs/LyricEditDialog.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
commit145364a8af6a1fec06556221e66d4b724a62fc9a (patch)
tree53bd71a544008c518034f208d64c932dc2883f50 /src/gui/dialogs/LyricEditDialog.cpp
downloadrosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz
rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/dialogs/LyricEditDialog.cpp')
-rw-r--r--src/gui/dialogs/LyricEditDialog.cpp253
1 files changed, 253 insertions, 0 deletions
diff --git a/src/gui/dialogs/LyricEditDialog.cpp b/src/gui/dialogs/LyricEditDialog.cpp
new file mode 100644
index 0000000..4dfeba2
--- /dev/null
+++ b/src/gui/dialogs/LyricEditDialog.cpp
@@ -0,0 +1,253 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
+
+/*
+ Rosegarden
+ A MIDI and audio sequencer and musical notation editor.
+
+ This program is Copyright 2000-2008
+ Guillaume Laurent <glaurent@telegraph-road.org>,
+ Chris Cannam <cannam@all-day-breakfast.com>,
+ Richard Bown <richard.bown@ferventsoftware.com>
+
+ The moral rights of Guillaume Laurent, Chris Cannam, and Richard
+ Bown to claim authorship of this work have been asserted.
+
+ Other copyrights also apply to some parts of this work. Please
+ see the AUTHORS file and individual file headers for details.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version. See the file
+ COPYING included with this distribution for more information.
+*/
+
+
+#include "LyricEditDialog.h"
+
+#include "base/Event.h"
+#include "base/BaseProperties.h"
+#include <klocale.h>
+#include "misc/Strings.h"
+#include "misc/Debug.h"
+#include "base/Composition.h"
+#include "base/NotationTypes.h"
+#include "base/Segment.h"
+#include <kdialogbase.h>
+#include <qgroupbox.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qtextedit.h>
+#include <qvbox.h>
+#include <qwidget.h>
+#include <kcombobox.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+
+
+namespace Rosegarden
+{
+
+LyricEditDialog::LyricEditDialog(QWidget *parent,
+ Segment *segment) :
+ KDialogBase(parent, 0, true, i18n("Edit Lyrics"), Ok | Cancel | Help),
+ m_segment(segment),
+ m_verseCount(0)
+{
+ setHelp("nv-text-lyrics");
+
+ QVBox *vbox = makeVBoxMainWidget();
+
+ QGroupBox *groupBox = new QGroupBox
+ (1, Horizontal, i18n("Lyrics for this segment"), vbox);
+
+ QHBox *hbox = new QHBox(groupBox);
+ hbox->setSpacing(5);
+// new QLabel(i18n("Verse:"), hbox);
+ m_verseNumber = new KComboBox(hbox);
+ m_verseNumber->setEditable(false);
+ connect(m_verseNumber, SIGNAL(activated(int)), this, SLOT(slotVerseNumberChanged(int)));
+ m_verseAddButton = new QPushButton(i18n("Add Verse"), hbox);
+ connect(m_verseAddButton, SIGNAL(clicked()), this, SLOT(slotAddVerse()));
+ QFrame *f = new QFrame(hbox);
+ hbox->setStretchFactor(f, 10);
+
+ m_textEdit = new QTextEdit(groupBox);
+ m_textEdit->setTextFormat(Qt::PlainText);
+
+ m_textEdit->setMinimumWidth(300);
+ m_textEdit->setMinimumHeight(200);
+
+ unparse();
+
+ for (int i = 0; i < m_verseCount; ++i) {
+ m_verseNumber->insertItem(i18n("Verse %1").arg(i + 1));
+ }
+ m_currentVerse = 0;
+ if (m_verseCount == 12) m_verseAddButton->setEnabled(false);
+}
+
+void
+LyricEditDialog::slotVerseNumberChanged(int verse)
+{
+ NOTATION_DEBUG << "LyricEditDialog::slotVerseNumberChanged(" << verse << ")" << endl;
+ QString text = m_textEdit->text();
+ m_texts[m_currentVerse] = text;
+ m_textEdit->setText(m_texts[verse]);
+ m_currentVerse = verse;
+}
+
+void
+LyricEditDialog::slotAddVerse()
+{
+ NOTATION_DEBUG << "LyricEditDialog::slotAddVerse" << endl;
+ m_verseCount++;
+ m_texts.push_back(m_skeleton);
+ m_verseNumber->insertItem(i18n("Verse %1").arg(m_verseCount));
+ m_verseNumber->setCurrentItem(m_verseCount - 1);
+ slotVerseNumberChanged(m_verseCount - 1);
+ if (m_verseCount == 12) m_verseAddButton->setEnabled(false);
+}
+
+void
+LyricEditDialog::countVerses()
+{
+ m_verseCount = 1;
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ if ((*i)->isa(Text::EventType)) {
+
+ std::string textType;
+ if ((*i)->get<String>(Text::TextTypePropertyName, textType) &&
+ textType == Text::Lyric) {
+
+ long verse = 0;
+ (*i)->get<Int>(Text::LyricVersePropertyName, verse);
+
+ if (verse >= m_verseCount) m_verseCount = verse + 1;
+ }
+ }
+ }
+}
+
+void
+LyricEditDialog::unparse()
+{
+ // This and SetLyricsCommand::execute() are opposites that will
+ // need to be kept in sync with any changes in one another. (They
+ // should really both be in a common lyric management class.)
+
+ countVerses();
+
+ Composition *comp = m_segment->getComposition();
+
+ bool firstNote = true;
+ timeT lastTime = m_segment->getStartTime();
+ int lastBarNo = comp->getBarNumber(lastTime);
+ std::map<int, bool> haveLyric;
+
+ QString fragment = QString("[%1] ").arg(lastBarNo + 1);
+
+ m_skeleton = fragment;
+ m_texts.clear();
+ for (size_t v = 0; v < m_verseCount; ++v) {
+ m_texts.push_back(fragment);
+ haveLyric[v] = false;
+ }
+
+ for (Segment::iterator i = m_segment->begin();
+ m_segment->isBeforeEndMarker(i); ++i) {
+
+ bool isNote = (*i)->isa(Note::EventType);
+ bool isLyric = false;
+
+ if (!isNote) {
+ if ((*i)->isa(Text::EventType)) {
+ std::string textType;
+ if ((*i)->get<String>(Text::TextTypePropertyName, textType) &&
+ textType == Text::Lyric) {
+ isLyric = true;
+ }
+ }
+ } else {
+ if ((*i)->has(BaseProperties::TIED_BACKWARD) &&
+ (*i)->get<Bool>(BaseProperties::TIED_BACKWARD)) {
+ continue;
+ }
+ }
+
+ if (!isNote && !isLyric) continue;
+
+ timeT myTime = (*i)->getNotationAbsoluteTime();
+ int myBarNo = comp->getBarNumber(myTime);
+
+ if (myBarNo > lastBarNo) {
+
+ fragment = "";
+
+ while (myBarNo > lastBarNo) {
+ fragment += " /";
+ ++lastBarNo;
+ }
+
+ fragment += QString("\n[%1] ").arg(myBarNo + 1);
+
+ m_skeleton += fragment;
+ for (size_t v = 0; v < m_verseCount; ++v) m_texts[v] += fragment;
+ }
+
+ if (isNote) {
+ if ((myTime > lastTime) || firstNote) {
+ m_skeleton += " .";
+ for (size_t v = 0; v < m_verseCount; ++v) {
+ if (!haveLyric[v]) m_texts[v] += " .";
+ haveLyric[v] = false;
+ }
+ lastTime = myTime;
+ firstNote = false;
+ }
+ }
+
+ if (isLyric) {
+
+ std::string ssyllable;
+ (*i)->get<String>(Text::TextPropertyName, ssyllable);
+
+ long verse = 0;
+ (*i)->get<Int>(Text::LyricVersePropertyName, verse);
+
+ QString syllable(strtoqstr(ssyllable));
+ syllable.replace(QRegExp("\\s+"), "~");
+
+ m_texts[verse] += " " + syllable;
+ haveLyric[verse] = true;
+ }
+ }
+
+ if (!m_texts.empty()) {
+ m_textEdit->setText(m_texts[0]);
+ } else {
+ m_texts.push_back(m_skeleton);
+ }
+}
+
+int
+LyricEditDialog::getVerseCount() const
+{
+ return m_verseCount;
+}
+
+QString
+LyricEditDialog::getLyricData(int verse) const
+{
+ if (verse == m_verseNumber->currentItem()) {
+ return m_textEdit->text();
+ } else {
+ return m_texts[verse];
+ }
+}
+
+}
+#include "LyricEditDialog.moc"