Skip to content

Commit

Permalink
Prioritise long strings
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsw1111 committed Apr 9, 2023
1 parent 549b9e5 commit c683563
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions xLights/effects/GuitarEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GuitarTiming
_fingerPos.push_back({ string, pos });
}

int GetPositionCentre(int middle)
int GetPositionCentre(int middle) const
{
int zeroCount = 0;
int total = 0;
Expand All @@ -61,7 +61,7 @@ class GuitarTiming

return total / (_fingerPos.size() - zeroCount);
}
int GetSpread()
int GetSpread() const
{
int min = -1;
int max = -1;
Expand Down Expand Up @@ -113,6 +113,11 @@ std::vector<GuitarNotes>
{ 0, 0, 64 }, // D4
};

bool centresort(const GuitarTiming* first, const GuitarTiming* second)
{
return first->GetPositionCentre(21/2) < second->GetPositionCentre(21/2);
}

class NoteTiming
{
// zero is an open string. 1 is longest and deepest, maxFrets is shortest and highest
Expand Down Expand Up @@ -352,6 +357,9 @@ class NoteTiming

bool allZero = false;

// prioritise centres that higher
_possibleTimings.sort(centresort);

// remove the largest finger spreads until no more than 3 are left
while (_possibleTimings.size() > 3 && !allZero) {
allZero = true;
Expand All @@ -363,7 +371,7 @@ class NoteTiming
while (it != _possibleTimings.end()) {
if ((*it)->GetSpread() != 0)
allZero = false;
if ((*it)->GetSpread() > maxSpread)
if ((*it)->GetSpread() >= maxSpread)
max = it;
++it;
}
Expand Down

0 comments on commit c683563

Please sign in to comment.