pianoroll updates

This commit is contained in:
ws 2013-02-18 19:52:24 +01:00
parent cefc79390c
commit 699b9afda3
4 changed files with 62 additions and 10 deletions

View file

@ -1198,8 +1198,8 @@ void Score::upDown(bool up, UpDownMode mode)
}
_is.pitch = newPitch;
if ( (oNote->pitch() != newPitch) || (oNote->tpc() != newTpc) )
undoChangePitch(oNote, newPitch, newTpc, oNote->line()/*, fret, string*/);
if ((oNote->pitch() != newPitch) || (oNote->tpc() != newTpc))
undoChangePitch(oNote, newPitch, newTpc, oNote->line());
// store fret change only if undoChangePitch has not been called,
// as undoChangePitch() already manages fret changes, if necessary
else if( oNote->staff()->staffType()->group() == TAB_STAFF) {
@ -1219,6 +1219,9 @@ void Score::upDown(bool up, UpDownMode mode)
// play new note with velocity 80 for 0.3 sec:
_playNote = true;
}
_selection.clear();
foreach(Note* note, el)
_selection.add(note);
_selection.updateState(); // accidentals may have changed
}

View file

@ -283,8 +283,9 @@ void PianorollEditor::updateSelection()
void PianorollEditor::selectionChanged()
{
printf("===PianorollEditor::selectionChanged\n");
updateSelection();
// _score->blockSignals(true);
QList<QGraphicsItem*> items = gv->scene()->selectedItems();
if (items.size() == 1) {
QGraphicsItem* item = items[0];
@ -305,7 +306,6 @@ void PianorollEditor::selectionChanged()
}
_score->setUpdateAll();
_score->end();
// _score->blockSignals(false);
}
//---------------------------------------------------------
@ -314,7 +314,7 @@ void PianorollEditor::selectionChanged()
void PianorollEditor::changeSelection(int)
{
// gv->scene()->blockSignals(true);
gv->scene()->blockSignals(true);
gv->scene()->clearSelection();
QList<QGraphicsItem*> il = gv->scene()->items();
foreach(QGraphicsItem* item, il) {
@ -322,7 +322,7 @@ void PianorollEditor::changeSelection(int)
if (note)
item->setSelected(note->selected());
}
// gv->scene()->blockSignals(false);
gv->scene()->blockSignals(false);
}
//---------------------------------------------------------
@ -617,7 +617,7 @@ Element* PianorollEditor::elementNear(QPointF)
void PianorollEditor::updateAll()
{
// printf("PianorollEditor::updateAll()\n");
gv->update();
}
//---------------------------------------------------------

View file

@ -47,7 +47,7 @@ PianoItem::PianoItem(Note* n, NoteEvent* e)
: QGraphicsRectItem(), note(n), event(e)
{
setFlags(flags() | QGraphicsItem::ItemIsSelectable);
int pitch = n->pitch();
int pitch = n->pitch() + e->pitch();
int ticks = n->playTicks();
int len = ticks * e->len() / 1000;
setRect(0, 0, len, keyHeight/2);
@ -322,8 +322,9 @@ void PianoView::setStaff(Staff* s, Pos* l)
pos.setContext(s->score()->tempomap(), s->score()->sigmap());
scene()->blockSignals(true);
scene()->clearSelection();
scene()->clear();
for (int i = 0; i < 3; ++i) {
locatorLines[i] = new QGraphicsLineItem(QLineF(0.0, 0.0, 0.0, keyHeight * 75.0 * 5));
QPen pen(lcColors[i]);
@ -374,7 +375,6 @@ void PianoView::setStaff(Staff* s, Pos* l)
boundingRect |= item->mapToScene(item->boundingRect()).boundingRect();
}
centerOn(boundingRect.center());
horizontalScrollBar()->setValue(0);
}
@ -558,3 +558,50 @@ void PianoView::ensureVisible(int tick)
QGraphicsView::ensureVisible(qreal(tick), pt.y(), 240.0, 1.0);
}
//---------------------------------------------------------
// update
//---------------------------------------------------------
void PianoView::update()
{
static const QColor lcColors[3] = { Qt::red, Qt::blue, Qt::blue };
scene()->blockSignals(true);
scene()->clear();
for (int i = 0; i < 3; ++i) {
locatorLines[i] = new QGraphicsLineItem(QLineF(0.0, 0.0, 0.0, keyHeight * 75.0 * 5));
QPen pen(lcColors[i]);
pen.setWidth(2);
locatorLines[i]->setPen(pen);
locatorLines[i]->setZValue(1000+i); // set stacking order
locatorLines[i]->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
scene()->addItem(locatorLines[i]);
}
int staffIdx = staff->idx();
int startTrack = staffIdx * VOICES;
int endTrack = startTrack + VOICES;
Segment::SegmentTypes st = Segment::SegChordRest | Segment::SegGrace;
for (Segment* s = staff->score()->firstSegment(st); s; s = s->next1(st)) {
for (int track = startTrack; track < endTrack; ++track) {
Chord* chord = static_cast<Chord*>(s->element(track));
if (chord == 0 || chord->type() != Element::CHORD)
continue;
foreach(Note* note, chord->notes()) {
if (note->tieBack())
continue;
int n = note->playEvents().size();
for (int i = 0; i < n; ++i) {
NoteEvent* e = &note->playEvents()[i];
scene()->addItem(new PianoItem(note, e));
}
}
}
}
for (int i = 0; i < 3; ++i)
moveLocator(i);
scene()->blockSignals(false);
}

View file

@ -31,6 +31,7 @@ class PianoItem : public QGraphicsRectItem {
public:
PianoItem(Note*, NoteEvent*);
virtual ~PianoItem() {}
};
//---------------------------------------------------------
@ -68,6 +69,7 @@ class PianoView : public QGraphicsView {
public slots:
void moveLocator(int);
void update();
public:
PianoView();