1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2002-2011 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 __HAIRPIN_H__
14 #define __HAIRPIN_H__
15 
16 #include "element.h"
17 #include "dynamic.h"
18 #include "line.h"
19 #include "textlinebase.h"
20 #include "mscore.h"
21 
22 namespace Ms {
23 
24 class Score;
25 class Hairpin;
26 
27 enum class ChangeMethod : signed char;
28 
29 enum class HairpinType : signed char {
30       INVALID = -1,
31       CRESC_HAIRPIN,
32       DECRESC_HAIRPIN,
33       CRESC_LINE,
34       DECRESC_LINE
35       };
36 
37 //---------------------------------------------------------
38 //   @@ HairpinSegment
39 //---------------------------------------------------------
40 
41 class HairpinSegment final : public TextLineBaseSegment {
42       bool    drawCircledTip;
43       QPointF circledTip;
44       qreal   circledTipRadius;
45 
46       void startEditDrag(EditData&) override;
47       void editDrag(EditData&) override;
48 
49       void draw(QPainter*) const override;
50       Sid getPropertyStyle(Pid) const override;
51 
52       bool acceptDrop(EditData&) const override;
53       Element* drop(EditData&) override;
54 
55    public:
56       HairpinSegment(Spanner* sp, Score* s);
57 
clone()58       HairpinSegment* clone() const override { return new HairpinSegment(*this);    }
type()59       ElementType type() const override      { return ElementType::HAIRPIN_SEGMENT; }
60 
hairpin()61       Hairpin* hairpin() const                       { return (Hairpin*)spanner();          }
62 
63       Element* propertyDelegate(Pid) override;
64 
65       void layout() override;
66       Shape shape() const override;
67 
gripsCount()68       int gripsCount() const override { return 4; }
69       std::vector<QPointF> gripsPositions(const EditData& = EditData()) const override;
70 
71       std::unique_ptr<ElementGroup> getDragGroup(std::function<bool(const Element*)> isDragged) override;
72       };
73 
74 //---------------------------------------------------------
75 //   @@ Hairpin
76 //   @P dynRange     enum (Dynamic.STAFF, Dynamic.PART, Dynamic.SYSTEM)
77 //   @P hairpinType  enum (Hairpin.CRESCENDO, Hairpin.DECRESCENDO)
78 //   @P veloChange   int
79 //---------------------------------------------------------
80 
81 class Hairpin final : public TextLineBase {
82       HairpinType _hairpinType { HairpinType::INVALID };
83       int _veloChange;
84       bool  _hairpinCircledTip;
85       Dynamic::Range _dynRange;
86       bool _singleNoteDynamics;
87       ChangeMethod _veloChangeMethod;
88 
89       Spatium _hairpinHeight;
90       Spatium _hairpinContHeight;
91 
92       Sid getPropertyStyle(Pid) const override;
93 
94    public:
95       Hairpin(Score* s);
96 
clone()97       Hairpin* clone() const override   { return new Hairpin(*this); }
type()98       ElementType type() const override { return ElementType::HAIRPIN;  }
99 
hairpinType()100       HairpinType hairpinType() const           { return _hairpinType; }
101       void setHairpinType(HairpinType val);
102 
segment()103       Segment* segment() const                  { return (Segment*)parent(); }
104       void layout() override;
105       LineSegment* createLineSegment() override;
106 
hairpinCircledTip()107       bool hairpinCircledTip() const            { return _hairpinCircledTip; }
setHairpinCircledTip(bool val)108       void setHairpinCircledTip(bool val)       { _hairpinCircledTip = val; }
109 
veloChange()110       int veloChange() const                    { return _veloChange; }
setVeloChange(int v)111       void setVeloChange(int v)                 { _veloChange = v;    }
112 
dynRange()113       Dynamic::Range dynRange() const           { return _dynRange; }
setDynRange(Dynamic::Range t)114       void setDynRange(Dynamic::Range t)        { _dynRange = t;    }
115 
hairpinHeight()116       Spatium hairpinHeight() const             { return _hairpinHeight; }
setHairpinHeight(Spatium val)117       void setHairpinHeight(Spatium val)        { _hairpinHeight = val; }
118 
hairpinContHeight()119       Spatium hairpinContHeight() const         { return _hairpinContHeight; }
setHairpinContHeight(Spatium val)120       void setHairpinContHeight(Spatium val)    { _hairpinContHeight = val; }
121 
singleNoteDynamics()122       bool singleNoteDynamics() const           { return _singleNoteDynamics; }
setSingleNoteDynamics(bool val)123       void setSingleNoteDynamics(bool val)      { _singleNoteDynamics = val; }
124 
veloChangeMethod()125       ChangeMethod veloChangeMethod() const     { return _veloChangeMethod; }
setVeloChangeMethod(ChangeMethod val)126       void setVeloChangeMethod(ChangeMethod val){ _veloChangeMethod = val; }
127 
isCrescendo()128       bool isCrescendo() const   { return _hairpinType == HairpinType::CRESC_HAIRPIN || _hairpinType == HairpinType::CRESC_LINE; }
isDecrescendo()129       bool isDecrescendo() const { return _hairpinType == HairpinType::DECRESC_HAIRPIN || _hairpinType == HairpinType::DECRESC_LINE; }
130 
131       void write(XmlWriter&) const override;
132       void read(XmlReader&) override;
133 
134       QVariant getProperty(Pid id) const override;
135       bool setProperty(Pid propertyId, const QVariant&) override;
136       QVariant propertyDefault(Pid id) const override;
137       Pid propertyId(const QStringRef& xmlName) const override;
138 
139       QString accessibleInfo() const override;
isLineType()140       bool isLineType() const  { return _hairpinType == HairpinType::CRESC_LINE || _hairpinType == HairpinType::DECRESC_LINE; }
141       };
142 
143 }     // namespace Ms
144 
145 Q_DECLARE_METATYPE(Ms::HairpinType);
146 
147 #endif
148 
149