Skip to content

Commit

Permalink
Apply new method
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBauer1984 committed Nov 26, 2021
1 parent 265b0f6 commit bc0e88e
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 128 deletions.
4 changes: 2 additions & 2 deletions include/vrv/object.h
Expand Up @@ -232,7 +232,7 @@ class Object : public BoundingBox {
///@{
int GetChildCount() const { return (int)m_children.size(); }
int GetChildCount(const ClassId classId) const;
int GetChildCount(const ClassId classId, int deepth);
int GetChildCount(const ClassId classId, int depth);
///@}

/**
Expand Down Expand Up @@ -348,7 +348,7 @@ class Object : public BoundingBox {
/**
* Look for all Objects of a class and return its position (-1 if not found)
*/
int GetDescendantIndex(const Object *child, const ClassId classId, int deepth);
int GetDescendantIndex(const Object *child, const ClassId classId, int depth);

/**
* Insert an element at the idx position.
Expand Down
4 changes: 1 addition & 3 deletions src/btrem.cpp
Expand Up @@ -96,9 +96,7 @@ int BTrem::GenerateMIDI(FunctorParams *functorParams)
// Apply expansion either to all notes in chord or to first note
Chord *chord = vrv_cast<Chord *>(this->FindDescendantByType(CHORD));
if (chord) {
ListOfObjects notes;
ClassIdComparison noteComparison(NOTE);
chord->FindAllDescendantsByComparison(&notes, &noteComparison);
ListOfObjects notes = chord->FindAllDescendantsByType(NOTE, false);
std::for_each(notes.begin(), notes.end(), expandNote);
}
else {
Expand Down
20 changes: 5 additions & 15 deletions src/doc.cpp
Expand Up @@ -155,9 +155,7 @@ bool Doc::GenerateDocumentScoreDef()
return false;
}

ListOfObjects staves;
ClassIdComparison matchType(STAFF);
measure->FindAllDescendantsByComparison(&staves, &matchType);
ListOfObjects staves = measure->FindAllDescendantsByType(STAFF, false);

if (staves.empty()) {
LogError("No staff found for generating a scoreDef");
Expand Down Expand Up @@ -226,9 +224,7 @@ bool Doc::GenerateHeader()

bool Doc::GenerateMeasureNumbers()
{
ClassIdComparison matchType(MEASURE);
ListOfObjects measures;
this->FindAllDescendantsByComparison(&measures, &matchType);
ListOfObjects measures = this->FindAllDescendantsByType(MEASURE, false);

// run through all measures and generate missing mNum from attribute
for (auto &object : measures) {
Expand Down Expand Up @@ -805,9 +801,7 @@ void Doc::PrepareDrawing()
*/

/************ Add default syl for syllables (if applicable) ************/
ListOfObjects syllables;
ClassIdComparison comp(SYLLABLE);
this->FindAllDescendantsByComparison(&syllables, &comp);
ListOfObjects syllables = this->FindAllDescendantsByType(SYLLABLE);
for (auto it = syllables.begin(); it != syllables.end(); ++it) {
Syllable *syllable = dynamic_cast<Syllable *>(*it);
syllable->MarkupAddSyl();
Expand Down Expand Up @@ -1107,9 +1101,7 @@ void Doc::ConvertToCastOffMensuralDoc(bool castOff)

contentPage->LayOutHorizontally();

ListOfObjects systems;
ClassIdComparison cmp(SYSTEM);
contentPage->FindAllDescendantsByComparison(&systems, &cmp, 1);
ListOfObjects systems = contentPage->FindAllDescendantsByType(SYSTEM, false, 1);
for (const auto item : systems) {
System *system = vrv_cast<System *>(item);
assert(system);
Expand Down Expand Up @@ -1309,9 +1301,7 @@ bool Doc::HasPage(int pageIdx)
std::list<Score *> Doc::GetScores()
{
std::list<Score *> scores;
ListOfObjects objects;
ClassIdComparison cmp(SCORE);
this->FindAllDescendantsByComparison(&objects, &cmp, 3);
ListOfObjects objects = this->FindAllDescendantsByType(SCORE, false, 3);
for (const auto object : objects) {
Score *score = vrv_cast<Score *>(object);
assert(score);
Expand Down
8 changes: 2 additions & 6 deletions src/editortoolkit_cmn.cpp
Expand Up @@ -486,9 +486,7 @@ bool EditorToolkitCMN::InsertNote(Object *object)
Note *note = new Note();
chord->AddChild(note);

ListOfObjects artics;
ClassIdComparison articComparison(ARTIC);
currentNote->FindAllDescendantsByComparison(&artics, &articComparison);
ListOfObjects artics = currentNote->FindAllDescendantsByType(ARTIC);
for (auto &artic : artics) {
artic->MoveItselfTo(chord);
}
Expand Down Expand Up @@ -541,9 +539,7 @@ bool EditorToolkitCMN::DeleteNote(Note *note)
chord->DetachChild(otherNote->GetIdx());
parent->ReplaceChild(chord, otherNote);

ListOfObjects artics;
ClassIdComparison articComparison(ARTIC);
chord->FindAllDescendantsByComparison(&artics, &articComparison, 1);
ListOfObjects artics = chord->FindAllDescendantsByType(ARTIC, false, 1);
for (auto &artic : artics) {
artic->MoveItselfTo(otherNote);
}
Expand Down
16 changes: 4 additions & 12 deletions src/editortoolkit_neume.cpp
Expand Up @@ -592,9 +592,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in

// Find closest valid staff
if (staffId == "auto") {
ListOfObjects staves;
ClassIdComparison ac(STAFF);
m_doc->FindAllDescendantsByComparison(&staves, &ac);
ListOfObjects staves = m_doc->FindAllDescendantsByType(STAFF, false);
std::vector<Object *> stavesVector(staves.begin(), staves.end());

ClosestBB comp;
Expand Down Expand Up @@ -651,9 +649,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
newStaff->AddChild(newLayer);

// Find index to insert new staff
ListOfObjects staves;
ClassIdComparison ac(STAFF);
parent->FindAllDescendantsByComparison(&staves, &ac);
ListOfObjects staves = parent->FindAllDescendantsByType(STAFF, false);
std::vector<Object *> stavesVector(staves.begin(), staves.end());
stavesVector.push_back(newStaff);
StaffSort staffSort;
Expand Down Expand Up @@ -2179,9 +2175,7 @@ bool EditorToolkitNeume::ChangeGroup(std::string elementId, std::string contour)
Nc *prevNc = NULL;

// Get children of neume. Keep the first child and delete the others.
ClassIdComparison ac(NC);
ListOfObjects children;
el->FindAllDescendantsByComparison(&children, &ac);
ListOfObjects children = el->FindAllDescendantsByType(NC);
for (auto it = children.begin(); it != children.end(); ++it) {
if (children.begin() == it) {
firstChild = dynamic_cast<Nc *>(*it);
Expand Down Expand Up @@ -2386,9 +2380,7 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId)
return false;
}

ListOfObjects stavesList;
ClassIdComparison ac(STAFF);
m_doc->FindAllDescendantsByComparison(&stavesList, &ac);
ListOfObjects stavesList = m_doc->FindAllDescendantsByType(STAFF, false);

std::vector<Object *> staves(stavesList.begin(), stavesList.end());

Expand Down
8 changes: 2 additions & 6 deletions src/facsimile.cpp
Expand Up @@ -52,9 +52,7 @@ Zone *Facsimile::FindZoneByUuid(std::string zoneId)

int Facsimile::GetMaxX()
{
ClassIdComparison ac(SURFACE);
ListOfObjects surfaces;
this->FindAllDescendantsByComparison(&surfaces, &ac);
ListOfObjects surfaces = this->FindAllDescendantsByType(SURFACE);

int max = 0;
for (auto iter = surfaces.begin(); iter != surfaces.end(); ++iter) {
Expand All @@ -67,9 +65,7 @@ int Facsimile::GetMaxX()

int Facsimile::GetMaxY()
{
ClassIdComparison ac(SURFACE);
ListOfObjects surfaces;
this->FindAllDescendantsByComparison(&surfaces, &ac);
ListOfObjects surfaces = this->FindAllDescendantsByType(SURFACE);

int max = 0;
for (auto iter = surfaces.begin(); iter != surfaces.end(); ++iter) {
Expand Down
4 changes: 1 addition & 3 deletions src/iomusxml.cpp
Expand Up @@ -267,9 +267,7 @@ void MusicXmlInput::InsertClefToLayer(Staff *staff, Layer *layer, Clef *clef, in
{
// Since AddClef handles #sameas clef only for the future layers, we need to check any previous existing layers for
// the same staff to see if we need to insert #sameas clef to them.
ListOfObjects staffLayers;
ClassIdComparison cmp(LAYER);
staff->FindAllDescendantsByComparison(&staffLayers, &cmp);
ListOfObjects staffLayers = staff->FindAllDescendantsByType(LAYER, false);
for (const auto listLayer : staffLayers) {
Layer *otherLayer = vrv_cast<Layer *>(listLayer);
if (m_layerTimes.find(otherLayer) == m_layerTimes.end()) continue;
Expand Down
4 changes: 1 addition & 3 deletions src/layerelement.cpp
Expand Up @@ -833,9 +833,7 @@ MapOfDotLocs LayerElement::CalcOptimalDotLocations()
// Find the first note on the other layer
Alignment *alignment = this->GetAlignment();
const int currentLayerN = abs(this->GetAlignmentLayerN());
ListOfObjects notes;
ClassIdComparison noteCmp(NOTE);
alignment->FindAllDescendantsByComparison(&notes, &noteCmp, 2);
ListOfObjects notes = alignment->FindAllDescendantsByType(NOTE, false);
auto noteIt = std::find_if(notes.cbegin(), notes.cend(), [currentLayerN](Object *obj) {
const int otherLayerN = abs(vrv_cast<Note *>(obj)->GetAlignmentLayerN());
return (currentLayerN != otherLayerN);
Expand Down
16 changes: 4 additions & 12 deletions src/measure.cpp
Expand Up @@ -371,9 +371,7 @@ std::vector<Staff *> Measure::GetFirstStaffGrpStaves(ScoreDef *scoreDef)
std::vector<int> staffList;

// First get all the staffGrps
ClassIdComparison matchType(STAFFGRP);
ListOfObjects staffGrps;
scoreDef->FindAllDescendantsByComparison(&staffGrps, &matchType);
ListOfObjects staffGrps = scoreDef->FindAllDescendantsByType(STAFFGRP);

// Then the @n of each first staffDef
for (auto &staffGrp : staffGrps) {
Expand All @@ -398,9 +396,7 @@ std::vector<Staff *> Measure::GetFirstStaffGrpStaves(ScoreDef *scoreDef)
Staff *Measure::GetTopVisibleStaff()
{
Staff *staff = NULL;
ListOfObjects staves;
ClassIdComparison matchType(STAFF);
this->FindAllDescendantsByComparison(&staves, &matchType, 1);
ListOfObjects staves = this->FindAllDescendantsByType(STAFF, false);
for (auto &child : staves) {
staff = vrv_cast<Staff *>(child);
assert(staff);
Expand All @@ -415,9 +411,7 @@ Staff *Measure::GetTopVisibleStaff()
Staff *Measure::GetBottomVisibleStaff()
{
Staff *bottomStaff = NULL;
ListOfObjects staves;
ClassIdComparison matchType(STAFF);
this->FindAllDescendantsByComparison(&staves, &matchType, 1);
ListOfObjects staves = this->FindAllDescendantsByType(STAFF, false);
for (const auto child : staves) {
Staff *staff = vrv_cast<Staff *>(child);
assert(staff);
Expand Down Expand Up @@ -625,9 +619,7 @@ void Measure::SetInvisibleStaffBarlines(

std::vector<std::pair<LayerElement *, LayerElement *>> Measure::GetInternalTieEndpoints()
{
ListOfObjects children;
ClassIdComparison comp(TIE);
this->FindAllDescendantsByComparison(&children, &comp);
ListOfObjects children = this->FindAllDescendantsByType(TIE);

std::vector<std::pair<LayerElement *, LayerElement *>> endpoints;
for (Object *object : children) {
Expand Down
4 changes: 1 addition & 3 deletions src/mrest.cpp
Expand Up @@ -96,9 +96,7 @@ int MRest::GetOptimalLayerLocation(Staff *staff, Layer *layer, int defaultLocati
// handle rest positioning for 2 layers. 3 layers and more are much more complex to solve
if (parentStaff->GetChildCount(LAYER) != 2) return defaultLocation;

ListOfObjects layers;
ClassIdComparison matchType(LAYER);
parentStaff->FindAllDescendantsByComparison(&layers, &matchType);
ListOfObjects layers = parentStaff->FindAllDescendantsByType(LAYER, false);
const bool isTopLayer = (vrv_cast<Layer *>(*layers.begin())->GetN() == layer->GetN());

ListOfObjects::iterator otherLayerIter = isTopLayer ? std::prev(layers.end()) : layers.begin();
Expand Down
12 changes: 3 additions & 9 deletions src/neume.cpp
Expand Up @@ -90,9 +90,7 @@ bool Neume::IsLastInNeume(LayerElement *element)

NeumeGroup Neume::GetNeumeGroup()
{
ListOfObjects children;
ClassIdComparison ac(NC);
this->FindAllDescendantsByComparison(&children, &ac);
ListOfObjects children = this->FindAllDescendantsByType(NC);

auto iter = children.begin();
Nc *previous = dynamic_cast<Nc *>(*iter);
Expand Down Expand Up @@ -129,9 +127,7 @@ NeumeGroup Neume::GetNeumeGroup()
std::vector<int> Neume::GetPitchDifferences()
{
std::vector<int> pitchDifferences;
ListOfObjects ncChildren;
ClassIdComparison ac(NC);
this->FindAllDescendantsByComparison(&ncChildren, &ac);
ListOfObjects ncChildren = this->FindAllDescendantsByType(NC);

pitchDifferences.reserve(ncChildren.size() - 1);

Expand All @@ -152,9 +148,7 @@ std::vector<int> Neume::GetPitchDifferences()

bool Neume::GenerateChildMelodic()
{
ListOfObjects children;
ClassIdComparison ac(NC);
this->FindAllDescendantsByComparison(&children, &ac);
ListOfObjects children = this->FindAllDescendantsByType(NC);

// Get the first neume component of the neume
auto iter = children.begin();
Expand Down
16 changes: 5 additions & 11 deletions src/object.cpp
Expand Up @@ -361,11 +361,9 @@ int Object::GetChildCount(const ClassId classId) const
return (int)count_if(m_children.begin(), m_children.end(), ObjectComparison(classId));
}

int Object::GetChildCount(const ClassId classId, int deepth)
int Object::GetChildCount(const ClassId classId, int depth)
{
ListOfObjects objects;
ClassIdComparison matchClassId(classId);
this->FindAllDescendantsByComparison(&objects, &matchClassId);
ListOfObjects objects = this->FindAllDescendantsByType(classId, true, depth);
return (int)objects.size();
}

Expand Down Expand Up @@ -605,9 +603,7 @@ Object *Object::GetChild(int idx) const

Object *Object::GetChild(int idx, const ClassId classId)
{
ListOfObjects objects;
ClassIdComparison matchClassId(classId);
this->FindAllDescendantsByComparison(&objects, &matchClassId, 1);
ListOfObjects objects = this->FindAllDescendantsByType(classId, true, 1);
if ((idx < 0) || (idx >= (int)objects.size())) {
return NULL;
}
Expand Down Expand Up @@ -717,11 +713,9 @@ int Object::GetChildIndex(const Object *child)
return -1;
}

int Object::GetDescendantIndex(const Object *child, const ClassId classId, int deepth)
int Object::GetDescendantIndex(const Object *child, const ClassId classId, int depth)
{
ListOfObjects objects;
ClassIdComparison matchClassId(classId);
this->FindAllDescendantsByComparison(&objects, &matchClassId);
ListOfObjects objects = this->FindAllDescendantsByType(classId, true, depth);
int i = 0;
for (auto &object : objects) {
if (child == object) return i;
Expand Down
12 changes: 3 additions & 9 deletions src/rest.cpp
Expand Up @@ -273,9 +273,7 @@ int Rest::GetOptimalLayerLocation(Staff *staff, Layer *layer, int defaultLocatio

// find best rest location relative to elements on other layers
Staff *realStaff = m_crossStaff ? m_crossStaff : staff;
ListOfObjects layers;
ClassIdComparison matchType(LAYER);
realStaff->FindAllDescendantsByComparison(&layers, &matchType);
ListOfObjects layers = realStaff->FindAllDescendantsByType(LAYER, false);
const auto otherLayerRelativeLocationInfo = GetLocationRelativeToOtherLayers(layers, layer, isTopLayer);
int currentLayerRelativeLocation = GetLocationRelativeToCurrentLayer(staff, layer, isTopLayer);
int otherLayerRelativeLocation = otherLayerRelativeLocationInfo.first
Expand Down Expand Up @@ -425,9 +423,7 @@ int Rest::GetFirstRelativeElementLocation(Staff *currentStaff, Layer *currentLay
if (!previousStaff) return VRV_UNSET;

// Compare number of layers in the next/previous staff and if it's the same - find layer with same N
ListOfObjects layers;
ClassIdComparison matchType(LAYER);
previousStaff->FindAllDescendantsByComparison(&layers, &matchType);
ListOfObjects layers = previousStaff->FindAllDescendantsByType(LAYER, false);
auto layerIter = std::find_if(layers.begin(), layers.end(),
[&](Object *foundLayer) { return vrv_cast<Layer *>(foundLayer)->GetN() == currentLayer->GetN(); });
if (((int)layers.size() != currentStaff->GetChildCount(LAYER)) || (layerIter == layers.end())) return VRV_UNSET;
Expand Down Expand Up @@ -681,9 +677,7 @@ int Rest::Transpose(FunctorParams *functorParams)
Layer *parentLayer = vrv_cast<Layer *>(GetFirstAncestor(LAYER));
assert(parentLayer);

ListOfObjects objects;
ClassIdComparison matchClassId(LAYER);
parentStaff->FindAllDescendantsByComparison(&objects, &matchClassId);
ListOfObjects objects = parentStaff->FindAllDescendantsByType(LAYER, false);
const int layerCount = (int)objects.size();

Layer *firstLayer = vrv_cast<Layer *>(objects.front());
Expand Down
4 changes: 1 addition & 3 deletions src/score.cpp
Expand Up @@ -143,9 +143,7 @@ bool Score::ScoreDefNeedsOptimization(int optionCondense)
bool optimize = (m_scoreDef.HasOptimize() && m_scoreDef.GetOptimize() == BOOLEAN_true);
// if nothing specified, do not if there is only one grpSym
if ((optionCondense == CONDENSE_auto) && !m_scoreDef.HasOptimize()) {
ListOfObjects symbols;
ClassIdComparison matchClassId(GRPSYM);
m_scoreDef.FindAllDescendantsByComparison(&symbols, &matchClassId);
ListOfObjects symbols = m_scoreDef.FindAllDescendantsByType(GRPSYM);
optimize = (symbols.size() > 1);
}

Expand Down
4 changes: 1 addition & 3 deletions src/scoredef.cpp
Expand Up @@ -432,9 +432,7 @@ StaffDef *ScoreDef::GetStaffDef(int n)
StaffGrp *ScoreDef::GetStaffGrp(const std::string &n)
{
// First get all the staffGrps
ClassIdComparison matchType(STAFFGRP);
ListOfObjects staffGrps;
this->FindAllDescendantsByComparison(&staffGrps, &matchType);
ListOfObjects staffGrps = this->FindAllDescendantsByType(STAFFGRP);

// Then the @n of each first staffDef
for (auto &item : staffGrps) {
Expand Down
9 changes: 2 additions & 7 deletions src/staff.cpp
Expand Up @@ -475,9 +475,7 @@ int Staff::ScoreDefOptimize(FunctorParams *functorParams)
matchTypeLayer.ReverseComparison();
this->FindAllDescendantsByComparison(&layers, &matchTypeLayer);

ListOfObjects mRests;
ClassIdComparison matchTypeMRest(MREST);
this->FindAllDescendantsByComparison(&mRests, &matchTypeMRest);
ListOfObjects mRests = this->FindAllDescendantsByType(MREST);

// Show the staff only if no layer with content or only mRests
if (layers.empty() || (mRests.size() != layers.size())) {
Expand Down Expand Up @@ -649,10 +647,7 @@ int Staff::CalcOnsetOffset(FunctorParams *functorParams)

int Staff::CalcStem(FunctorParams *)
{
ClassIdComparison isLayer(LAYER);
ListOfObjects layers;
this->FindAllDescendantsByComparison(&layers, &isLayer);

ListOfObjects layers = this->FindAllDescendantsByType(LAYER, false);
if (layers.empty()) {
return FUNCTOR_CONTINUE;
}
Expand Down

0 comments on commit bc0e88e

Please sign in to comment.