MuseScore  3.4
Music composition and notation
beam.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2012 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 __BEAM_H__
14 #define __BEAM_H__
15 
16 #include "element.h"
17 #include "durationtype.h"
18 #include "property.h"
19 
20 namespace Ms {
21 
22 class ChordRest;
23 class MuseScoreView;
24 class Chord;
25 class System;
26 class Skyline;
27 
28 enum class IconType : signed char;
29 enum class SpannerSegmentType;
30 
31 struct BeamFragment;
32 
33 //---------------------------------------------------------
34 // @@ Beam
35 //---------------------------------------------------------
36 
37 class Beam final : public Element {
38  Q_GADGET
39  QVector<ChordRest*> _elements; // must be sorted by tick
40  QVector<QLineF*> beamSegments;
42 
43  bool _up;
44  bool _distribute; // equal spacing of elements
45  bool _noSlope;
46 
47  bool _userModified[2]; // 0: auto/down 1: up
48  bool _isGrace;
49  bool _cross;
50 
51  qreal _grow1; // define "feather" beams
52  qreal _grow2;
53  qreal _beamDist;
54 
55  QVector<BeamFragment*> fragments; // beam splits across systems
56 
57  mutable int _id; // used in read()/write()
58 
59  int minMove; // set in layout1()
60  int maxMove;
62  qreal slope { 0.0 };
63 
64  void layout2(std::vector<ChordRest*>, SpannerSegmentType, int frag);
65  bool twoBeamedNotes();
66  void computeStemLen(const std::vector<ChordRest*>& crl, qreal& py1, int beamLevels);
67  bool slopeZero(const std::vector<ChordRest*>& crl);
68  bool hasNoSlope();
69  void addChordRest(ChordRest* a);
70  void removeChordRest(ChordRest* a);
71 
72  public:
73  enum class Mode : signed char {
75  AUTO, BEGIN, MID, END, NONE, BEGIN32, BEGIN64, INVALID = -1
77  };
78  Q_ENUM(Mode);
79 
80  Beam(Score* = 0);
81  Beam(const Beam&);
82  ~Beam();
83  virtual Beam* clone() const override { return new Beam(*this); }
84  virtual ElementType type() const override { return ElementType::BEAM; }
85  virtual QPointF pagePos() const override;
86  virtual QPointF canvasPos() const override;
87 
88  virtual bool isEditable() const override { return true; }
89  virtual void startEdit(EditData&) override;
90  virtual void endEdit(EditData&) override;
91  virtual void editDrag(EditData&) override;
92 
93  virtual Fraction tick() const override;
94  virtual Fraction rtick() const override;
95 
96  virtual void write(XmlWriter& xml) const override;
97  virtual void read(XmlReader&) override;
98  virtual void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/) override;
99 
100  virtual void reset() override;
101 
102  System* system() const { return toSystem(parent()); }
103 
104  void layout1();
105  void layoutGraceNotes();
106  void layout();
107 
108  const QVector<ChordRest*>& elements() { return _elements; }
109  void clear() { _elements.clear(); }
110  bool empty() const { return _elements.empty(); }
111  bool contains(const ChordRest* cr) const { return std::find(_elements.begin(), _elements.end(), cr) != _elements.end(); }
112 
113  virtual void add(Element*) override;
114  virtual void remove(Element*) override;
115 
116  virtual void move(const QPointF&) override;
117  virtual void draw(QPainter*) const override;
118 
119  bool up() const { return _up; }
120  void setUp(bool v) { _up = v; }
121  void setId(int i) const { _id = i; }
122  int id() const { return _id; }
123  bool noSlope() const { return _noSlope; }
124  void setNoSlope(bool val) { _noSlope = val; }
125 
126  void setBeamDirection(Direction d);
127  Direction beamDirection() const { return _direction; }
128 
129  virtual bool acceptDrop(EditData&) const override;
130  virtual Element* drop(EditData&) override;
131 
132  qreal growLeft() const { return _grow1; }
133  qreal growRight() const { return _grow2; }
134  void setGrowLeft(qreal val) { _grow1 = val; }
135  void setGrowRight(qreal val) { _grow2 = val; }
136 
137  bool distribute() const { return _distribute; }
138  void setDistribute(bool val) { _distribute = val; }
139 
140  bool userModified() const;
141  void setUserModified(bool val);
142 
143  QPointF beamPos() const;
144  void setBeamPos(const QPointF& bp);
145 
146  qreal beamDist() const { return _beamDist; }
147 
148  virtual QVariant getProperty(Pid propertyId) const override;
149  virtual bool setProperty(Pid propertyId, const QVariant&) override;
150  virtual QVariant propertyDefault(Pid id) const override;
151 
152  bool isGrace() const { return _isGrace; } // for debugger
153  bool cross() const { return _cross; }
154 
155  void addSkyline(Skyline&);
156 
157  virtual void triggerLayout() const override;
158 
159  EditBehavior normalModeEditBehavior() const override { return EditBehavior::Edit; }
160  int gripsCount() const override { return 3; }
161  Grip initialEditModeGrip() const override { return Grip::END; }
162  Grip defaultGrip() const override { return Grip::MIDDLE; }
163  std::vector<QPointF> gripsPositions(const EditData&) const override;
164 
165  static IconType iconType(Mode);
166 
167  QRectF drag(EditData &) override;
168  bool isMovable() const override;
169  void startDrag(EditData &) override;
170 
171  private:
172  void initBeamEditData(EditData &ed);
173  };
174 
175 
176 } // namespace Ms
177 #endif
bool _noSlope
Definition: beam.h:45
Definition: durationtype.h:28
bool contains(const ChordRest *cr) const
Definition: beam.h:111
Definition: beam.h:37
Pid
Definition: property.h:62
Definition: xml.h:67
System * system() const
Definition: beam.h:102
int _id
Definition: beam.h:57
qreal _beamDist
Definition: beam.h:53
virtual ElementType type() const override
Definition: beam.h:84
int gripsCount() const override
Definition: beam.h:160
Base class of score layout elements.
Definition: element.h:158
void setUp(bool v)
Definition: beam.h:120
qreal beamDist() const
Definition: beam.h:146
int minMove
Definition: beam.h:59
IconType
Definition: mscore.h:219
Definition: score.h:391
Q_GADGET QVector< ChordRest * > _elements
Definition: beam.h:39
void setId(int i) const
Definition: beam.h:121
void clear()
Definition: beam.h:109
Direction beamDirection() const
Definition: beam.h:127
int id() const
Definition: beam.h:122
Direction _direction
Definition: beam.h:41
Grip
Definition: element.h:43
const QVector< ChordRest * > & elements()
Definition: beam.h:108
qreal growLeft() const
Definition: beam.h:132
SpannerSegmentType
Definition: spanner.h:26
Mode
Definition: beam.h:73
Definition: aeolus.cpp:26
virtual Beam * clone() const override
Definition: beam.h:83
QVector< BeamFragment * > fragments
Definition: beam.h:55
Definition: skyline.h:75
Grip defaultGrip() const override
Definition: beam.h:162
EditBehavior normalModeEditBehavior() const override
Definition: beam.h:159
Definition: xml.h:218
qreal _grow2
Definition: beam.h:52
qreal growRight() const
Definition: beam.h:133
bool _distribute
Definition: beam.h:44
bool isGrace() const
Definition: beam.h:152
TDuration maxDuration
Definition: beam.h:61
QVector< QLineF * > beamSegments
Definition: beam.h:40
bool _up
Definition: beam.h:43
Definition: chordrest.h:48
Direction
Definition: types.h:282
Definition: element.h:111
bool empty() const
Definition: beam.h:110
void setGrowRight(qreal val)
Definition: beam.h:135
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
bool _cross
Definition: beam.h:49
bool distribute() const
Definition: beam.h:137
bool up() const
Definition: beam.h:119
bool noSlope() const
Definition: beam.h:123
Definition: fraction.h:46
Grip initialEditModeGrip() const override
Definition: beam.h:161
void setDistribute(bool val)
Definition: beam.h:138
ElementType
Definition: types.h:34
bool _isGrace
Definition: beam.h:48
int maxMove
Definition: beam.h:60
virtual bool isEditable() const override
Definition: beam.h:88
void setNoSlope(bool val)
Definition: beam.h:124
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
EditBehavior
Definition: element.h:173
void setGrowLeft(qreal val)
Definition: beam.h:134
bool cross() const
Definition: beam.h:153
qreal _grow1
Definition: beam.h:51