MuseScore  3.4
Music composition and notation
accidental.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2004-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 __ACCIDENTAL_H__
14 #define __ACCIDENTAL_H__
15 
21 #include "config.h"
22 #include "element.h"
23 
24 namespace Ms {
25 
26 class Note;
27 enum class SymId;
28 enum class AccidentalVal : signed char;
29 
30 //---------------------------------------------------------
31 // AccidentalRole
32 //---------------------------------------------------------
33 
34 enum class AccidentalRole : char {
35  AUTO, // layout created accidental
36  USER // user created accidental
37  };
38 
39 //---------------------------------------------------------
40 // AccidentalBracket
41 //---------------------------------------------------------
42 
43 enum class AccidentalBracket : char {
44  NONE,
46  BRACKET
47  };
48 
49 //---------------------------------------------------------
50 // SymElement
51 //---------------------------------------------------------
52 
53 struct SymElement {
55  qreal x;
56  SymElement(SymId _sym, qreal _x) : sym(_sym), x(_x) {}
57  };
58 
59 //---------------------------------------------------------
60 // @@ Accidental
61 // @P role enum (Accidental.AUTO, .USER) (read only)
62 // @P small bool
63 //---------------------------------------------------------
64 
65 class Accidental final : public Element {
66  QList<SymElement> el;
67  AccidentalType _accidentalType { AccidentalType::NONE };
68  bool _small { false };
71 
72  public:
73  Accidental(Score* s = 0);
74  virtual Accidental* clone() const override { return new Accidental(*this); }
75  virtual ElementType type() const override { return ElementType::ACCIDENTAL; }
76 
77  QString subtypeUserName() const;
78  void setSubtype(const QString& s);
79  void setAccidentalType(AccidentalType t) { _accidentalType = t; }
80 
81  AccidentalType accidentalType() const { return _accidentalType; }
82  AccidentalRole role() const { return _role; }
83 
84  virtual int subtype() const override { return (int)_accidentalType; }
85  virtual QString subtypeName() const override { return QString(subtype2name(_accidentalType)); }
86 
87  virtual bool acceptDrop(EditData&) const override;
88  virtual Element* drop(EditData&) override;
89  virtual void layout() override;
90  virtual void draw(QPainter*) const override;
91  virtual bool isEditable() const override { return true; }
92  virtual void startEdit(EditData&) override { setGenerated(false); }
93 
94  SymId symbol() const;
95  Note* note() const { return (parent() && parent()->isNote()) ? toNote(parent()) : 0; }
96 
97  AccidentalBracket bracket() const { return _bracket; }
98  void setBracket(AccidentalBracket val) { _bracket = val; }
99 
100  void setRole(AccidentalRole r) { _role = r; }
101 
102  bool small() const { return _small; }
103  void setSmall(bool val) { _small = val; }
104 
105  void undoSetSmall(bool val);
106 
107  virtual void read(XmlReader&) override;
108  virtual void write(XmlWriter& xml) const override;
109 
110  virtual QVariant getProperty(Pid propertyId) const override;
111  virtual bool setProperty(Pid propertyId, const QVariant&) override;
112  virtual QVariant propertyDefault(Pid propertyId) const override;
113  virtual Pid propertyId(const QStringRef& xmlName) const override;
114  virtual QString propertyUserValue(Pid) const override;
115 
116  static AccidentalVal subtype2value(AccidentalType); // return effective pitch offset
117  static SymId subtype2symbol(AccidentalType);
118  static const char* subtype2name(AccidentalType);
119  static AccidentalType value2subtype(AccidentalVal);
120  static AccidentalType name2subtype(const QString&);
121  static bool isMicrotonal(AccidentalType t) { return t > AccidentalType::FLAT2; }
122 
123  QString accessibleInfo() const override;
124  };
125 
127 
128 } // namespace Ms
129 
130 Q_DECLARE_METATYPE(Ms::AccidentalRole);
131 
132 
133 #endif
134 
SymId sym
Definition: accidental.h:54
AccidentalVal
Definition: mscore.h:147
Pid
Definition: property.h:62
AccidentalRole
Definition: accidental.h:34
Definition: xml.h:67
virtual QString subtypeName() const override
Definition: accidental.h:85
SymElement(SymId _sym, qreal _x)
Definition: accidental.h:56
AccidentalRole role() const
Definition: accidental.h:82
void setAccidentalType(AccidentalType t)
Definition: accidental.h:79
AccidentalType
Definition: types.h:152
SymId
Definition: sym.h:30
Base class of score layout elements.
Definition: element.h:158
virtual ElementType type() const override
Definition: accidental.h:75
Definition: accidental.h:65
Definition: score.h:391
void setBracket(AccidentalBracket val)
Definition: accidental.h:98
AccidentalBracket
Definition: accidental.h:43
Note * note() const
Definition: accidental.h:95
AccidentalBracket bracket() const
Definition: accidental.h:97
static bool isMicrotonal(AccidentalType t)
Definition: accidental.h:121
bool small() const
Definition: accidental.h:102
void setRole(AccidentalRole r)
Definition: accidental.h:100
virtual bool isEditable() const override
Definition: accidental.h:91
virtual Accidental * clone() const override
Definition: accidental.h:74
Definition: aeolus.cpp:26
Definition: accidental.h:53
Definition: xml.h:218
void setSmall(bool val)
Definition: accidental.h:103
AccidentalVal sym2accidentalVal(SymId id)
Definition: accidental.cpp:137
Definition: element.h:111
virtual int subtype() const override
Definition: accidental.h:84
Graphic representation of a note.
Definition: note.h:212
ElementType
Definition: types.h:34
AccidentalType accidentalType() const
Definition: accidental.h:81
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
QList< SymElement > el
Definition: accidental.h:66
virtual void startEdit(EditData &) override
Definition: accidental.h:92
qreal x
Definition: accidental.h:55