forked from RaptDept/ptparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowertabobject.cpp
242 lines (216 loc) · 8.1 KB
/
powertabobject.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
/////////////////////////////////////////////////////////////////////////////
// Name: powertabobject.cpp
// Purpose: Provides support for polymorphic reading/writing of Power
// Tab objects
// Author: Brad Larsen
// Modified by:
// Created: Dec 20, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "powertabobject.h"
#include "powertabfileheader.h"
#include "guitar.h"
#include "chorddiagram.h"
#include "floatingtext.h"
#include "guitarin.h"
#include "tempomarker.h"
#include "dynamic.h"
#include "alternateending.h"
#include "system.h"
#include "oldrehearsalsign.h"
#include "oldtimesignature.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Constructor/Destructor
/// Default Constructor
PowerTabObject::PowerTabObject()
{
//------Last Checked------//
// - Dec 21, 2004
}
/// Destructor
PowerTabObject::~PowerTabObject()
{
//------Last Checked------//
// - Dec 21, 2004
}
// Creation Functions
/// Creates a new object based on the class id
/// @param classId Class id for the object to create
/// @return Pointer to object if it was created, NULL if the object couldn't be
/// created
PowerTabObject* PowerTabObject::CreateObject(const wxString& classId)
{
//------Last Checked------//
// - Dec 21, 2004
// TODO: add all classes
PowerTabObject* returnValue = NULL;
if (strcmp(wxT("CGuitar-1"), classId) == 0)
returnValue = new Guitar;
else if (strcmp(wxT("CTuning-1"), classId) == 0)
returnValue = new Tuning;
else if (strcmp(wxT("CChordDiagram-1"), classId) == 0)
returnValue = new ChordDiagram;
else if (strcmp(wxT("CFloatingText-1"), classId) == 0)
returnValue = new FloatingText;
else if (strcmp(wxT("CGuitarIn-1"), classId) == 0)
returnValue = new GuitarIn;
else if (strcmp(wxT("CTempoMarker-1"), classId) == 0)
returnValue = new TempoMarker;
else if (strcmp(wxT("CDynamic-1"), classId) == 0)
returnValue = new Dynamic;
else if (strcmp(wxT("CSectionSymbol-1"), classId) == 0)
returnValue = new AlternateEnding;
else if (strcmp(wxT("CSection-1"), classId) == 0)
returnValue = new System;
else if (strcmp(wxT("CDirection-1"), classId) == 0)
returnValue = new Direction;
else if (strcmp(wxT("CChordText-1"), classId) == 0)
returnValue = new ChordText;
else if (strcmp(wxT("CRhythmSlash-1"), classId) == 0)
returnValue = new RhythmSlash;
else if (strcmp(wxT("CStaff-1"), classId) == 0)
returnValue = new Staff;
else if (strcmp(wxT("CMusicBar-1"), classId) == 0)
returnValue = new Barline;
else if (strcmp(wxT("CPosition-1"), classId) == 0)
returnValue = new Position;
else if (strcmp(wxT("CLineData-1"), classId) == 0)
returnValue = new Note;
else if (strcmp(wxT("CRehearsalSign-old-1"), classId) == 0)
returnValue = new OldRehearsalSign;
else if (strcmp(wxT("CTimeSignature-old-1"), classId) == 0)
returnValue = new OldTimeSignature;
wxASSERT(returnValue != NULL);
return (returnValue);
}
// MFC Class Functions
/// Writes the MFC class information for the object to an output stream
/// @param stream Output stream to write to
/// @return True if the class information was written, false if not
bool PowerTabObject::WriteMFCClassInformation(wxOutputStream& stream) const
{
//------Last Checked------//
// - Dec 24, 2004
PowerTabOutputStream data_stream(stream);
return (WriteMFCClassInformation(data_stream));
}
/// Writes the MFC class information for the object to a Power Tab output stream
/// @param stream Power Tab output stream to write to
/// @return True if the class information was written, false if not
bool PowerTabObject::WriteMFCClassInformation(
PowerTabOutputStream& stream) const
{
//------Last Checked------//
// - Dec 24, 2004
wxString className = GetMFCClassName();
wxWord schema = GetMFCClassSchema();
wxWord classNameLength = (wxWord)className.Length();
// Write the schema and the length of the class name
stream << schema << classNameLength;
wxCHECK(stream.CheckState(), false);
// Write the class name
// Note: all MFC class names are stored as ANSI text
if (!stream.WriteAnsiText(className))
return (false);
return (stream.CheckState());
}
/// Reads the MFC class information for an object from an input stream
/// @param stream Input stream to read from
/// @param version File version
/// @param classId Class id for the object
/// @return True if the object's class information was read, false if not
bool PowerTabObject::ReadMFCClassInformation(wxInputStream& stream,
wxWord version, wxString& classId)
{
//------Last Checked------//
// - Dec 24, 2004
PowerTabInputStream data_stream(stream);
return (ReadMFCClassInformation(data_stream, version, classId));
}
/// Reads the MFC class information for an object from a Power Tab input stream
/// @param stream Power Tab input stream to read from
/// @param version File version
/// @param classId Class id for the object
/// @return True if the object's class information was read, false if not
bool PowerTabObject::ReadMFCClassInformation(PowerTabInputStream& stream,
wxWord version, wxString& classId)
{
//------Last Checked------//
// - Dec 24, 2004
classId.Clear();
// Read the schema
wxWord schema;
stream >> schema;
wxCHECK(stream.CheckState(), false);
// Read the length of the class name
wxWord length;
stream >> length;
wxCHECK(stream.CheckState(), false);
if (length >= MAX_CLASSNAME_LENGTH)
{
stream.m_lastPowerTabError = POWERTABSTREAM_BAD_CLASS;
return (false);
}
if (!stream.ReadAnsiText(length, classId))
{
stream.m_lastPowerTabError = POWERTABSTREAM_BAD_CLASS;
return (false);
}
// Add "old" tag for outdated classes used in v1.0-1.0.2
if (version <= PowerTabFileHeader::FILEVERSION_1_0_2)
{
if ((classId == wxT("CRehearsalSign")) ||
(classId == wxT("CTimeSignature")))
classId += wxT("-old");
}
// Attach the schema to the class id
classId += wxString::Format(wxT("-%d"), schema);
// TODO: Add class validation here?
return (stream.CheckState());
}
// Serialization Functions
/// Saves a Power Tab object to an output stream
/// @param stream Output stream to save to
/// @return True if the object was saved, false if not
bool PowerTabObject::Serialize(wxOutputStream& stream)
{
//------Last Checked------//
// - Dec 21, 2004
PowerTabOutputStream data_stream(stream);
return (Serialize(data_stream));
}
/// Saves a Power Tab object to a Power Tab output stream
/// @param stream Power Tab output stream to save to
/// @return True if the object was saved, false if not
bool PowerTabObject::Serialize(PowerTabOutputStream& stream)
{
//------Last Checked------//
// - Dec 27, 2004
return (DoSerialize(stream));
}
/// Loads a Power Tab object from an input stream
/// @param stream Input stream to load from
/// @param version File version
/// @return True if the object was loaded, false if not
bool PowerTabObject::Deserialize(wxInputStream& stream, wxWord version)
{
//------Last Checked------//
// - Dec 21, 2004
PowerTabInputStream data_stream(stream);
return (Deserialize(data_stream, version));
}
/// Loads a Power Tab object from a Power Tab input stream
/// @param stream Power Tab input stream to load from
/// @param version File version
/// @return True if the object was loaded, false if not
bool PowerTabObject::Deserialize(PowerTabInputStream& stream, wxWord version)
{
//------Last Checked------//
// - Dec 27, 2004
return (DoDeserialize(stream, version));
}