|
From: Tapio V. <aa...@us...> - 2011-01-25 07:34:17
|
Module: editor
Branch: master
Commit: d79b2063a627f354d3b7d278fbee98d3617e1493
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 25 09:32:14 2011 +0200
Initial "timing during playback" implementation.
Weight on the word initial.
---
editor.ui | 57 ++++++++++++++++++++++++++++++++++++++++++++++-
editorapp.cc | 2 +
notegraphwidget.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++---
notegraphwidget.hh | 8 ++++++
4 files changed, 123 insertions(+), 6 deletions(-)
diff --git a/editor.ui b/editor.ui
index b579695..123ea52 100644
--- a/editor.ui
+++ b/editor.ui
@@ -321,16 +321,43 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>Playback</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Timing</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
<widget class="QPushButton" name="cmdPlay">
<property name="toolTip">
- <string>Start playing the music file.</string>
+ <string>Play/pause the music file.</string>
</property>
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
- <item row="0" column="1">
+ <item row="1" column="1">
+ <widget class="QPushButton" name="cmdTimeSyllable">
+ <property name="toolTip">
+ <string>Set selected note start to cursor position.</string>
+ </property>
+ <property name="text">
+ <string>Time syllable (N)</string>
+ </property>
+ <property name="shortcut">
+ <string>N</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
<widget class="QPushButton" name="cmdStop">
<property name="toolTip">
<string>Stop the music.</string>
@@ -340,6 +367,32 @@
</property>
</widget>
</item>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="cmdTimeSentence">
+ <property name="toolTip">
+ <string>Set selected note start to cursor position and move to next sentence start.</string>
+ </property>
+ <property name="text">
+ <string>Time sentence (M)</string>
+ </property>
+ <property name="shortcut">
+ <string>M</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</widget>
</widget>
diff --git a/editorapp.cc b/editorapp.cc
index 0489304..856a1ad 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -36,6 +36,8 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent), projectFileName(), h
// Custom signals/slots
connect(noteGraph, SIGNAL(operationDone(const Operation&)), this, SLOT(operationDone(const Operation&)));
connect(noteGraph, SIGNAL(updateNoteInfo(NoteLabel*)), this, SLOT(updateNoteInfo(NoteLabel*)));
+ connect(ui.cmdTimeSyllable, SIGNAL(pressed()), noteGraph, SLOT(timeSyllable()));
+ connect(ui.cmdTimeSentence, SIGNAL(pressed()), noteGraph, SLOT(timeSentence()));
// Duplicate/reused signals/slots
connect(ui.cmdMusicFile, SIGNAL(clicked()), this, SLOT(on_actionMusicFile_triggered()));
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index d3e4a4c..689d772 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -213,6 +213,58 @@ void NoteGraphWidget::seek(int x)
emit seeked(1000 * px2s(x));
}
+void NoteGraphWidget::timeCurrent()
+{
+ if (m_selectedNote) {
+ // TODO: Automatic pitch detection
+ Operation op("MOVE");
+ op << getNoteLabelId(m_selectedNote)
+ << m_seekHandle.curx() << m_selectedNote->y();
+ doOperation(op);
+ }
+}
+
+void NoteGraphWidget::timeSyllable()
+{
+ timeCurrent();
+ selectNextSyllableAfterSeekHandle();
+}
+
+void NoteGraphWidget::timeSentence()
+{
+ timeCurrent();
+ selectNextSentenceStart();
+}
+
+void NoteGraphWidget::selectNextSyllableAfterSeekHandle()
+{
+ bool currentFound = (m_selectedNote ? false : true);
+ if (m_notes.size() > 1 && m_selectedNote != m_notes.back()) {
+ for (NoteLabels::iterator it = m_notes.begin(); it != m_notes.end(); ++it) {
+ if (m_selectedNote == *it) currentFound = true;
+ else if (currentFound && (*it)->x() > m_seekHandle.curx()) {
+ selectNote(*it); break;
+ }
+ }
+ }
+}
+
+void NoteGraphWidget::selectNextSentenceStart()
+{
+ bool currentFound = (m_selectedNote ? false : true);
+ NoteLabel *prev = NULL;
+ if (m_notes.size() > 1 && m_selectedNote != m_notes.back()) {
+ for (NoteLabels::iterator it = m_notes.begin(); it != m_notes.end(); prev = *it, ++it) {
+ if (m_selectedNote == *it) currentFound = true;
+ else if (currentFound && (*it)->x() > m_seekHandle.curx()
+ && prev && prev->note().lineBreak) {
+ selectNote(*it); break;
+ }
+ }
+ }
+}
+
+
void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
{
NoteLabel *child = qobject_cast<NoteLabel*>(childAt(event->pos()));
@@ -313,6 +365,7 @@ void NoteGraphWidget::mouseDoubleClickEvent(QMouseEvent *event)
if (!child) {
// Double click empty space = seek there
seek(event->x());
+ selectNextSyllableAfterSeekHandle();
return;
}
@@ -342,8 +395,8 @@ void NoteGraphWidget::mouseMoveEvent(QMouseEvent *event)
m_actionHappened = true; // We have movement, so resize/move can be accepted
// See if the note needs to be unfloated
if (m_selectedAction != NONE && m_selectedNote && m_selectedNote->isFloating()) {
- Operation op("FLOATING"); op << getNoteLabelId(m_selectedNote) << false;
- doOperation(op);
+ // Undo op is handled later by the SETGEOM constructed at drop
+ m_selectedNote->setFloating(false);
}
}
@@ -442,14 +495,15 @@ void NoteGraphWidget::doOperation(const Operation& op, Operation::OperationFlags
if (action == "DEL") {
n->close();
m_notes.removeAt(op.i(1));
- } else if (action == "SPLIT") {
- // TODO
} else if (action == "SETGEOM") {
n->setGeometry(op.i(2), op.i(3), op.i(4), op.i(5));
+ n->setFloating(false);
} else if (action == "RESIZE") {
n->resize(op.i(2), op.i(3));
+ n->setFloating(false);
} else if (action == "MOVE") {
n->move(op.i(2), op.i(3));
+ n->setFloating(false);
} else if (action == "FLOATING") {
n->setFloating(op.b(2));
} else if (action == "LYRIC") {
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 3db1520..e2c7e9f 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -16,6 +16,7 @@ class SeekHandle: public QLabel
Q_OBJECT
public:
SeekHandle(QWidget *parent = 0);
+ int curx() const { return x() + width() / 2; }
int moveTimerId;
protected:
void mouseMoveEvent(QMouseEvent *event);
@@ -55,6 +56,10 @@ public:
int px2n(int px) const;
int h() const { return m_pitch->height; }
+public slots:
+ void timeSyllable();
+ void timeSentence();
+
signals:
void updateNoteInfo(NoteLabel*);
void analyzeProgress(int, int);
@@ -72,6 +77,9 @@ protected:
private:
void finalizeNewLyrics();
+ void timeCurrent();
+ void selectNextSyllableAfterSeekHandle();
+ void selectNextSentenceStart();
int m_requiredWidth;
int m_noteHalfHeight;
|