forked from RaptDept/ptparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdtimesignature.cpp
131 lines (111 loc) · 3.96 KB
/
oldtimesignature.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
/////////////////////////////////////////////////////////////////////////////
// Name: oldtimesignature.cpp
// Purpose: Used to retrieve time signatures in older file versions
// Author: Brad Larsen
// Modified by:
// Created: Dec 29, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "oldtimesignature.h"
#include "timesignature.h" // Needed for ConstructTimeSignature
#include <math.h> // Needed for pow
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Default Constants
const wxWord OldTimeSignature::DEFAULT_SYSTEM = 0;
const wxByte OldTimeSignature::DEFAULT_POSITION = 0;
const wxUint32 OldTimeSignature::DEFAULT_DATA = 0;
/// Default Constructor
OldTimeSignature::OldTimeSignature() :
m_system(DEFAULT_SYSTEM), m_position(DEFAULT_POSITION), m_data(DEFAULT_DATA)
{
//------Last Checked------//
// - Jan 3, 2005
}
/// Destructor
OldTimeSignature::~OldTimeSignature()
{
//------Last Checked------//
// - Jan 3, 2005
}
// Construction Functions
/// Constructs a TimeSignature object using OldTimeSignature data
/// @param timeSignature TimeSignature object to construct
/// @return True if the object was constructed, false if not
bool OldTimeSignature::ConstructTimeSignature(
TimeSignature& timeSignature) const
{
//------Last Checked------//
// - Jan 3, 2005
wxByte byTemp = HIBYTE(HIWORD(m_data));
wxByte beatsPerMeasure = (wxByte)(((byTemp >> 3) & 0x1f) + 1); // Top 5 bits = bpm, where 0 = 1, 1 = 2, etc.
wxByte beatAmount = (wxByte)pow((double)2, (double)(byTemp & 0x07)); // Bottom 3 bits = ba in power of 2
if (!timeSignature.SetMeter(beatsPerMeasure, beatAmount))
return (false);
if ((m_data & 0x400000) == 0x400000)
timeSignature.SetCommonTime();
else if ((m_data & 0x800000) == 0x800000)
timeSignature.SetCutTime();
// Each beam part is stored in 5 bit segments
wxUint32 beamingPattern =
MAKELONG(
MAKEWORD(m_data & 0x1f, ((m_data & 0x3e0) >> 5)),
MAKEWORD(((m_data & 0x7c00) >> 10), ((m_data & 0xf8000) >> 15))
);
if (!timeSignature.SetBeamingPatternFromwxUint32(beamingPattern))
return (false);
return (true);
}
// Operators
/// Assignment Operator
const OldTimeSignature& OldTimeSignature::operator=(
const OldTimeSignature& oldTimeSignature)
{
//------Last Checked------//
// - Jan 5, 2005
// Check for assignment to self
if (this != &oldTimeSignature)
{
m_system = oldTimeSignature.m_system;
m_position = oldTimeSignature.m_position;
m_data = oldTimeSignature.m_data;
}
return (*this);
}
/// Equality Operator
bool OldTimeSignature::operator==(
const OldTimeSignature& oldTimeSignature) const
{
//------Last Checked------//
// - Jan 5, 2005
return (
(m_system == oldTimeSignature.m_system) &&
(m_position == oldTimeSignature.m_position) &&
(m_data == oldTimeSignature.m_data)
);
}
/// Inequality Operator
bool OldTimeSignature::operator!=(
const OldTimeSignature& oldTimeSignature) const
{
//------Last Checked------//
// - Jan 5, 2005
return (!operator==(oldTimeSignature));
}
/// 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 OldTimeSignature::DoDeserialize(PowerTabInputStream& stream,
wxWord WXUNUSED(version))
{
//------Last Checked------//
// - Apr 22, 2007
stream >> m_system >> m_position >> m_data;
wxCHECK(stream.CheckState(), false);
return (stream.CheckState());
}