forked from RaptDept/ptparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeysignature.h
249 lines (229 loc) · 12.4 KB
/
keysignature.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/////////////////////////////////////////////////////////////////////////////
// Name: keysignature.h
// Purpose: Stores and renders a key signature
// Author: Brad Larsen
// Modified by:
// Created: Dec 10, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef __KEYSIGNATURE_H__
#define __KEYSIGNATURE_H__
/// Stores and renders a key signature
class KeySignature : public PowerTabObject
{
friend class KeySignatureTestSuite;
// Constants
public:
// Default constants
static const wxByte DEFAULT_DATA; ///< Default value for the data member variable
enum flags
{
keyAccidentalsMask = (wxByte)0x0f, ///< Bit mask used to retrieve the key accidentals value
show = (wxByte)0x10, ///< Key signature is shown
cancellation = (wxByte)0x20, ///< Key signature is a cancellation
keyTypeMask = (wxByte)0x40 ///< Bit mask used to retrieve the key type value
};
enum keyTypes
{
majorKey = (wxByte)0, ///< Key signature is a major key type (i.e. C major)
minorKey = (wxByte)1 ///< Key signature is a minor key type (i.e. A minor)
};
enum keyAccidentals
{
noAccidentals = (wxByte)0, ///< Key signature uses no accidentals
oneSharp = (wxByte)1, ///< Key signature uses 1 sharp
twoSharps = (wxByte)2, ///< Key signature uses 2 sharps
threeSharps = (wxByte)3, ///< Key signature uses 3 sharps
fourSharps = (wxByte)4, ///< Key signature uses 4 sharps
fiveSharps = (wxByte)5, ///< Key signature uses 5 sharps
sixSharps = (wxByte)6, ///< Key signature uses 6 sharps
sevenSharps = (wxByte)7, ///< Key signature uses 7 sharps
oneFlat = (wxByte)8, ///< Key signature uses 1 flat
twoFlats = (wxByte)9, ///< Key signature uses 2 flats
threeFlats = (wxByte)10, ///< Key signature uses 3 flats
fourFlats = (wxByte)11, ///< Key signature uses 4 flats
fiveFlats = (wxByte)12, ///< Key signature uses 5 flats
sixFlats = (wxByte)13, ///< Key signature uses 6 flats
sevenFlats = (wxByte)14 ///< Key signature uses 7 flats
};
// Member Variables
protected:
wxByte m_data; ///< Stores all data required by the key signature (see the flags enum for the meaning of the individual bits)
// Constructor/Destructor
public:
KeySignature();
KeySignature(wxByte keyType, wxByte keyAccidentals);
KeySignature(const KeySignature& keySignature);
~KeySignature();
// Creation Functions
/// Creates an exact duplicate of the object
/// @return The duplicate object
PowerTabObject* CloneObject() const
{return (new KeySignature(*this));}
// Operators
const KeySignature& operator=(const KeySignature& keySignature);
bool operator==(const KeySignature& keySignature) const;
bool operator!=(const KeySignature& keySignature) const;
// MFC Class Functions
/// Gets the MFC Class Name for the object
/// @return The MFC Class Name
wxString GetMFCClassName() const
{return (wxT("CKeySignature"));}
/// Gets the MFC Class Schema for the object
/// @return The MFC Class Schema
wxWord GetMFCClassSchema() const
{return ((wxWord)1);}
// Serialization Functions
protected:
bool DoSerialize(PowerTabOutputStream& stream);
bool DoDeserialize(PowerTabInputStream& stream, wxWord version);
// Key Functions
public:
bool SetKey(wxByte keyType, wxByte keyAccidentals);
void GetKey(wxByte & keyType, wxByte & keyAccidentals) const;
/// Determines if the key (type + accidentals) is the same as that of
/// another KeySignature object
/// @param keySignature KeySignature object to compare with
/// @return True if the key signatures have the same key, false if not
bool IsSameKey(const KeySignature& keySignature) const
{
return ((GetKeyType() == keySignature.GetKeyType()) &&
(GetKeyAccidentals() == keySignature.GetKeyAccidentals()));
}
bool GetDrawKey(wxByte& keyType, wxByte& keyAccidentals) const;
// Type Functions
/// Deteremines if a key type is valid
/// @param keyType The key type to validate
/// @return True if the key type is valid, false if not
static bool IsValidKeyType(wxByte keyType)
{return ((keyType == majorKey) || (keyType == minorKey));}
bool SetKeyType(wxByte keyType);
/// Gets the key type for the key signature (majorKey vs minorKey)
/// @return majorKey (see enum) if the key signature is a majorKey key,
/// minorKey (see enum) if the key signature is a minorKey key
wxByte GetKeyType() const
{return (wxByte)((m_data & keyTypeMask) >> 6);}
/// Determines if the key signature is a majorKey key
/// @return True if the key signature is a majorKey key, false if not
bool IsMajorKey() const
{return (GetKeyType() == majorKey);}
/// Determines if the key signature is a minorKey key
/// @return True if the key signature is a minorKey key, false if not
bool IsMinorKey() const
{return (GetKeyType() == minorKey);}
// Accidentals Functions
/// Determines if a key accidentals value is valid
/// @param keyAccidentals Key accidentals value to validate
/// @return True if the key accidentals value is validate, false if not
static bool IsValidKeyAccidentals(wxByte keyAccidentals)
{return (keyAccidentals <= sevenFlats);}
bool SetKeyAccidentals(wxByte keyAccidentals);
wxByte GetKeyAccidentals() const;
/// Determines if the key signature uses no accidentals
/// @return True if the key signature uses no accidentals, false if not
bool HasNoKeyAccidentals() const
{return (GetKeyAccidentals() == noAccidentals);}
/// Determines if the key signature has one sharp
/// @return True if the key signature has one sharp, false if not
bool HasOneSharp() const
{return (GetKeyAccidentals() == oneSharp);}
/// Determines if the key signature has two sharps
/// @return True if the key signature has two sharps, false if not
bool HasTwoSharps() const
{return (GetKeyAccidentals() == twoSharps);}
/// Determines if the key signature has three sharps
/// @return True if the key signature has three sharps, false if not
bool HasThreeSharps() const
{return (GetKeyAccidentals() == threeSharps);}
/// Determines if the key signature has four sharps
/// @return True if the key signature has four sharps, false if not
bool HasFourSharps() const
{return (GetKeyAccidentals() == fourSharps);}
/// Determines if the key signature has five sharps
/// @return True if the key signature has five sharps, false if not
bool HasFiveSharps() const
{return (GetKeyAccidentals() == fiveSharps);}
/// Determines if the key signature has six sharps
/// @return True if the key signature has six sharps, false if not
bool HasSixSharps() const
{return (GetKeyAccidentals() == sixSharps);}
/// Determines if the key signature has seven sharps
/// @return True if the key signature has seven sharps, false if not
bool HasSevenSharps() const
{return (GetKeyAccidentals() == sevenSharps);}
/// Determines if the key signature has one flat
/// @return True if the key signature has one flat, false if not
bool HasOneFlat() const
{return (GetKeyAccidentals() == oneFlat);}
/// Determines if the key signature has two flats
/// @return True if the key signature has two flats, false if not
bool HasTwoFlats() const
{return (GetKeyAccidentals() == twoFlats);}
/// Determines if the key signature has three flats
/// @return True if the key signature has three flats, false if not
bool HasThreeFlats() const
{return (GetKeyAccidentals() == threeFlats);}
/// Determines if the key signature has four flats
/// @return True if the key signature has four flats, false if not
bool HasFourFlats() const
{return (GetKeyAccidentals() == fourFlats);}
/// Determines if the key signature has five flats
/// @return True if the key signature has five flats, false if not
bool HasFiveFlats() const
{return (GetKeyAccidentals() == fiveFlats);}
/// Determines if the key signature has six flats
/// @return True if the key signature has six flats, false if not
bool HasSixFlats() const
{return (GetKeyAccidentals() == sixFlats);}
/// Determines if the key signature has seven flats
/// @return True if the key signature has seven flats, false if not
bool HasSevenFlats() const
{return (GetKeyAccidentals() == sevenFlats);}
// Show/Hide Functions
/// Makes the key signature visible
void Show()
{SetFlag(show);}
/// Makes the key signature invisible
void Hide()
{ClearFlag(show);}
/// Determines if the key signature is shown
/// @return True if the key signature is shown, false if not
bool IsShown() const
{return (IsFlagSet(show));}
// Cancellation Functions
/// Sets or clears the cancellation on a key signature
/// @param set If true, makes the key signature a cancellation, otherwise
/// clears the cancellation
void SetCancellation(bool set = true)
{if (set) SetFlag(cancellation); else ClearFlag(cancellation);}
/// Determines if the key signature is a cancellation
/// @return True if the key signature is a cancellation, false if not
bool IsCancellation() const
{return (IsFlagSet(cancellation));}
// Operations
wxString GetText() const;
int GetWidth() const;
// Flag Functions
protected:
/// Determines if a flag is valid
/// @param flag Flag to validate
/// @return True if the flag is valid, false if not
static bool IsValidFlag(wxByte flag)
{return ((flag == show) || (flag == cancellation));}
/// Sets a flag used by the KeySignature object
/// @param flag The flag to set
bool SetFlag(wxByte flag)
{wxCHECK(IsValidFlag(flag), false); m_data |= flag; return (true);}
/// Clears a flag used by the KeySignature object
/// @param flag The flag to clear
bool ClearFlag(wxByte flag)
{wxCHECK(IsValidFlag(flag), false); m_data &= ~flag; return (true);}
/// Determines if a flag used by the KeySignature object is set
/// @param flag The flag to test
/// @return True if the flag is set, false if not
bool IsFlagSet(wxByte flag) const
{wxCHECK(IsValidFlag(flag), false); return ((m_data & flag) == flag);}
};
#endif