Skip to content

Commit

Permalink
fix some spanner bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 9, 2014
1 parent f97c0a4 commit d59cc84
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 112 deletions.
1 change: 0 additions & 1 deletion libmscore/accidental.h
Expand Up @@ -19,7 +19,6 @@
*/

#include "element.h"
#include "mscore.h"

class QPainter;

Expand Down
1 change: 0 additions & 1 deletion libmscore/articulation.h
Expand Up @@ -13,7 +13,6 @@
#ifndef __ARTICULATION_H__
#define __ARTICULATION_H__

#include "mscore.h"
#include "element.h"

class QPainter;
Expand Down
3 changes: 2 additions & 1 deletion libmscore/beam.h
Expand Up @@ -15,7 +15,6 @@

#include "element.h"
#include "durationtype.h"
#include "spanner.h"

class QPainter;

Expand All @@ -24,6 +23,8 @@ namespace Ms {
class ChordRest;
class MuseScoreView;
class Chord;
class System;
enum class SpannerSegmentType : char;

struct BeamFragment;

Expand Down
1 change: 0 additions & 1 deletion libmscore/bracket.h
Expand Up @@ -14,7 +14,6 @@
#define __BRACKET_H__

#include "element.h"
#include "mscore.h"

class QPainter;

Expand Down
6 changes: 2 additions & 4 deletions libmscore/chord.cpp
Expand Up @@ -942,10 +942,8 @@ void Chord::write(Xml& xml) const
_glissando->write(xml);
if (_tremolo && tremoloChordType() != TremoloChordType::TremoloSecondNote)
_tremolo->write(xml);
for (Element* e : _el) {
if (e->type() != Element::Type::SLUR)
e->write(xml);
}
for (Element* e : _el)
e->write(xml);
for (auto i : score()->spanner()) { // TODO: dont search whole list
Spanner* s = i.second;
if (s->generated() || s->type() != Element::Type::SLUR)
Expand Down
3 changes: 0 additions & 3 deletions libmscore/chord.h
Expand Up @@ -18,10 +18,7 @@
Definition of classes Chord, HelpLine and NoteList.
*/

#include <functional>
#include "chordrest.h"
#include "noteevent.h"
#include <vector>

class QPainter;

Expand Down
13 changes: 7 additions & 6 deletions libmscore/layout.cpp
Expand Up @@ -1375,6 +1375,13 @@ void Score::doLayout()
for (Measure* m = firstMeasureMM(); m; m = m->nextMeasureMM())
m->layout2();

for (auto s : _spanner.map()) { // DEBUG
Spanner* sp = s.second;
if (sp->type() == Element::Type::SLUR) {
sp->layout();
}
}

rebuildBspTree();

for (MuseScoreView* v : viewer) {
Expand Down Expand Up @@ -1402,12 +1409,6 @@ void Score::layoutSpanner()
}
Chord* c = static_cast<Chord*>(segment->element(track));
if (c && c->type() == Element::Type::CHORD) {
for (Chord* cc : c->graceNotes()) {
for (Element* e : cc->el()) {
if (e->type() == Element::Type::SLUR)
e->layout();
}
}
c->layoutStem();
for (Note* n : c->notes()) {
Tie* tie = n->tieFor();
Expand Down
36 changes: 7 additions & 29 deletions libmscore/line.cpp
Expand Up @@ -28,11 +28,6 @@ namespace Ms {
// LineSegment
//---------------------------------------------------------

LineSegment::LineSegment(Score* s)
: SpannerSegment(s)
{
}

LineSegment::LineSegment(const LineSegment& s)
: SpannerSegment(s)
{
Expand Down Expand Up @@ -144,28 +139,15 @@ QPointF LineSegment::getGrip(int grip) const
return p;
}

//---------------------------------------------------------
// pagePos
// return position in canvas coordinates
//---------------------------------------------------------

QPointF LineSegment::pagePos() const
{
QPointF pt(pos());
if (parent())
pt += parent()->pos();
return pt;
}

//---------------------------------------------------------
// gripAnchor
// return page coordinates
//---------------------------------------------------------

QPointF LineSegment::gripAnchor(int grip) const
{
qreal y = system()->staffYpage(staffIdx());
if (spannerSegmentType() == SpannerSegmentType::MIDDLE) {
qreal y = system()->staffYpage(staffIdx());
qreal x;
switch((GripLine)grip) {
case GripLine::START:
Expand All @@ -189,6 +171,7 @@ QPointF LineSegment::gripAnchor(int grip) const
else {
System* s;
QPointF p(line()->linePos((GripLine)grip, &s));
p.ry() += y - system()->pos().y();
if (s)
p += s->pos();
return p;
Expand Down Expand Up @@ -318,6 +301,7 @@ bool LineSegment::edit(MuseScoreView* sv, int curGrip, int key, Qt::KeyboardModi
_score->rebuildBspTree();
if (ls)
_score->undoRemoveElement(ls);

return true;
}

Expand Down Expand Up @@ -452,7 +436,7 @@ SLine::SLine(const SLine& s)

//---------------------------------------------------------
// linePos
// return System() coordinates
// return System/Staff coordinates
//---------------------------------------------------------

QPointF SLine::linePos(GripLine grip, System** sys)
Expand Down Expand Up @@ -524,21 +508,15 @@ QPointF SLine::linePos(GripLine grip, System** sys)
{
System* s = static_cast<Note*>(startElement())->chord()->segment()->system();
*sys = s;
if (grip == GripLine::START)
return startElement()->pagePos() - s->pagePos();
else
return endElement()->pagePos() - s->pagePos();
Element* e = grip == GripLine::START ? startElement() : endElement();
return e->pagePos() - QPointF(s->pagePos().x(), s->staffYpage(e->staffIdx()));
}

case Spanner::Anchor::CHORD:
qFatal("Sline::linePos(): anchor not implemented");
break;
}
qreal y = 0.0;
if (*sys)
y = (*sys)->staffYpage(staffIdx()) - (*sys)->pos().y();
// x += (*sys)->pos().x();
return QPointF(x, y);
return QPointF(x, 0.0);
}

//---------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions libmscore/line.h
Expand Up @@ -61,13 +61,12 @@ class LineSegment : public SpannerSegment {
virtual QPointF gripAnchor(int) const override;

public:
LineSegment(Score* s);
LineSegment(Score* s) : SpannerSegment(s) {}
LineSegment(const LineSegment&);
virtual LineSegment* clone() const = 0;
virtual void draw(QPainter*) const = 0;
SLine* line() const { return (SLine*)spanner(); }
virtual void spatiumChanged(qreal, qreal) override;
virtual QPointF pagePos() const override;

friend class SLine;
virtual void read(XmlReader&) override;
Expand Down
4 changes: 3 additions & 1 deletion libmscore/ottava.cpp
Expand Up @@ -56,11 +56,12 @@ static const OttavaDefault ottavaDefault[] = {
void OttavaSegment::layout()
{
TextLineSegment::layout1();
if (parent()) { // for palette
if (parent()) {
qreal yo(score()->styleS(StyleIdx::ottavaY).val() * spatium());
if (ottava()->placement() == Element::Placement::BELOW)
yo = -yo + staff()->height();
rypos() += yo;
return;
}
adjustReadPos();
}
Expand Down Expand Up @@ -175,6 +176,7 @@ Ottava::Ottava(Score* s)
lineWidthStyle = PropertyStyle::STYLED;
setLineStyle(Qt::PenStyle(score()->styleI(StyleIdx::ottavaLineStyle)));
lineStyleStyle = PropertyStyle::STYLED;
setFlag(ElementFlag::ON_STAFF, true);
}

Ottava::Ottava(const Ottava& o)
Expand Down
5 changes: 2 additions & 3 deletions libmscore/ottava.h
Expand Up @@ -39,11 +39,10 @@ class OttavaSegment : public TextLineSegment {
protected:

public:
// OttavaSegment(Score* s) : TextLineSegment(s) { setFlag(ElementFlag::ON_STAFF, true); }
OttavaSegment(Score* s) : TextLineSegment(s) { }
OttavaSegment(Score* s) : TextLineSegment(s) { }
virtual Element::Type type() const override { return Element::Type::OTTAVA_SEGMENT; }
virtual OttavaSegment* clone() const override { return new OttavaSegment(*this); }
Ottava* ottava() const { return (Ottava*)spanner(); }
Ottava* ottava() const { return (Ottava*)spanner(); }
virtual void layout() override;
virtual QVariant getProperty(P_ID propertyId) const override;
virtual bool setProperty(P_ID propertyId, const QVariant&) override;
Expand Down
6 changes: 4 additions & 2 deletions libmscore/score.cpp
Expand Up @@ -1348,10 +1348,10 @@ void Score::addElement(Element* element)
case Element::Type::HAIRPIN:
{
Spanner* spanner = static_cast<Spanner*>(element);
addSpanner(spanner);
if (et == Element::Type::TEXTLINE && spanner->anchor() == Spanner::Anchor::NOTE)
break;
foreach(SpannerSegment* ss, spanner->spannerSegments()) {
addSpanner(spanner);
for (SpannerSegment* ss : spanner->spannerSegments()) {
if (ss->system())
ss->system()->add(ss);
}
Expand Down Expand Up @@ -1486,6 +1486,8 @@ void Score::removeElement(Element* element)
case Element::Type::HAIRPIN:
{
Spanner* spanner = static_cast<Spanner*>(element);
if (et == Element::Type::TEXTLINE && spanner->anchor() == Spanner::Anchor::NOTE)
break;
removeSpanner(spanner);
for (SpannerSegment* ss : spanner->spannerSegments()) {
if (ss->system())
Expand Down
9 changes: 1 addition & 8 deletions libmscore/score.h
Expand Up @@ -19,26 +19,19 @@
*/

#include "input.h"
#include "mscore.h"
#include "style.h"
#include "durationtype.h"
#include "select.h"
#include "fraction.h"
#include "interval.h"
#include "synthesizerstate.h"
#include "mscoreview.h"
#include "segment.h"
#include "accidental.h"
#include "note.h"
#include "ottava.h"
#include "spannermap.h"
#include "pitchspelling.h"
#include "beam.h"

class QPainter;

namespace Ms {

class Interval;
class TempoMap;
struct TEvent;
class SigEvent;
Expand Down
6 changes: 3 additions & 3 deletions libmscore/scorefile.cpp
Expand Up @@ -1268,9 +1268,9 @@ void Score::writeSegments(Xml& xml, int strack, int etrack,
}
foreach (Element* e, segment->annotations()) {
if (e->track() != track || e->generated()
|| (e->systemFlag() && !writeSystemElements)) {
continue;
}
|| (e->systemFlag() && !writeSystemElements)) {
continue;
}
if (needTick) {
xml.tag("tick", segment->tick() - xml.tickDiff);
xml.curTick = segment->tick();
Expand Down
3 changes: 2 additions & 1 deletion libmscore/slur.cpp
Expand Up @@ -613,6 +613,8 @@ void SlurSegment::layout(const QPointF& p1, const QPointF& p2)
}
}
}
if (system() && staffIdx() != -1)
setPos(QPointF(0.0, -system()->staff(staffIdx())->y()));
setbbox(path.boundingRect());
adjustReadPos();
}
Expand Down Expand Up @@ -1452,6 +1454,5 @@ void SlurTie::fixupSegments(unsigned nsegs)
}
}
}

}

2 changes: 1 addition & 1 deletion libmscore/spanner.cpp
Expand Up @@ -33,7 +33,7 @@ QList<QPointF> Spanner::userOffsets;
SpannerSegment::SpannerSegment(Score* s)
: Element(s)
{
setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE | ElementFlag::SEGMENT);
setFlags(ElementFlag::MOVABLE | ElementFlag::SELECTABLE | ElementFlag::SEGMENT | ElementFlag::ON_STAFF);
setSpannerSegmentType(SpannerSegmentType::SINGLE);
_spanner = 0;
}
Expand Down
15 changes: 0 additions & 15 deletions libmscore/textline.cpp
Expand Up @@ -27,11 +27,6 @@ namespace Ms {
// TextLineSegment
//---------------------------------------------------------

TextLineSegment::TextLineSegment(Score* s)
: LineSegment(s)
{
}

TextLineSegment::TextLineSegment(const TextLineSegment& seg)
: LineSegment(seg)
{
Expand Down Expand Up @@ -565,16 +560,6 @@ LineSegment* TextLine::createLineSegment()
return new TextLineSegment(score());
}

//---------------------------------------------------------
// layout
// compute segments from tick() to _tick2
//---------------------------------------------------------

void TextLine::layout()
{
SLine::layout();
}

//---------------------------------------------------------
// spatiumChanged
//---------------------------------------------------------
Expand Down

0 comments on commit d59cc84

Please sign in to comment.