MuseScore Plugins  3.2.3
Plugins API for MuseScore
beam.h
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 SpannerSegmentType;
29 
30 struct BeamFragment;
31 
32 //---------------------------------------------------------
33 // @@ Beam
34 //---------------------------------------------------------
35 
36 class Beam final : public Element {
37  Q_GADGET
38  QVector<ChordRest*> _elements; // must be sorted by tick
39  QVector<QLineF*> beamSegments;
40  Direction _direction;
41 
42  bool _up;
43  bool _distribute; // equal spacing of elements
44  bool _noSlope;
45 
46  bool _userModified[2]; // 0: auto/down 1: up
47  bool _isGrace;
48  bool _cross;
49 
50  qreal _grow1; // define "feather" beams
51  qreal _grow2;
52  qreal _beamDist;
53 
54  QVector<BeamFragment*> fragments; // beam splits across systems
55 
56  mutable int _id; // used in read()/write()
57 
58  int minMove; // set in layout1()
59  int maxMove;
60  TDuration maxDuration;
61  qreal slope { 0.0 };
62 
63  void layout2(std::vector<ChordRest*>, SpannerSegmentType, int frag);
64  bool twoBeamedNotes();
65  void computeStemLen(const std::vector<ChordRest*>& crl, qreal& py1, int beamLevels);
66  bool slopeZero(const std::vector<ChordRest*>& crl);
67  bool hasNoSlope();
68  void addChordRest(ChordRest* a);
69  void removeChordRest(ChordRest* a);
70 
71  public:
72  enum class Mode : signed char {
76  };
77  Q_ENUM(Mode)
78 
79  Beam(Score* = 0);
80  Beam(const Beam&);
81  ~Beam();
82  virtual Beam* clone() const override { return new Beam(*this); }
83  virtual ElementType type() const override { return ElementType::BEAM; }
84  virtual QPointF pagePos() const override;
85  virtual QPointF canvasPos() const override;
86 
87  virtual bool isEditable() const override { return true; }
88  virtual void startEdit(EditData&) override;
89  virtual void endEdit(EditData&) override;
90  virtual void editDrag(EditData&) override;
91  virtual void updateGrips(EditData&) const 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 
160 
161 } // namespace Ms
162 #endif
Ms::Beam
Definition: beam.h:36
Ms::Beam::Mode::INVALID
@ INVALID
Ms::Beam::Mode::MID
@ MID
Ms::Beam::Mode::BEGIN
@ BEGIN
Ms::SegmentType::ChordRest
@ ChordRest
Ms::Beam::Mode::END
@ END
Ms::Beam::Mode::AUTO
@ AUTO
Ms::ElementType::BEAM
@ BEAM
Ms::Beam::pagePos
virtual QPointF pagePos() const override
position in page coordinates
Ms::Beam::Mode::BEGIN32
@ BEGIN32
Ms::Beam::Mode::NONE
@ NONE
Ms::Beam::Mode::BEGIN64
@ BEGIN64
Ms::Beam::canvasPos
virtual QPointF canvasPos() const override
position in page coordinates
Ms
Definition: cursor.cpp:29
Ms::Direction
Direction
Definition: types.h:281
Ms::ElementType
ElementType
Definition: types.h:34
Ms::Beam::Mode
Mode
Definition: beam.h:72