update pianoroll editor: editing of note even ontime/duration
This commit is contained in:
parent
cd5c7d916d
commit
0fded1b281
9 changed files with 193 additions and 42 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -74,6 +74,7 @@ class DrumrollEditor : public QMainWindow {
|
|||
void setStaff(Staff* staff);
|
||||
Score* score() const { return _score; }
|
||||
void heartBeat(Seq*);
|
||||
void writeSettings();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<PianoItem*>(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<QGraphicsItem*> items = gv->scene()->selectedItems();
|
||||
if (items.size() != 1)
|
||||
return;
|
||||
QGraphicsItem* item = items[0];
|
||||
if (item->type() != PianoItemType)
|
||||
return;
|
||||
PianoItem* pi = static_cast<PianoItem*>(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<QGraphicsItem*> items = gv->scene()->selectedItems();
|
||||
if (items.size() != 1)
|
||||
return;
|
||||
QGraphicsItem* item = items[0];
|
||||
if (item->type() != PianoItemType)
|
||||
return;
|
||||
PianoItem* pi = static_cast<PianoItem*>(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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue