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 __CLEF_H__ 14 #define __CLEF_H__ 15 16 /** 17 \file 18 Definition of classes Clef 19 */ 20 21 #include "element.h" 22 #include "mscore.h" 23 24 namespace Ms { 25 26 class XmlWriter; 27 class MuseScoreView; 28 class Segment; 29 30 static const int NO_CLEF = -1000; 31 32 33 //--------------------------------------------------------- 34 // ClefType 35 //--------------------------------------------------------- 36 37 enum class ClefType : signed char { 38 INVALID = -1, 39 G = 0, 40 G15_MB, 41 G8_VB, 42 G8_VA, 43 G15_MA, 44 G8_VB_O, 45 G8_VB_P, 46 G_1, 47 C1, 48 C2, 49 C3, 50 C4, 51 C5, 52 C_19C, 53 C1_F18C, 54 C3_F18C, 55 C4_F18C, 56 C3_F20C, 57 C1_F20C, 58 C4_F20C, 59 F, 60 F15_MB, 61 F8_VB, 62 F_8VA, 63 F_15MA, 64 F_B, 65 F_C, 66 F_F18C, 67 F_19C, 68 PERC, 69 PERC2, 70 TAB, 71 TAB4, 72 TAB_SERIF, 73 TAB4_SERIF, 74 MAX 75 }; 76 77 //--------------------------------------------------------- 78 // ClefTypeList 79 //--------------------------------------------------------- 80 81 struct ClefTypeList { 82 ClefType _concertClef = ClefType::G; 83 ClefType _transposingClef = ClefType::G; 84 ClefTypeListClefTypeList85 ClefTypeList() {} ClefTypeListClefTypeList86 ClefTypeList(ClefType a, ClefType b) : _concertClef(a), _transposingClef(b) {} ClefTypeListClefTypeList87 ClefTypeList(ClefType a) : _concertClef(a), _transposingClef(a) {} 88 bool operator==(const ClefTypeList& t) const; 89 bool operator!=(const ClefTypeList& t) const; 90 }; 91 92 //--------------------------------------------------------- 93 // ClefInfo 94 /// Info about a clef. 95 //--------------------------------------------------------- 96 97 class ClefInfo { 98 public: 99 static const ClefInfo clefTable[]; 100 101 const char* _tag; ///< comprehensive name for instruments.xml 102 const char* _sign; ///< Name for musicXml. 103 int _line; ///< Line for musicXml and for positioning on the staff 104 int _octChng; ///< Octave change for musicXml. 105 int _pitchOffset; ///< Pitch offset for line 0. 106 signed char _lines[14]; 107 SymId _symId; 108 const char* _name; 109 StaffGroup _staffGroup; 110 111 public: tag(ClefType t)112 static const char* tag(ClefType t) { return clefTable[int(t)]._tag; } sign(ClefType t)113 static const char* sign(ClefType t) { return clefTable[int(t)]._sign; } line(ClefType t)114 static int line(ClefType t) { return clefTable[int(t)]._line; } octChng(ClefType t)115 static int octChng(ClefType t) { return clefTable[int(t)]._octChng; } pitchOffset(ClefType t)116 static int pitchOffset(ClefType t) { return clefTable[int(t)]._pitchOffset; } symId(ClefType t)117 static SymId symId(ClefType t) { return clefTable[int(t)]._symId; } lines(ClefType t)118 static const signed char* lines(ClefType t) { return clefTable[int(t)]._lines; } name(ClefType t)119 static const char* name(ClefType t) { return clefTable[int(t)]._name; } staffGroup(ClefType t)120 static StaffGroup staffGroup(ClefType t) { return clefTable[int(t)]._staffGroup; } 121 static ClefType tag2type(const QString&); 122 }; 123 124 //--------------------------------------------------------- 125 // @@ Clef 126 /// Graphic representation of a clef. 127 // 128 // @P showCourtesy bool show/hide courtesy clef when applicable 129 // @P small bool small, mid-staff clef (read only, set by layout) 130 //--------------------------------------------------------- 131 132 class Clef final : public Element { 133 SymId symId; 134 bool _showCourtesy = true; 135 bool _small = false; 136 bool _forInstrumentChange = false; 137 138 ClefTypeList _clefTypes { ClefType::INVALID }; 139 140 public: 141 Clef(Score*); clone()142 Clef* clone() const override { return new Clef(*this); } type()143 ElementType type() const override { return ElementType::CLEF; } 144 qreal mag() const override; 145 segment()146 Segment* segment() const { return (Segment*)parent(); } measure()147 Measure* measure() const { return (Measure*)parent()->parent(); } 148 149 bool acceptDrop(EditData&) const override; 150 Element* drop(EditData&) override; 151 void layout() override; 152 void draw(QPainter*) const override; 153 void read(XmlReader&) override; 154 void write(XmlWriter&) const override; 155 isEditable()156 bool isEditable() const override { return false; } 157 small()158 bool small() const { return _small; } 159 void setSmall(bool val); 160 showCourtesy()161 bool showCourtesy() const { return _showCourtesy; } setShowCourtesy(bool v)162 void setShowCourtesy(bool v) { _showCourtesy = v; } 163 void undoSetShowCourtesy(bool v); 164 Clef* otherClef(); 165 166 static ClefType clefType(const QString& s); 167 const char* clefTypeName(); 168 169 ClefType clefType() const; 170 void setClefType(ClefType i); 171 void setClefType(const QString& s); 172 setForInstrumentChange(bool forInstrumentChange)173 void setForInstrumentChange(bool forInstrumentChange) { _forInstrumentChange = forInstrumentChange; } forInstrumentChange()174 bool forInstrumentChange() const { return _forInstrumentChange; } 175 clefTypeList()176 ClefTypeList clefTypeList() const { return _clefTypes; } concertClef()177 ClefType concertClef() const { return _clefTypes._concertClef; } transposingClef()178 ClefType transposingClef() const { return _clefTypes._transposingClef; } 179 void setConcertClef(ClefType val); 180 void setTransposingClef(ClefType val); setClefType(const ClefTypeList & ctl)181 void setClefType(const ClefTypeList& ctl) { _clefTypes = ctl; } 182 void spatiumChanged(qreal oldValue, qreal newValue) override; 183 184 QVariant getProperty(Pid propertyId) const override; 185 bool setProperty(Pid propertyId, const QVariant&) override; 186 QVariant propertyDefault(Pid id) const override; 187 188 Element* nextSegmentElement() override; 189 Element* prevSegmentElement() override; 190 QString accessibleInfo() const override; 191 void clear(); 192 }; 193 194 } // namespace Ms 195 #endif 196 197