Skip to content

Commit

Permalink
Ensure ends of strings tend to centre.
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsw1111 committed Apr 9, 2023
1 parent c683563 commit faca89c
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions xLights/effects/GuitarEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ std::vector<GuitarNotes>

bool centresort(const GuitarTiming* first, const GuitarTiming* second)
{
return first->GetPositionCentre(21/2) < second->GetPositionCentre(21/2);
// we want full strings to be the lowest
return first->GetPositionCentre(0) < second->GetPositionCentre(0);
}

class NoteTiming
Expand Down Expand Up @@ -357,7 +358,7 @@ class NoteTiming

bool allZero = false;

// prioritise centres that higher
// prioritise centres that are lower (hence longer)
_possibleTimings.sort(centresort);

// remove the largest finger spreads until no more than 3 are left
Expand Down Expand Up @@ -651,6 +652,8 @@ void GuitarEffect::DrawGuitarFlashFade(RenderBuffer& buffer, uint8_t string, uin
}
}

#define WAVE_RAMP 3.0

void GuitarEffect::DrawGuitarWave(RenderBuffer& buffer, uint8_t string, uint8_t fretPos, uint32_t timePos, uint8_t maxFrets, uint8_t strings, bool showStrings)
{
xlColor c;
Expand All @@ -667,7 +670,16 @@ void GuitarEffect::DrawGuitarWave(RenderBuffer& buffer, uint8_t string, uint8_t
}

for (uint32_t x = 0; x < maxX; ++x) {
uint32_t y = (perString / 2.0) * sin((PI * 2.0 * cycles * (double)x) / maxX + timePos * 2) + perString / 2.0 + perString * string;

// this foces the wave to zero near the ends
double maxY = perString;
if (x < WAVE_RAMP) {
maxY *= ((double)x * 1.0 / WAVE_RAMP);
} else if (x >= maxX - WAVE_RAMP) {
maxY *= (WAVE_RAMP - (double)(maxX - x - 1)) * 1.0 / WAVE_RAMP;
}

uint32_t y = (maxY / 2.0) * sin((PI * 2.0 * cycles * (double)x) / maxX + timePos * 2) + perString / 2.0 + perString * string;
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
}
Expand All @@ -692,9 +704,16 @@ void GuitarEffect::DrawGuitarWaveFade(RenderBuffer& buffer, uint8_t string, uint
}
}

double maxY = perString * alpha;

for (uint32_t x = 0; x < maxX; ++x) {

// this foces the wave to zero near the ends
double maxY = perString * alpha;
if (x < WAVE_RAMP) {
maxY *= ((double)x * 1.0 / WAVE_RAMP);
} else if (x >= maxX - WAVE_RAMP) {
maxY *= (WAVE_RAMP - (double)(maxX - x - 1.0)) * 1.0 / WAVE_RAMP;
}

uint32_t y = (maxY / 2.0) * sin((PI * 2.0 * cycles * (double)x) / maxX + timePos * 2) + perString / 2.0 + perString * string;
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
Expand All @@ -717,9 +736,18 @@ void GuitarEffect::DrawGuitarWaveCollapse(RenderBuffer& buffer, uint8_t string,
}
}

double maxY = perString * alpha;

for (uint32_t x = 0; x < maxX; ++x) {

// this foces the wave to zero near the ends
double maxY = perString * alpha;
if (x < WAVE_RAMP)
{
maxY *= ((double)x * 1.0 / WAVE_RAMP);
} else if (x >= maxX - WAVE_RAMP)
{
maxY *= (WAVE_RAMP - (double)(maxX - x - 1.0)) * 1.0 / WAVE_RAMP;
}

uint32_t y = (maxY / 2.0) * sin((PI * 2.0 * cycles * (double)x) / maxX + timePos * 2) + perString / 2.0 + perString * string;
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
Expand Down

0 comments on commit faca89c

Please sign in to comment.