-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdynamic.cpp
248 lines (219 loc) · 7.71 KB
/
dynamic.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
/////////////////////////////////////////////////////////////////////////////
// Name: dynamic.cpp
// Purpose: Stores and renders a dynamic
// Author: Brad Larsen
// Modified by:
// Created: Jan 13, 2005
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "dynamic.h"
#include "powertabfileheader.h" // Needed for file version constants
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Default constants
const wxWord Dynamic::DEFAULT_SYSTEM = 0;
const wxByte Dynamic::DEFAULT_STAFF = 0;
const wxByte Dynamic::DEFAULT_POSITION = 0;
const wxWord Dynamic::DEFAULT_DATA = MAKEWORD(DEFAULT_RHYTHM_SLASH_VOLUME, DEFAULT_STAFF_VOLUME);
const wxByte Dynamic::DEFAULT_STAFF_VOLUME = Dynamic::fff;
const wxByte Dynamic::DEFAULT_RHYTHM_SLASH_VOLUME = 0;
// System Constants
const wxUint32 Dynamic::MIN_SYSTEM = 0;
const wxUint32 Dynamic::MAX_SYSTEM = 65535;
// Staff Constants
const wxUint32 Dynamic::MIN_STAFF = 0;
const wxUint32 Dynamic::MAX_STAFF = 2;
// Position Constants
const wxUint32 Dynamic::MIN_POSITION = 0;
const wxUint32 Dynamic::MAX_POSITION = 255;
// Constructor/Destructor
/// Default Constructor
Dynamic::Dynamic() :
m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 12, 2005
}
/// Primary Constructor
/// @param system Zero-based index of the system where the dynamic is anchored
/// @param staff Zero-based index of the staff where the dynamic is anchored
/// @param position Zero-based index of the position within the system where the
/// dynamic is anchored
/// @param staffVolume Staff volume to set (see volumeLevels enum)
/// @param rhythmSlashVolume Rhythm slash volume to set (see volumeLevels enum)
Dynamic::Dynamic(wxUint32 system, wxUint32 staff, wxUint32 position,
wxByte staffVolume, wxByte rhythmSlashVolume) : m_system(DEFAULT_SYSTEM),
m_staff(DEFAULT_STAFF), m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 12, 2005
wxASSERT(IsValidSystem(system));
wxASSERT(IsValidStaff(staff));
wxASSERT(IsValidPosition(position));
SetSystem(system);
SetStaff(staff);
SetPosition(position);
SetStaffVolume(staffVolume);
SetRhythmSlashVolume(rhythmSlashVolume);
}
/// Copy Constructor
Dynamic::Dynamic(const Dynamic& dynamic) :
m_system(DEFAULT_SYSTEM), m_staff(DEFAULT_STAFF),
m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 12, 2005
*this = dynamic;
}
/// Destructor
Dynamic::~Dynamic()
{
//------Last Checked------//
// - Jan 12, 2005
}
/// Assignment Operator
const Dynamic& Dynamic::operator=(const Dynamic& dynamic)
{
//------Last Checked------//
// - Jan 12, 2005
// Check for assignment to self
if (this != &dynamic)
{
m_system = dynamic.m_system;
m_staff = dynamic.m_staff;
m_position = dynamic.m_position;
m_data = dynamic.m_data;
}
return (*this);
}
/// Equality Operator
bool Dynamic::operator==(const Dynamic& dynamic) const
{
//------Last Checked------//
// - Jan 12, 2005
return (
(m_system == dynamic.m_system) &&
(m_staff == dynamic.m_staff) &&
(m_position == dynamic.m_position) &&
(m_data == dynamic.m_data)
);
}
/// Inequality Operator
bool Dynamic::operator!=(const Dynamic& dynamic) const
{
//------Last Checked------//
// - Jan 12, 2005
return (!operator==(dynamic));
}
/// 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 Dynamic::DoSerialize(PowerTabOutputStream& stream)
{
//------Last Checked------//
// - Jan 12, 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 Dynamic::DoDeserialize(PowerTabInputStream& stream, wxWord version)
{
//------Last Checked------//
// - Jan 12, 2005
// Version 1.0 and 1.0.2 (only staff volume was stored)
if (version == PowerTabFileHeader::FILEVERSION_1_0 ||
version == PowerTabFileHeader::FILEVERSION_1_0_2)
{
wxByte staffVolume;
stream >> m_system >> m_staff >> m_position >> staffVolume;
wxCHECK(stream.CheckState(), false);
m_data = MAKEWORD(notSet, staffVolume);
}
// Latest version
else
{
stream >> m_system >> m_staff >> m_position >> m_data;
wxCHECK(stream.CheckState(), false);
}
return (stream.CheckState());
}
// Volume Functions
/// Sets the volume
/// @param rhythmSlashes True to set the rhythm slash volume, false to set the
/// staff volume
/// @param volume Volume to set
/// @return True if the volume was set, false if not
bool Dynamic::SetVolume(bool rhythmSlashes, wxByte volume)
{
//------Last Checked------//
// - Jan 12, 2005
wxCHECK(IsValidVolume(volume), false);
if (rhythmSlashes)
m_data = MAKEWORD(volume, GetStaffVolume());
else
m_data = MAKEWORD(GetRhythmSlashVolume(), volume);
return (true);
}
/// Gets the volume
/// @param rhythmSlashes True to get the rhythm slash volume, false to get the
/// staff volume
/// @return The volume
wxByte Dynamic::GetVolume(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 12, 2005
if (rhythmSlashes)
return (LOBYTE(m_data));
return (HIBYTE(m_data));
}
/// Determines if the volume is set
/// @param rhythmSlashes True to test if the rhythm slash volume is set, false
/// to test if the staff volume is set
/// @return True if the volume is set, false if not
bool Dynamic::IsVolumeSet(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 13, 2005
wxByte volume = ((rhythmSlashes) ? GetRhythmSlashVolume() :
GetStaffVolume());
return (volume != notSet);
}
// Operations
/// Returns a text representation of the dynamic volume level (i.e. mf, ppp,
/// etc.)
/// @param rhythmSlashes If true, gets the rhythm slash volume level text,
/// otherwise the staff volume level text
/// @return A text representation of the volume level
wxString Dynamic::GetText(bool rhythmSlashes) const
{
//------Last Checked------//
// - Jan 13, 2005
// Get the appropriate volume level
wxByte volume = GetVolume(rhythmSlashes);
if (volume == Dynamic::off)
return (wxT("off"));
else if (volume <= Dynamic::ppp)
return (wxT("ppp"));
else if (volume <= Dynamic::pp)
return (wxT("pp"));
else if (volume <= Dynamic::p)
return (wxT("p"));
else if (volume <= Dynamic::mp)
return (wxT("mp"));
else if (volume <= Dynamic::mf)
return (wxT("mf"));
else if (volume <= Dynamic::f)
return (wxT("f"));
else if (volume <= Dynamic::ff)
return (wxT("ff"));
return (wxT("fff"));
}