MuseScore  3.4
Music composition and notation
slurtie.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2016 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __SLURTIE_H__
14 #define __SLURTIE_H__
15 
16 #include "spanner.h"
17 #include "mscore.h"
18 
19 namespace Ms {
20 
21 //---------------------------------------------------------
22 // SlurPos
23 //---------------------------------------------------------
24 
25 struct SlurPos {
26  QPointF p1; // start point of slur
27  System* system1; // start system of slur
28  QPointF p2; // end point of slur
29  System* system2; // end system of slur
30  };
31 
32 struct SlurOffsets {
33  QPointF o[4];
34  };
35 
36 //---------------------------------------------------------
37 // UP
38 //---------------------------------------------------------
39 
40 struct UP {
41  QPointF p; // layout position relative to pos()
42  QPointF off; // user offset in point units
43 
44  QPointF pos() const { return p + off; }
45  bool operator!=(const UP& up) const { return p != up.p || off != up.off; }
46  };
47 
48 //---------------------------------------------------------
49 // CubicBezier
50 // Helper class to optimize cubic Bezier curve points
51 // calculation.
52 //---------------------------------------------------------
53 
54 class CubicBezier {
55  QPointF p1;
56  QPointF p2;
57  QPointF p3;
58  QPointF p4;
59 
60  public:
61  CubicBezier(QPointF _p1, QPointF _p2, QPointF _p3, QPointF _p4)
62  : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {}
63 
64  QPointF pointAtPercent(qreal t) const
65  {
66  Q_ASSERT(t >= 0.0 && t <= 1.0);
67  const qreal r = 1.0 - t;
68  const QPointF B123 = r * (r*p1 + t*p2) + t * (r*p2 + t*p3);
69  const QPointF B234 = r * (r*p2 + t*p3) + t * (r*p3 + t*p4);
70  return r*B123 + t*B234;
71  }
72  };
73 
74 class SlurTie;
75 
76 //---------------------------------------------------------
77 // SlurTieSegment
78 //---------------------------------------------------------
79 
81  protected:
82  struct UP _ups[int(Grip::GRIPS)];
83 
84  QPainterPath path;
85  QPainterPath shapePath;
86  Shape _shape;
87 
88  virtual void changeAnchor(EditData&, Element*) = 0;
89  virtual QPointF gripAnchor(Grip grip) const override;
90 
91  public:
92  SlurTieSegment(Score*);
93  SlurTieSegment(const SlurTieSegment&);
94  virtual void spatiumChanged(qreal, qreal) override;
95  SlurTie* slurTie() const { return (SlurTie*)spanner(); }
96 
97  virtual void startEditDrag(EditData& ed) override;
98  virtual void endEditDrag(EditData& ed) override;
99  virtual void editDrag(EditData&) override;
100 
101  virtual QVariant getProperty(Pid propertyId) const override;
102  virtual bool setProperty(Pid propertyId, const QVariant&) override;
103  virtual QVariant propertyDefault(Pid id) const override;
104  virtual void reset() override;
105  virtual void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps) override;
106  virtual void move(const QPointF& s) override;
107  virtual bool isEditable() const override { return true; }
108 
109  void setSlurOffset(Grip i, const QPointF& val) { _ups[int(i)].off = val; }
110  const struct UP& ups(Grip i) const { return _ups[int(i)]; }
111  struct UP& ups(Grip i) { return _ups[int(i)]; }
112  virtual Shape shape() const override { return _shape; }
113 
115  int gripsCount() const override { return int(Grip::GRIPS); }
116  Grip initialEditModeGrip() const override{ return Grip::END; }
117  Grip defaultGrip() const override { return Grip::DRAG; }
118  std::vector<QPointF> gripsPositions(const EditData&) const override;
119 
120  void writeSlur(XmlWriter& xml, int no) const;
121  void read(XmlReader&);
122  virtual void drawEditMode(QPainter*, EditData&) override;
123  virtual void computeBezier(QPointF so = QPointF()) = 0;
124  };
125 
126 //-------------------------------------------------------------------
127 // @@ SlurTie
128 // @P lineType int (0 - solid, 1 - dotted, 2 - dashed, 3 - wide dashed)
129 // @P slurDirection enum (Direction.AUTO, Direction.DOWN, Direction.UP)
130 //-------------------------------------------------------------------
131 
132 class SlurTie : public Spanner {
133  int _lineType; // 0 = solid, 1 = dotted, 2 = dashed, 3 = wide dashed
134 
135  protected:
136  bool _up; // actual direction
137 
139  qreal firstNoteRestSegmentX(System* system);
140  void fixupSegments(unsigned nsegs);
141 
142  public:
143  SlurTie(Score*);
144  SlurTie(const SlurTie&);
145  ~SlurTie();
146 
147  virtual ElementType type() const = 0;
148  bool up() const { return _up; }
149 
150  virtual void reset() override;
151 
152  Direction slurDirection() const { return _slurDirection; }
153  void setSlurDirection(Direction d) { _slurDirection = d; }
154  void undoSetSlurDirection(Direction d);
155 
156  virtual void layout2(const QPointF, int, struct UP&) {}
157  virtual bool contains(const QPointF&) const { return false; } // not selectable
158 
159  virtual void read(XmlReader&) override;
160 
161  void writeProperties(XmlWriter& xml) const;
162  bool readProperties(XmlReader&);
163 
164  int lineType() const { return _lineType; }
165  void setLineType(int val) { _lineType = val; }
166  void undoSetLineType(int);
167 
168  virtual void slurPos(SlurPos*) = 0;
169  virtual SlurTieSegment* newSlurTieSegment() = 0;
170 
171 
172  virtual QVariant getProperty(Pid propertyId) const override;
173  virtual bool setProperty(Pid propertyId, const QVariant&) override;
174  virtual QVariant propertyDefault(Pid id) const override;
175  };
176 
177 }
178 
179 #endif
180 
virtual void layout2(const QPointF, int, struct UP &)
Definition: slurtie.h:156
virtual bool isEditable() const override
Definition: slurtie.h:107
Pid
Definition: property.h:62
Definition: xml.h:67
void setSlurDirection(Direction d)
Definition: slurtie.h:153
QPointF p3
Definition: slurtie.h:57
parent: System
Definition: spanner.h:50
int gripsCount() const override
Definition: slurtie.h:115
QPointF p2
Definition: slurtie.h:28
Virtual base class for slurs, ties, lines etc.
Definition: spanner.h:136
Definition: slurtie.h:132
void setSlurOffset(Grip i, const QPointF &val)
Definition: slurtie.h:109
QPointF p
Definition: slurtie.h:41
Direction _slurDirection
Definition: slurtie.h:138
Definition: slurtie.h:54
virtual Shape shape() const override
Definition: slurtie.h:112
QPointF pos() const
Definition: slurtie.h:44
Definition: score.h:391
PropertyFlags
Definition: property.h:54
Element::EditBehavior normalModeEditBehavior() const override
Definition: slurtie.h:114
bool up() const
Definition: slurtie.h:148
Definition: slurtie.h:32
QPointF p4
Definition: slurtie.h:58
QPointF off
Definition: slurtie.h:42
QPointF p1
Definition: slurtie.h:26
int _lineType
Definition: slurtie.h:133
bool operator!=(const UP &up) const
Definition: slurtie.h:45
System * system1
Definition: slurtie.h:27
System * system2
Definition: slurtie.h:29
virtual bool contains(const QPointF &) const
Definition: slurtie.h:157
Grip
Definition: element.h:43
struct UP & ups(Grip i)
Definition: slurtie.h:111
QPointF p2
Definition: slurtie.h:56
const struct UP & ups(Grip i) const
Definition: slurtie.h:110
Definition: aeolus.cpp:26
Definition: slurtie.h:80
Definition: slurtie.h:25
Definition: xml.h:218
CubicBezier(QPointF _p1, QPointF _p2, QPointF _p3, QPointF _p4)
Definition: slurtie.h:61
QPointF p1
Definition: slurtie.h:55
Direction slurDirection() const
Definition: slurtie.h:152
Direction
Definition: types.h:282
Definition: element.h:111
bool _up
Definition: slurtie.h:136
QPointF pointAtPercent(qreal t) const
Definition: slurtie.h:64
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
Definition: shape.h:42
Grip initialEditModeGrip() const override
Definition: slurtie.h:116
Grip defaultGrip() const override
Definition: slurtie.h:117
ElementType
Definition: types.h:34
Definition: slurtie.h:40
void setLineType(int val)
Definition: slurtie.h:165
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
EditBehavior
Definition: element.h:173
int lineType() const
Definition: slurtie.h:164