8 #ifndef __VRV_COMPARISON_H__
9 #define __VRV_COMPARISON_H__
12 #include "atts_shared.h"
13 #include "durationinterface.h"
14 #include "horizontalaligner.h"
15 #include "lyricelement.h"
22 #include "timeinterface.h"
26 enum DurExtreme { LONGEST = 0, SHORTEST };
35 virtual bool operator()(
const Object *
object) = 0;
37 bool Result(
bool comparison) {
return (m_reverse) ? !comparison : comparison; }
40 void ReverseComparison()
42 assert(m_supportReverse);
48 bool m_supportReverse =
false;
52 bool m_reverse =
false;
65 m_supportReverse =
true;
68 bool operator()(
const Object *
object)
override {
return Result(this->MatchesType(
object)); }
70 ClassId GetType() {
return m_classId; }
72 bool MatchesType(
const Object *
object) {
return (object->Is(m_classId)); }
87 m_classIds = classIds;
88 m_supportReverse =
true;
91 bool operator()(
const Object *
object)
override {
return Result(this->MatchesType(
object)); }
93 bool MatchesType(
const Object *
object) {
return (object->IsAnyOf(m_classIds)); }
96 std::vector<ClassId> m_classIds;
108 bool operator()(
const Object *
object)
override
110 if (object->HasInterface(m_interfaceId)) {
117 InterfaceId m_interfaceId;
129 bool operator()(
const Object *
object)
override
147 m_pointingTo = pointingTo;
150 bool operator()(
const Object *
object)
override
152 if (!MatchesType(
object))
return false;
154 if (!interface)
return false;
155 return (interface->GetStart() == m_pointingTo);
159 const Object *m_pointingTo;
171 m_pointingTo = pointingTo;
174 bool operator()(
const Object *
object)
override
176 if (!MatchesType(
object))
return false;
178 if (!interface)
return false;
179 return (interface->GetEnd() == m_pointingTo);
183 const Object *m_pointingTo;
198 bool operator()(
const Object *
object)
override
200 if (object->IsEditorialElement())
return Result(
true);
201 return Result(
false);
217 bool operator()(
const Object *
object)
override
219 if (!MatchesType(
object))
return false;
220 if (object->GetChildCount() == 0) {
224 return Result(
false);
241 bool operator()(
const Object *
object)
override
243 if (!MatchesType(
object))
return false;
244 if (object->IsAttribute())
return true;
261 void SetN(
int n) { m_n = n; }
263 bool operator()(
const Object *
object)
override
265 if (!MatchesType(
object))
return false;
267 if (!object->HasAttClass(ATT_NINTEGER))
return false;
268 const AttNInteger *element =
dynamic_cast<const AttNInteger *
>(object);
270 return (element->GetN() == m_n);
289 void SetNs(std::vector<int> ns) { m_ns = ns; }
290 void AppendN(
int n) { m_ns.push_back(n); }
292 bool operator()(
const Object *
object)
override
294 if (!MatchesType(
object))
return false;
296 if (!object->HasAttClass(ATT_NINTEGER))
return false;
297 const AttNInteger *element =
dynamic_cast<const AttNInteger *
>(object);
299 return (std::find(m_ns.begin(), m_ns.end(), element->GetN()) != m_ns.end());
303 std::vector<int> m_ns;
315 assert(Object::IsLyricElement(classId));
318 bool operator()(
const Object *
object)
override
320 if (!this->MatchesType(
object))
return false;
321 const LyricElement *lyricElement = vrv_cast<const LyricElement *>(
object);
322 assert(lyricElement);
342 void SetN(std::string n) { m_n = n; }
344 bool operator()(
const Object *
object)
override
346 if (!MatchesType(
object))
return false;
348 if (!object->HasAttClass(ATT_NNUMBERLIKE))
return false;
349 const AttNNumberLike *element =
dynamic_cast<const AttNNumberLike *
>(object);
351 return (element->GetN() == m_n);
372 m_extremeType = extremeType;
373 m_extremeDur = (m_extremeType == LONGEST) ? -VRV_UNSET : VRV_UNSET;
376 bool operator()(
const Object *
object)
override
378 if (!object->HasInterface(INTERFACE_DURATION))
return false;
381 if (interface->HasDur()) {
382 if ((m_extremeType == LONGEST) && (interface->GetActualDur() < m_extremeDur)) {
383 m_extremeDur = interface->GetActualDur();
386 else if ((m_extremeType == SHORTEST) && (interface->GetActualDur() > m_extremeDur)) {
387 m_extremeDur = interface->GetActualDur();
396 DurExtreme m_extremeType;
410 m_isVisible = isVisible;
413 bool operator()(
const Object *
object)
override
415 if (!MatchesType(
object))
return false;
416 if (!object->HasAttClass(ATT_VISIBILITY))
return false;
417 const AttVisibility *visibility =
dynamic_cast<const AttVisibility *
>(object);
419 return (visibility->GetVisible() == m_isVisible);
423 data_BOOLEAN m_isVisible;
438 bool operator()(
const Object *
object)
override
440 if (!MatchesType(
object))
return false;
442 if (!object->HasAttClass(ATT_FORMEWORK))
return false;
443 const AttFormework *element =
dynamic_cast<const AttFormework *
>(object);
445 return (element->GetFunc() == m_func);
463 bool operator()(
const Object *
object)
override
465 if (!this->MatchesType(
object))
return false;
484 void SetType(AlignmentType type) { m_type = type; }
486 bool operator()(
const Object *
object)
override
488 if (!MatchesType(
object))
return false;
489 const Alignment *alignment = vrv_cast<const Alignment *>(
object);
491 return (alignment->GetType() == m_type);
495 AlignmentType m_type;
510 void SetTime(
int time) { m_time = time; }
512 bool operator()(
const Object *
object)
override
514 if (!MatchesType(
object))
return false;
515 const Measure *measure = vrv_cast<const Measure *>(
object);
536 void SetTime(
int time) { m_time = time; }
538 bool operator()(
const Object *
object)
override
540 if (!MatchesType(
object))
return false;
543 return ((m_time >= interface->GetRealTimeOnsetMilliseconds())
544 && (m_time <= interface->GetRealTimeOffsetMilliseconds()));
563 void SetID(
const std::string &
id) { m_id = id; }
565 bool operator()(
const Object *
object)
override
567 if (!MatchesType(
object))
return false;
568 return (object->GetID() == m_id);
587 void Skip(
const Object *objectToExclude) { m_objectToExclude = objectToExclude; }
589 bool operator()(
const Object *
object)
override
591 if (
object == m_objectToExclude || !ClassIdsComparison::operator()(
object))
return false;
593 if (object->Is(STAFFDEF)) {
594 const StaffDef *staffDef = vrv_cast<const StaffDef *>(
object);
595 return staffDef && staffDef->GetDrawingVisibility() != OPTIMIZATION_HIDDEN;
598 const StaffGrp *staffGrp = vrv_cast<const StaffGrp *>(
object);
599 return staffGrp && staffGrp->GetDrawingVisibility() != OPTIMIZATION_HIDDEN;
603 const Object *m_objectToExclude;
615 enum class Type { AllOf, AnyOf };
619 explicit Filters(
const std::initializer_list<Comparison *> &comp)
621 std::copy(comp.begin(), comp.end(), std::back_inserter(m_filters));
625 void Clear() { m_filters.clear(); }
626 void SetType(Type type) { m_type = type; }
636 if (cmp)
return (cmp->GetType() !=
object->GetClassId()) ?
true : (*iter)(object);
637 return (*iter)(object);
641 return std::any_of(m_filters.cbegin(), m_filters.cend(), condition);
645 return std::all_of(m_filters.cbegin(), m_filters.cend(), condition);
650 Filters &operator=(
const std::initializer_list<Comparison *> &other)
653 std::copy(other.begin(), other.end(), std::back_inserter(m_filters));
658 std::vector<Comparison *> m_filters;
659 Type m_type = Type::AllOf;
This class stores an alignment position elements will point to.
Definition: horizontalaligner.h:77
This class stores a references of LayerElements for a staff.
Definition: horizontalaligner.h:294
bool HasCrossStaffElements() const
Return true if the reference has elements from cross-staff.
This class evaluates if the object the extreme duration so far The object has to have a DurationInter...
Definition: comparison.h:367
This class evaluates if the object is of a certain ClassId and has a of value n.
Definition: comparison.h:284
This class evaluates if the object is of a certain ClassId and has a of value n.
Definition: comparison.h:256
This class evaluates if the object is of a certain ClassId and has a of value n.
Definition: comparison.h:337
This class evaluates if the object is visible.
Definition: comparison.h:405
Definition: comparison.h:124
Definition: comparison.h:59
Definition: comparison.h:82
Definition: comparison.h:32
This class evaluates if alignment reference contains cross-staff elements.
Definition: comparison.h:459
This class is an interface for elements with duration, such as notes and rests.
Definition: durationinterface.h:39
This class is used to store comparison filters and apply them when necessary.
Definition: comparison.h:613
bool Apply(const Object *object) const
Apply comparison filter based on the specified type.
Definition: comparison.h:631
This class evaluates if the object is of a certain ClassId has a certain ID.
Definition: comparison.h:558
Definition: comparison.h:103
This class evaluates if the object is of a certain ClassId and is an attribute in the original MEI.
Definition: comparison.h:236
This class evaluates if the object is an editorial element.
Definition: comparison.h:193
This class evaluates if the object is of a certain ClassId and is empty.
Definition: comparison.h:212
Match a verse or refrain by its internal lyric-processing group.
Definition: comparison.h:311
Shared implementation for note-attached verse and refrain lyrics.
Definition: lyricelement.h:33
int GetDrawingLyricGroupN() const
Stable processing group used to isolate connectors and horizontal spacing.
Definition: lyricelement.h:63
This class evaluates if the object is an Alignment of a certain type.
Definition: comparison.h:479
This class represents a measure in a page-based score (Doc).
Definition: measure.h:46
int EnclosesTime(int time) const
Check if the measure encloses the given time (in millisecond) Return the playing repeat time (1-based...
This class evaluates if the object is a measure enclosing the given time.
Definition: comparison.h:505
This class evaluates if the object is a note being played at the given time.
Definition: comparison.h:531
This class represents a basic object.
Definition: object.h:66
Object * GetParent()
Get the parent of the Object.
Definition: object.h:410
Definition: comparison.h:142
Definition: comparison.h:166
This class represents a MEI staffDef.
Definition: staffdef.h:37
This class represents a MEI staffGrp.
Definition: staffgrp.h:39
This class is an interface for elements having a single time point, such as tempo,...
Definition: timeinterface.h:39
This class is an interface for spanning elements, such as slur, hairpin, etc.
Definition: timeinterface.h:145
This class evaluates if the object is a visible StaffDef or StaffGrp.
Definition: comparison.h:582