forked from rism-digital/verovio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftrem.cpp
145 lines (117 loc) · 3.65 KB
/
ftrem.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
/////////////////////////////////////////////////////////////////////////////
// Name: ftrem.cpp
// Author: Klaus Rettinghaus
// Created: 2017
// Copyright (c) Authors and others. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
#include "ftrem.h"
//----------------------------------------------------------------------------
#include <cassert>
#include <math.h>
//----------------------------------------------------------------------------
#include "chord.h"
#include "editorial.h"
#include "functor.h"
#include "layer.h"
#include "note.h"
#include "staff.h"
#include "vrv.h"
//----------------------------------------------------------------------------
#include "MidiFile.h"
namespace vrv {
//----------------------------------------------------------------------------
// FTrem
//----------------------------------------------------------------------------
static const ClassRegistrar<FTrem> s_factory("fTrem", FTREM);
FTrem::FTrem() : LayerElement(FTREM, "ftrem-"), BeamDrawingInterface(), AttFTremVis(), AttTremMeasured()
{
this->RegisterAttClass(ATT_FTREMVIS);
this->RegisterAttClass(ATT_TREMMEASURED);
this->Reset();
}
FTrem::~FTrem() {}
void FTrem::Reset()
{
LayerElement::Reset();
BeamDrawingInterface::Reset();
this->ResetFTremVis();
this->ResetTremMeasured();
}
bool FTrem::IsSupportedChild(Object *child)
{
if (child->Is(CHORD)) {
assert(dynamic_cast<Chord *>(child));
}
else if (child->Is(CLEF)) {
assert(dynamic_cast<Clef *>(child));
}
else if (child->Is(NOTE)) {
assert(dynamic_cast<Note *>(child));
}
else if (child->IsEditorialElement()) {
assert(dynamic_cast<EditorialElement *>(child));
}
else {
return false;
}
return true;
}
const ArrayOfBeamElementCoords *FTrem::GetElementCoords()
{
this->GetList();
return &m_beamElementCoords;
}
void FTrem::FilterList(ListOfConstObjects &childList) const
{
ListOfConstObjects::iterator iter = childList.begin();
while (iter != childList.end()) {
if (!(*iter)->Is(NOTE) && !(*iter)->Is(CHORD)) {
// remove anything that is not an LayerElement (e.g. Verse, Syl, etc.)
iter = childList.erase(iter);
continue;
}
// also remove notes within chords
if ((*iter)->Is(NOTE)) {
const Note *note = vrv_cast<const Note *>(*iter);
assert(note);
if (note->IsChordTone()) {
iter = childList.erase(iter);
continue;
}
}
++iter;
}
}
std::pair<int, int> FTrem::GetAdditionalBeamCount() const
{
return { 0, std::max(this->GetBeams(), this->GetBeamsFloat()) };
}
std::pair<int, int> FTrem::GetFloatingBeamCount() const
{
return { this->GetBeams(), this->GetBeamsFloat() };
}
void FTrem::SetElementShortening(int shortening)
{
std::for_each(m_beamSegment.m_beamElementCoordRefs.begin(), m_beamSegment.m_beamElementCoordRefs.end(),
[shortening](BeamElementCoord *coord) { coord->m_maxShortening = shortening; });
}
//----------------------------------------------------------------------------
// Functors methods
//----------------------------------------------------------------------------
FunctorCode FTrem::Accept(Functor &functor)
{
return functor.VisitFTrem(this);
}
FunctorCode FTrem::Accept(ConstFunctor &functor) const
{
return functor.VisitFTrem(this);
}
FunctorCode FTrem::AcceptEnd(Functor &functor)
{
return functor.VisitFTremEnd(this);
}
FunctorCode FTrem::AcceptEnd(ConstFunctor &functor) const
{
return functor.VisitFTremEnd(this);
}
} // namespace vrv