fix pianoroll crash if there is no score

This commit is contained in:
ws 2014-03-28 11:56:00 +01:00
parent 4a780b308e
commit 448c2cf085
4 changed files with 56 additions and 50 deletions

View file

@ -259,29 +259,6 @@ PianorollEditor::~PianorollEditor()
_score->removeViewer(this);
}
//---------------------------------------------------------
// setStaff
//---------------------------------------------------------
void PianorollEditor::setStaff(Staff* st)
{
staff = st;
_score = staff->score();
setWindowTitle(QString(tr("MuseScore: <%1> Staff: %2")).arg(_score->name()).arg(st->idx()));
TempoMap* tl = _score->tempomap();
TimeSigMap* sl = _score->sigmap();
for (int i = 0; i < 3; ++i)
locator[i].setContext(tl, sl);
gv->setStaff(staff, locator);
ruler->setScore(_score, locator);
if (waveView)
waveView->setScore(_score, locator);
pos->setContext(tl, sl);
updateSelection();
showWave->setEnabled(_score->audio() != 0);
}
//---------------------------------------------------------
// updateSelection
//---------------------------------------------------------
@ -515,31 +492,49 @@ void PianorollEditor::adjustCanvasPosition(const Element*, bool)
{
}
//---------------------------------------------------------
// setScore
//---------------------------------------------------------
void PianorollEditor::setScore(Score* s)
{
if (_score) {
_score->removeViewer(this);
disconnect(s, SIGNAL(posChanged(POS,unsigned)), this, SLOT(posChanged(POS,unsigned)));
}
_score = s;
_score->addViewer(this);
setLocator(POS::CURRENT, _score->pos(POS::CURRENT));
setLocator(POS::LEFT, _score->pos(POS::LEFT));
setLocator(POS::RIGHT, _score->pos(POS::RIGHT));
connect(s, SIGNAL(posChanged(POS,unsigned)), SLOT(posChanged(POS,unsigned)));
}
//---------------------------------------------------------
// removeScore
//---------------------------------------------------------
void PianorollEditor::removeScore()
{
_score = 0;
setStaff(0);
}
//---------------------------------------------------------
// setStaff
//---------------------------------------------------------
void PianorollEditor::setStaff(Staff* st)
{
if ((st && st->score() != _score) || (!st && _score)) {
if (_score) {
_score->removeViewer(this);
disconnect(_score, SIGNAL(posChanged(POS,unsigned)), this, SLOT(posChanged(POS,unsigned)));
}
_score = st ? st->score() : nullptr;
if (_score) {
_score->addViewer(this);
setLocator(POS::CURRENT, _score->pos(POS::CURRENT));
setLocator(POS::LEFT, _score->pos(POS::LEFT));
setLocator(POS::RIGHT, _score->pos(POS::RIGHT));
connect(_score, SIGNAL(posChanged(POS,unsigned)), SLOT(posChanged(POS,unsigned)));
}
}
staff = st;
if (staff) {
setWindowTitle(QString(tr("MuseScore: <%1> Staff: %2")).arg(_score->name()).arg(st->idx()));
TempoMap* tl = _score->tempomap();
TimeSigMap* sl = _score->sigmap();
for (int i = 0; i < 3; ++i)
locator[i].setContext(tl, sl);
pos->setContext(tl, sl);
showWave->setEnabled(_score->audio() != 0);
}
ruler->setScore(_score, locator);
gv->setStaff(staff, locator);
updateSelection();
setEnabled(st != nullptr);
}
//---------------------------------------------------------

View file

@ -82,13 +82,13 @@ class PianorollEditor : public QMainWindow, public MuseScoreView {
virtual ~PianorollEditor();
void setStaff(Staff* staff);
Score* score() const { return _score; }
// Score* score() const { return _score; }
void heartBeat(Seq*);
virtual void dataChanged(const QRectF&);
virtual void updateAll();
virtual void adjustCanvasPosition(const Element*, bool);
virtual void setScore(Score*);
virtual void setScore(Score*) {}
virtual void removeScore();
virtual void changeEditElement(Element*);
virtual QCursor cursor() const;

View file

@ -473,14 +473,21 @@ void PianoView::setStaff(Staff* s, Pos* l)
{
staff = s;
_locator = l;
pos.setContext(s->score()->tempomap(), s->score()->sigmap());
updateNotes();
setEnabled(staff != nullptr);
if (!staff) {
scene()->blockSignals(true); // block changeSelection()
scene()->clear();
scene()->blockSignals(false);
return;
}
pos.setContext(staff->score()->tempomap(), staff->score()->sigmap());
Measure* lm = staff->score()->lastMeasure();
ticks = lm->tick() + lm->ticks();
scene()->setSceneRect(0.0, 0.0, double(ticks + 960), keyHeight * 75);
updateNotes();
//
// move to something interesting
//
@ -516,9 +523,8 @@ void PianoView::addChord(Chord* chord)
void PianoView::updateNotes()
{
scene()->clear();
scene()->blockSignals(true); // block changeSelection()
scene()->clear();
createLocators();
int staffIdx = staff->idx();

View file

@ -125,7 +125,9 @@ void Ruler::setScore(Score* s, Pos* lc)
{
_score = s;
_locator = lc;
_cursor.setContext(s->tempomap(), s->sigmap());
if (_score)
_cursor.setContext(_score->tempomap(), _score->sigmap());
setEnabled(_score != 0);
}
//---------------------------------------------------------
@ -215,6 +217,9 @@ void Ruler::paintEvent(QPaintEvent* e)
if (x < (-_xpos))
x = -_xpos;
if (!_score)
return;
Pos pos1 = pix2pos(x);
Pos pos2 = pix2pos(x+w);