Skip to content

Commit

Permalink
Fix guitar orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsw1111 committed Apr 9, 2023
1 parent 9215d94 commit 549b9e5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions xLights/effects/GuitarEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ void GuitarEffect::RenderGuitar(RenderBuffer& buffer, SequenceElements* elements
DrawGuitar(buffer, cache->GetTimingAt(time), stringAppearance, maxFrets, strings, showStrings);
}

inline uint32_t FlipY(uint32_t y, uint32_t height)
{
return height - y - 1;
}

void GuitarEffect::DrawGuitarOn(RenderBuffer& buffer, uint8_t string, uint8_t fretPos, uint8_t maxFrets, uint8_t strings, bool showStrings)
{
xlColor c;
Expand All @@ -601,13 +606,13 @@ void GuitarEffect::DrawGuitarOn(RenderBuffer& buffer, uint8_t string, uint8_t fr

if (showStrings) {
for (uint32_t x = maxX; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, c);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), c);
}
}

for (uint32_t x = 0; x < maxX; ++x) {
for (uint32_t y = perString * string; y < perString * (string + 1); ++y) {
buffer.SetPixel(x, y, c);
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
}
}
Expand All @@ -627,13 +632,13 @@ void GuitarEffect::DrawGuitarFlashFade(RenderBuffer& buffer, uint8_t string, uin
uint32_t maxX = ((maxFrets - fretPos) * buffer.BufferWi) / maxFrets;
if (showStrings) {
for (uint32_t x = maxX; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, cc);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), cc);
}
}

for (uint32_t x = 0; x < maxX; ++x) {
for (uint32_t y = perString * string; y < perString * (string + 1); ++y) {
buffer.SetPixel(x, y, c);
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
}
}
Expand All @@ -649,13 +654,13 @@ void GuitarEffect::DrawGuitarWave(RenderBuffer& buffer, uint8_t string, uint8_t

if (showStrings) {
for (uint32_t x = maxX; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, c);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), c);
}
}

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;
buffer.SetPixel(x, y, c);
buffer.SetPixel(x, FlipY(y, buffer.BufferHt), c);
}
}

Expand All @@ -675,15 +680,15 @@ void GuitarEffect::DrawGuitarWaveFade(RenderBuffer& buffer, uint8_t string, uint

if (showStrings) {
for (uint32_t x = maxX; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, cc);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), cc);
}
}

double maxY = perString * alpha;

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

Expand All @@ -700,15 +705,15 @@ void GuitarEffect::DrawGuitarWaveCollapse(RenderBuffer& buffer, uint8_t string,

if (showStrings) {
for (uint32_t x = maxX; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, c);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), c);
}
}

double maxY = perString * alpha;

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

Expand All @@ -719,7 +724,7 @@ void GuitarEffect::DrawString(RenderBuffer& buffer, uint8_t string, uint8_t stri

double perString = (float)buffer.BufferHt / strings;
for (uint32_t x = 0; x < buffer.BufferWi; ++x) {
buffer.SetPixel(x, perString * string + perString / 2, c);
buffer.SetPixel(x, FlipY(perString * string + perString / 2, buffer.BufferHt), c);
}
}

Expand Down

0 comments on commit 549b9e5

Please sign in to comment.