From 0fded1b281404d377f6ae0578712938272676dda Mon Sep 17 00:00:00 2001 From: ws Date: Thu, 27 Mar 2014 14:50:01 +0100 Subject: [PATCH] update pianoroll editor: editing of note even ontime/duration --- libmscore/undo.cpp | 14 +++++ libmscore/undo.h | 21 +++++++- mscore/drumroll.cpp | 23 +++++++++ mscore/drumroll.h | 1 + mscore/musescore.cpp | 4 ++ mscore/pianoroll.cpp | 118 +++++++++++++++++++++++++++++++++++-------- mscore/pianoroll.h | 6 +++ mscore/pianoview.cpp | 41 +++++++++------ mscore/pianoview.h | 7 +-- 9 files changed, 193 insertions(+), 42 deletions(-) diff --git a/libmscore/undo.cpp b/libmscore/undo.cpp index 2f3dc0120e..2f018e3e46 100644 --- a/libmscore/undo.cpp +++ b/libmscore/undo.cpp @@ -3379,5 +3379,19 @@ void InsertTime::undo() score->insertTime(tick, -len); } +//--------------------------------------------------------- +// ChangeNoteEvent::flip +//--------------------------------------------------------- + +void ChangeNoteEvent::flip() + { + for (NoteEvent& ne : note->playEvents()) { + if (ne == oldEvent) { + ne = newEvent; + break; + } + } + qSwap(oldEvent, newEvent); + } } diff --git a/libmscore/undo.h b/libmscore/undo.h index 5bc80f9a08..cdcc5208e1 100644 --- a/libmscore/undo.h +++ b/libmscore/undo.h @@ -1384,11 +1384,28 @@ class InsertTime : public UndoCommand { void undo(); public: - InsertTime(Score* _score, int _tick, int _len) : - score(_score), tick(_tick), len(_len) {} + InsertTime(Score* _score, int _tick, int _len) + : score(_score), tick(_tick), len(_len) {} UNDO_NAME("InsertTime"); }; +//--------------------------------------------------------- +// ChangeNoteEvent +//--------------------------------------------------------- + +class ChangeNoteEvent : public UndoCommand { + Note* note; + NoteEvent oldEvent; + NoteEvent newEvent; + + void flip(); + + public: + ChangeNoteEvent(Note* n, const NoteEvent& oe, const NoteEvent& ne) + : note(n), oldEvent(oe), newEvent(ne) {} + }; + + } // namespace Ms #endif diff --git a/mscore/drumroll.cpp b/mscore/drumroll.cpp index 69a94fe5f9..2786cba564 100644 --- a/mscore/drumroll.cpp +++ b/mscore/drumroll.cpp @@ -41,6 +41,8 @@ namespace Ms { +extern bool useFactorySettings; + //--------------------------------------------------------- // DrumrollEditor //--------------------------------------------------------- @@ -159,6 +161,27 @@ DrumrollEditor::DrumrollEditor(QWidget* parent) ag->addAction(a); addActions(ag->actions()); connect(ag, SIGNAL(triggered(QAction*)), SLOT(cmd(QAction*))); + + if (!useFactorySettings) { + QSettings settings; + settings.beginGroup("Drumroll"); + resize(settings.value("size", QSize(900, 500)).toSize()); + move(settings.value("pos", QPoint(10, 10)).toPoint()); + settings.endGroup(); + } + } + +//--------------------------------------------------------- +// writeSettings +//--------------------------------------------------------- + +void DrumrollEditor::writeSettings() + { + QSettings settings; + settings.beginGroup("Drumroll"); + settings.setValue("size", size()); + settings.setValue("pos", QWidget::pos()); + settings.endGroup(); } //--------------------------------------------------------- diff --git a/mscore/drumroll.h b/mscore/drumroll.h index a8ed4be556..2eb9c59004 100644 --- a/mscore/drumroll.h +++ b/mscore/drumroll.h @@ -74,6 +74,7 @@ class DrumrollEditor : public QMainWindow { void setStaff(Staff* staff); Score* score() const { return _score; } void heartBeat(Seq*); + void writeSettings(); }; diff --git a/mscore/musescore.cpp b/mscore/musescore.cpp index fccafa9758..910cde6d69 100644 --- a/mscore/musescore.cpp +++ b/mscore/musescore.cpp @@ -290,6 +290,10 @@ void MuseScore::closeEvent(QCloseEvent* ev) } if (instrList) instrList->writeSettings(); + if (pianorollEditor) + pianorollEditor->writeSettings(); + if (drumrollEditor) + drumrollEditor->writeSettings(); ev->accept(); if (preferences.dirty) diff --git a/mscore/pianoroll.cpp b/mscore/pianoroll.cpp index 76c93a2aa6..2755919f14 100644 --- a/mscore/pianoroll.cpp +++ b/mscore/pianoroll.cpp @@ -34,6 +34,8 @@ namespace Ms { +extern bool useFactorySettings; + //--------------------------------------------------------- // PianorollEditor //--------------------------------------------------------- @@ -117,6 +119,14 @@ PianorollEditor::PianorollEditor(QWidget* parent) pitch->setReadOnly(true); tb->addWidget(pitch); + tb->addWidget(new QLabel(tr("OnTime:"))); + tb->addWidget((onTime = new QSpinBox)); + onTime->setRange(-2000, 2000); + + tb->addWidget(new QLabel(tr("Len:"))); + tb->addWidget((tickLen = new QSpinBox)); + tickLen->setRange(-2000, 2000); + //------------- qreal xmag = .1; ruler = new Ruler; @@ -181,10 +191,19 @@ PianorollEditor::PianorollEditor(QWidget* parent) connect(ruler, SIGNAL(locatorMoved(int, const Pos&)), SLOT(moveLocator(int, const Pos&))); connect(veloType, SIGNAL(activated(int)), SLOT(veloTypeChanged(int))); connect(velocity, SIGNAL(valueChanged(int)), SLOT(velocityChanged(int))); + connect(onTime, SIGNAL(valueChanged(int)), SLOT(onTimeChanged(int))); + connect(tickLen, SIGNAL(valueChanged(int)), SLOT(tickLenChanged(int))); connect(gv->scene(), SIGNAL(selectionChanged()), SLOT(selectionChanged())); connect(piano, SIGNAL(keyPressed(int)), SLOT(keyPressed(int))); connect(piano, SIGNAL(keyReleased(int)), SLOT(keyReleased(int))); - resize(800, 400); + + if (!useFactorySettings) { + QSettings settings; + settings.beginGroup("Pianoroll"); + resize(settings.value("size", QSize(900, 500)).toSize()); + move(settings.value("pos", QPoint(10, 10)).toPoint()); + settings.endGroup(); + } QActionGroup* ag = new QActionGroup(this); QAction* a = new QAction(this); @@ -196,6 +215,19 @@ PianorollEditor::PianorollEditor(QWidget* parent) setXpos(0); } +//--------------------------------------------------------- +// writeSettings +//--------------------------------------------------------- + +void PianorollEditor::writeSettings() + { + QSettings settings; + settings.beginGroup("Pianoroll"); + settings.setValue("size", size()); + settings.setValue("pos", QWidget::pos()); + settings.endGroup(); + } + //--------------------------------------------------------- // setXpos //--------------------------------------------------------- @@ -261,31 +293,20 @@ void PianorollEditor::updateSelection() PianoItem* item = static_cast(items[0]); if (item->type() == PianoItemType) { Note* note = item->note(); + NoteEvent* event = item->event(); pitch->setEnabled(true); pitch->setValue(note->pitch()); - veloType->setEnabled(true); - velocity->setEnabled(true); + onTime->setValue(event->ontime()); + tickLen->setValue(event->len()); updateVelocity(note); } } - else if (items.size() == 0) { - velocity->setValue(0); - velocity->setEnabled(false); - pitch->setValue(0); - pitch->setEnabled(false); - veloType->setEnabled(false); - veloType->setCurrentIndex(int(MScore::USER_VAL)); - } - else { - velocity->setEnabled(true); - velocity->setValue(0); - velocity->setReadOnly(false); - pitch->setEnabled(true); - pitch->setDeltaMode(true); - pitch->setValue(0); - veloType->setEnabled(true); - veloType->setCurrentIndex(int(MScore::OFFSET_VAL)); - } + bool b = items.size() != 0; + velocity->setEnabled(b); + pitch->setEnabled(b); + veloType->setEnabled(b); + onTime->setEnabled(b); + tickLen->setEnabled(b); } //--------------------------------------------------------- @@ -665,4 +686,59 @@ void PianorollEditor::posChanged(POS pos, unsigned tick) ruler->update(); } +//--------------------------------------------------------- +// onTimeChanged +//--------------------------------------------------------- + +void PianorollEditor::onTimeChanged(int val) + { + QList items = gv->scene()->selectedItems(); + if (items.size() != 1) + return; + QGraphicsItem* item = items[0]; + if (item->type() != PianoItemType) + return; + PianoItem* pi = static_cast(item); + Note* note = pi->note(); + NoteEvent* event = pi->event(); + if (event->ontime() == val) + return; + + NoteEvent ne = *event; + ne.setOntime(val); + _score->undo()->beginMacro(); + _score->undo(new ChangeNoteEvent(note, *event, ne)); + _score->undo()->endMacro(_score->undo()->current()->childCount() == 0); + gv->scene()->update(pi->updateValues()); + } + +//--------------------------------------------------------- +// tickLenChanged +//--------------------------------------------------------- + +void PianorollEditor::tickLenChanged(int val) + { + QList items = gv->scene()->selectedItems(); + if (items.size() != 1) + return; + QGraphicsItem* item = items[0]; + if (item->type() != PianoItemType) + return; + PianoItem* pi = static_cast(item); + Note* note = pi->note(); + NoteEvent* event = pi->event(); + if (event->len() == val) + return; + + NoteEvent ne = *event; + ne.setLen(val); +// _score->undo()->beginMacro(); + _score->startCmd(); + _score->undo(new ChangeNoteEvent(note, *event, ne)); + _score->endCmd(); +// _score->undo()->endMacro(_score->undo()->current()->childCount() == 0); + gv->scene()->update(pi->updateValues()); + mscore->endCmd(); + } + } diff --git a/mscore/pianoroll.h b/mscore/pianoroll.h index ecc8b7d42c..0911a3ef2b 100644 --- a/mscore/pianoroll.h +++ b/mscore/pianoroll.h @@ -46,6 +46,8 @@ class PianorollEditor : public QMainWindow, public MuseScoreView { Staff* staff; Awl::PitchEdit* pitch; QSpinBox* velocity; + QSpinBox* onTime; + QSpinBox* tickLen; Pos locator[3]; QComboBox* veloType; Awl::PosLabel* pos; @@ -69,6 +71,8 @@ class PianorollEditor : public QMainWindow, public MuseScoreView { void setXpos(int x); void showWaveView(bool); void posChanged(POS pos, unsigned tick); + void tickLenChanged(int); + void onTimeChanged(int val); public slots: void changeSelection(int); @@ -100,6 +104,8 @@ class PianorollEditor : public QMainWindow, public MuseScoreView { virtual void drawBackground(QPainter* /*p*/, const QRectF& /*r*/) const {} void setLocator(POS pos, int tick) { locator[int(pos)].setTick(tick); } + + void writeSettings(); }; diff --git a/mscore/pianoview.cpp b/mscore/pianoview.cpp index 62e331a975..900d505bd2 100644 --- a/mscore/pianoview.cpp +++ b/mscore/pianoview.cpp @@ -46,24 +46,33 @@ static int pitch2y(int pitch) //--------------------------------------------------------- PianoItem::PianoItem(Note* n, NoteEvent* e) - : QGraphicsRectItem(0), _note(n), event(e) + : QGraphicsRectItem(0), _note(n), _event(e) { - Chord* chord = n->chord(); - int tieLen, ticks; - ticks = chord->duration().ticks(); - tieLen = n->playTicks() - ticks; - setFlags(flags() | QGraphicsItem::ItemIsSelectable); + setBrush(QBrush()); + updateValues(); + } - int pitch = n->pitch() + e->pitch(); - int len = ticks * e->len() / 1000 + tieLen; +//--------------------------------------------------------- +// updateValues +//--------------------------------------------------------- + +QRectF PianoItem::updateValues() + { + QRectF r(rect().translated(pos())); + Chord* chord = _note->chord(); + int ticks = chord->duration().ticks(); + int tieLen = _note->playTicks() - ticks; + int pitch = _note->pitch() + _event->pitch(); + int len = ticks * _event->len() / 1000 + tieLen; setRect(0, 0, len, keyHeight/2); - setBrush(QBrush()); setSelected(_note->selected()); - setPos(_note->chord()->tick() + e->ontime() * ticks / 1000 + MAP_OFFSET, + setPos(_note->chord()->tick() + _event->ontime() * ticks / 1000 + MAP_OFFSET, pitch2y(pitch) + keyHeight / 4); + + return r | rect().translated(pos()); } //--------------------------------------------------------- @@ -173,11 +182,11 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r) if (magStep > 0) { double x = double(pos2pix(stick)); if (x > 0) { - p->setPen(Qt::lightGray); + p->setPen(QPen(Qt::lightGray, 0.0)); p->drawLine(x, y1, x, y2); } else { - p->setPen(Qt::black); + p->setPen(QPen(Qt::black, 0.0)); p->drawLine(x, y1, x, y1); } } @@ -190,11 +199,11 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r) if (xp < 0) continue; if (xp > 0) { - p->setPen(beat == 0 ? Qt::lightGray : Qt::gray); + p->setPen(QPen(beat == 0 ? Qt::lightGray : Qt::gray, 0.0)); p->drawLine(xp, y1, xp, y2); } else { - p->setPen(Qt::black); + p->setPen(QPen(Qt::black, 0.0)); p->drawLine(xp, y1, xp, y2); } } @@ -218,11 +227,11 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r) if (xp < 0) continue; if (xp > 0) { - p->setPen(i == 0 && beat == 0 ? Qt::lightGray : Qt::gray); + p->setPen(QPen(i == 0 && beat == 0 ? Qt::lightGray : Qt::gray, 0.0)); p->drawLine(xp, y1, xp, y2); } else { - p->setPen(Qt::black); + p->setPen(QPen(Qt::black, 0.0)); p->drawLine(xp, y1, xp, y2); } } diff --git a/mscore/pianoview.h b/mscore/pianoview.h index ab4728bcef..e17ca22b2e 100644 --- a/mscore/pianoview.h +++ b/mscore/pianoview.h @@ -30,14 +30,16 @@ enum { PianoItemType = QGraphicsItem::UserType + 1 }; class PianoItem : public QGraphicsRectItem { Note* _note; - NoteEvent* event; + NoteEvent* _event; virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); public: PianoItem(Note*, NoteEvent*); virtual ~PianoItem() {} virtual int type() const { return PianoItemType; } - Note* note() { return _note; } + Note* note() { return _note; } + NoteEvent* event() { return _event; } + QRectF updateValues(); }; //--------------------------------------------------------- @@ -87,7 +89,6 @@ class PianoView : public QGraphicsView { }; - } // namespace Ms #endif