-
Notifications
You must be signed in to change notification settings - Fork 1
/
barline.h
238 lines (215 loc) · 9.95 KB
/
barline.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
/////////////////////////////////////////////////////////////////////////////
// Name: barline.h
// Purpose: Stores and renders barlines
// Author: Brad Larsen
// Modified by:
// Created: Jan 4, 2005
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef __BARLINE_H__
#define __BARLINE_H__
#include "rehearsalsign.h"
#include "timesignature.h"
#include "keysignature.h"
/// Stores and renders barlines
class Barline : public PowerTabObject
{
// Constants
public:
// Default Constants
static const wxByte DEFAULT_POSITION; ///< Default value for the position member variable
static const wxByte DEFAULT_DATA; ///< Default value for the data member variable
// Repeat Count Constants
static const wxByte MIN_REPEAT_COUNT; ///< Minimum allowed value for the repeat count
static const wxByte MAX_REPEAT_COUNT; ///< Maximum allowed value for the repeat count
enum barTypes
{
bar = (wxByte)0,
doubleBar = (wxByte)1,
freeTimeBar = (wxByte)2,
repeatStart = (wxByte)3,
openBar = (wxByte)3,
repeatEnd = (wxByte)4,
doubleBarFine = (wxByte)5
};
enum flags
{
typeMask = (wxByte)0xe0, ///< Mask used to retrieve the type
repeatCountMask = (wxByte)0x1f ///< Mask used to retrieve the repeat count
};
// Member Variables
protected:
wxByte m_position; ///< Zero-based index of the position within the system where the barline is anchored
wxByte m_data; ///< Top 3 bits = type, bottom 5 = repeat number
KeySignature m_keySignature; ///< Key signature
TimeSignature m_timeSignature; ///< Time signature
RehearsalSign m_rehearsalSign; ///< Rehearsal sign
// Constructor/Destructor
public:
Barline();
Barline(wxUint32 position, wxByte type, wxByte repeatCount = 0);
Barline(const Barline& barline);
~Barline();
// Creation Functions
/// Creates an exact duplicate of the object
/// @return The duplicate object
PowerTabObject* CloneObject() const
{return (new Barline(*this));}
// Operators
const Barline& operator=(const Barline& barline);
bool operator==(const Barline& barline) const;
bool operator!=(const Barline& barline) const;
// Serialization Functions
protected:
bool DoSerialize(PowerTabOutputStream& stream);
bool DoDeserialize(PowerTabInputStream& stream, wxWord version);
// MFC Class Functions
public:
/// Gets the MFC Class Name for the object
/// @return The MFC Class Name
wxString GetMFCClassName() const
{return (wxT("CMusicBar"));}
/// Gets the MFC Class Schema for the object
/// @return The MFC Class Schema
wxWord GetMFCClassSchema() const
{return ((wxWord)1);}
// Position Functions
/// Determines whether a position is valid
/// @param position Position to validate
/// @return True if the position is valid, false if not
static bool IsValidPosition(wxUint32 position)
{return ((position >= 0) && (position <= 255));}
/// Sets the position within the system where the barline is anchored
/// @param position Zero-based index within the system where the barline is
/// anchored
/// @return True if the position was set, false if not
bool SetPosition(wxUint32 position)
{
wxCHECK(IsValidPosition(position), false);
m_position = (wxByte)position;
return (true);
}
/// Gets the position within the system where the barline is anchored
/// @return The position within the system where the barline is anchored
wxUint32 GetPosition() const
{return (m_position);}
// Barline Data Functions
bool SetBarlineData(wxByte type, wxByte repeatCount);
void GetBarlineData(wxByte& type, wxByte& repeatCount) const;
// Type Functions
/// Determines if a type is valid
/// @param type Type to validate
/// @return True if the type is valid, false if not
static bool IsValidType(wxByte type)
{return (type <= doubleBarFine);}
bool SetType(wxByte type);
/// Gets the type of barline (see barTypes enum for values)
/// @return The type of barline
wxByte GetType() const
{return ((wxByte)((m_data & typeMask) >> 5));}
/// Determines if the barline type is a standard bar
/// @return True if the barline type is a standard bar, false if not
bool IsBar() const
{return (GetType() == bar);}
/// Determines if the barline type is a double bar
/// @return True if the barline type is a double bar, false if not
bool IsDoubleBar() const
{return (GetType() == doubleBar);}
/// Determines if the barline type is a freetime bar
/// @return True if the barline type is a freetime bar, false if not
bool IsFreeTimeBar() const
{return (GetType() == freeTimeBar);}
/// Determines if the barline type is a repeat start bar
/// @return True if the barline type is a repeat start bar, false if not
bool IsRepeatStart() const
{return (GetType() == repeatStart);}
/// Determines if the barline type is a repeat end bar
/// @return True if the barline type is a repeat end bar, false if not
bool IsRepeatEnd() const
{return (GetType() == repeatEnd);}
/// Determines if the barline type is a double bar (fine) bar
/// @return True if the barline type is a double bar (fine) bar, false if
/// not
bool IsDoubleBarFine() const
{return (GetType() == doubleBarFine);}
// Repeat Count Functions
/// Determines if a repeat count is valid
/// @param repeatCount Repeat count to validate
/// @return True if the repeat count is valid, false if not
static bool IsValidRepeatCount(wxUint32 repeatCount)
{
return (((repeatCount >= MIN_REPEAT_COUNT) &&
(repeatCount <= MAX_REPEAT_COUNT)) || (repeatCount == 0));
}
bool SetRepeatCount(wxUint32 repeatCount);
/// Gets the repeat count (used by repeat end bars)
/// @return The repeat count
wxUint32 GetRepeatCount() const
{return ((wxUint32)(m_data & repeatCountMask));}
// Key Signature Functions
/// Sets the key signature
void SetKeySignature(const KeySignature& keySignature)
{m_keySignature = keySignature;}
/// Gets the key signature
/// @return The key signature
KeySignature GetKeySignature() const
{return (m_keySignature);}
/// Gets a reference to the key signature
/// @return A reference to the key signature
KeySignature& GetKeySignatureRef()
{return (m_keySignature);}
/// Gets a constant reference to the key signature
/// @return A constant reference to the key signature
const KeySignature& GetKeySignatureConstRef() const
{return (m_keySignature);}
/// Gets a pointer to the key signature
/// @return A pointer to the key signature
KeySignature* GetKeySignaturePtr()
{return (&m_keySignature);}
// Time Signature Functions
/// Sets the time signature
void SetTimeSignature(const TimeSignature& timeSignature)
{m_timeSignature = timeSignature;}
/// Gets the time signature
/// @return The time signature
TimeSignature GetTimeSignature() const
{return (m_timeSignature);}
/// Gets a reference to the time signature
/// @return A reference to the time signature
TimeSignature& GetTimeSignatureRef()
{return (m_timeSignature);}
/// Gets a constant reference to the time signature
/// @return A constant reference to the time signature
const TimeSignature& GetTimeSignatureConstRef() const
{return (m_timeSignature);}
/// Gets a pointer to the time signature
/// @return A pointer to the time signature
TimeSignature* GetTimeSignaturePtr()
{return (&m_timeSignature);}
// Rehearsal Sign Functions
/// Sets the rehearsal sign
void SetRehearsalSign(const RehearsalSign& rehearsalSign)
{m_rehearsalSign = rehearsalSign;}
/// Gets the rehearsal sign
/// @return The rehearsal sign
RehearsalSign GetRehearsalSign() const
{return (m_rehearsalSign);}
/// Gets a reference to the rehearsal sign
/// @return A reference to the rehearsal sign
RehearsalSign& GetRehearsalSignRef()
{return (m_rehearsalSign);}
/// Gets a constant reference to the rehearsal sign
/// @return A constant reference to the rehearsal sign
const RehearsalSign& GetRehearsalSignConstRef() const
{return (m_rehearsalSign);}
/// Gets a pointer to the rehearsal sign
/// @return A pointer to the rehearsal sign
RehearsalSign* GetRehearsalSignPtr()
{return (&m_rehearsalSign);}
// Operations
int GetKeyAndTimeSignatureWidth() const;
};
WX_DEFINE_POWERTABARRAY(Barline*, BarlineArray);
#endif