-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguitarin.cpp
250 lines (220 loc) · 7.74 KB
/
guitarin.cpp
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
250
/////////////////////////////////////////////////////////////////////////////
// Name: guitarin.cpp
// Purpose: Stores and renders guitar in symbols
// Author: Brad Larsen
// Modified by:
// Created: Dec 16, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "guitarin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Default constants
const wxWord GuitarIn::DEFAULT_SYSTEM = 0;
const wxByte GuitarIn::DEFAULT_STAFF = 0;
const wxByte GuitarIn::DEFAULT_POSITION = 0;
const wxWord GuitarIn::DEFAULT_DATA = 0;
// System Constants
const wxUint32 GuitarIn::MIN_SYSTEM = 0;
const wxUint32 GuitarIn::MAX_SYSTEM = 65535;
// Staff Constants
const wxUint32 GuitarIn::MIN_STAFF = 0;
const wxUint32 GuitarIn::MAX_STAFF = 2;
// Position Constants
const wxUint32 GuitarIn::MIN_POSITION = 0;
const wxUint32 GuitarIn::MAX_POSITION = 255;
/// Default Constructor
GuitarIn::GuitarIn() :
m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 25, 2005
}
/// Primary Constructor
/// @param system Zero-based index of the system where the guitar in is anchored
/// @param staff Zero-based inded of the staff within the system where the
/// guitar in is anchored
/// @param position Zero-based index of the position within the system where the
/// guitar in is anchored
/// @param staffGuitars A bit map representing the guitars to set on the staff
/// (bit 1 = guitar 0, bit 2 = guitar 1, etc.)
/// @param rhythmSlashGuitars A bit map representing the guitars to set for the
/// rhythm slashes (bit 1 = guitar 0, bit 2 = guitar 1, etc.)
GuitarIn::GuitarIn(wxUint32 system, wxUint32 staff, wxUint32 position,
wxByte staffGuitars, wxByte rhythmSlashGuitars) :
m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 25, 2005
wxASSERT(IsValidSystem(system));
wxASSERT(IsValidStaff(staff));
wxASSERT(IsValidPosition(position));
SetSystem(system);
SetStaff(staff);
SetPosition(position);
SetStaffGuitars(staffGuitars);
SetRhythmSlashGuitars(rhythmSlashGuitars);
}
/// Copy Constructor
GuitarIn::GuitarIn(const GuitarIn& guitarIn) :
m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Dec 16, 2004
*this = guitarIn;
}
/// Destructor
GuitarIn::~GuitarIn()
{
//------Last Checked------//
// - Dec 16, 2004
}
/// Assignment Operator
const GuitarIn& GuitarIn::operator=(const GuitarIn& guitarIn)
{
//------Last Checked------//
// - Jan 25, 2005
// Check for assignment to self
if (this != &guitarIn)
{
m_system = guitarIn.m_system;
m_staff = guitarIn.m_staff;
m_position = guitarIn.m_position;
m_data = guitarIn.m_data;
}
return (*this);
}
/// Equality Operator
bool GuitarIn::operator==(const GuitarIn& guitarIn) const
{
//------Last Checked------//
// - Jan 25, 2005
return (
(m_system == guitarIn.m_system) &&
(m_staff == guitarIn.m_staff) &&
(m_position == guitarIn.m_position) &&
(m_data == guitarIn.m_data)
);
}
/// Inequality Operator
bool GuitarIn::operator!=(const GuitarIn& guitarIn) const
{
//------Last Checked------//
// - Jan 5, 2005
return (!operator==(guitarIn));
}
// Serialize Functions
/// Performs serialization for the class
/// @param stream Power Tab output stream to serialize to
/// @return True if the object was serialized, false if not
bool GuitarIn::DoSerialize(PowerTabOutputStream& stream)
{
//------Last Checked------//
// - Jan 25, 2005
stream << m_system << m_staff << m_position << m_data;
wxCHECK(stream.CheckState(), false);
return (stream.CheckState());
}
/// Performs deserialization for the class
/// @param stream Power Tab input stream to load from
/// @param version File version
/// @return True if the object was deserialized, false if not
bool GuitarIn::DoDeserialize(PowerTabInputStream& stream,
wxWord WXUNUSED(version))
{
//------Last Checked------//
// - Apr 22, 2007
stream >> m_system >> m_staff >> m_position >> m_data;
wxCHECK(stream.CheckState(), false);
return (stream.CheckState());
}
// Guitars Functions
/// Sets the guitars
/// @param rhythmSlashes True to set the rhythm slash guitars, false to set the
/// staff guitars
/// @param guitars A bit map representing the guitars to set (bit 1 = guitar 0,
/// bit 2 = guitar 1, etc.)
/// @return True if the guitars was set, false if not
bool GuitarIn::SetGuitars(bool rhythmSlashes, wxByte guitars)
{
//------Last Checked------//
// - Jan 25, 2005
if (rhythmSlashes)
m_data = MAKEWORD(guitars, GetStaffGuitars());
else
m_data = MAKEWORD(GetRhythmSlashGuitars(), guitars);
return (true);
}
/// Gets the guitars
/// @param rhythmSlashes True to get the rhythm slash guitars, false to get the
/// staff guitars
/// @return A bit map representing the guitars (bit map where bit 1 = guitar 0,
/// bit 2 = guitar 1, etc.)
wxByte GuitarIn::GetGuitars(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 25, 2005
if (rhythmSlashes)
return (LOBYTE(m_data));
return (HIBYTE(m_data));
}
/// Determines if the guitars is set
/// @param rhythmSlashes True to test if the rhythm slash guitars are set, false
/// to test if the staff guitars are set
/// @return True if the guitars is set, false if not
bool GuitarIn::HasGuitarsSet(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 25, 2005
wxByte guitars = ((rhythmSlashes) ? GetRhythmSlashGuitars() :
GetStaffGuitars());
return (guitars != 0);
}
// Operations
/// Returns a text representation of the guitar in (i.e. Gtr I, II)
/// @param rhythmSlashes If true, gets the rhythm slash guitars text, otherwise
/// the staff guitars text
/// @return A text representation of the guitars
wxString GuitarIn::GetText(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 25, 2005
wxByte guitars = GetGuitars(rhythmSlashes);
if (guitars == 0)
return wxT("");
wxString returnValue;
wxString romanNumerals;
// Loop through, add guitars as we go - there are only 7 guitars
wxByte mask = 1;
wxUint32 guitarCount = 0;
wxUint32 guitarNumber = 1;
for (;; mask *= 2, guitarNumber++)
{
// Guitar is set
if ((guitars & mask) == mask)
{
// Add a comma if we already have a numeral
if (!romanNumerals.IsEmpty())
romanNumerals += wxT(", ");
// Add the roman numeral
romanNumerals += wxArabicToRoman(guitarNumber, true);
guitarCount++;
}
// block overflow
if (mask == 64)
break;
}
// Add the symbol Gtr before
if (guitarCount == 1)
returnValue = wxString::Format(_T("Gtr %s"), romanNumerals.c_str());
else
returnValue = wxString::Format(_T("Gtrs %s"), romanNumerals.c_str());
return (returnValue);
}