From b17131fa79dbdd7a0b1dbb1cd0e17a7327043308 Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 28 Feb 2018 13:04:44 +0200 Subject: [PATCH] Use lambda for envelope drawing. Ignore using envelope tilt transform for now because it's not correctly implemented. --- Source/envelope_component.cpp | 31 ++++++++++++++----------------- Source/jcdp_envelope.h | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Source/envelope_component.cpp b/Source/envelope_component.cpp index c203928..a65cff3 100644 --- a/Source/envelope_component.cpp +++ b/Source/envelope_component.cpp @@ -92,32 +92,29 @@ void EnvelopeComponent::paint(Graphics& g) if (name.isEmpty() == true) name = "Untitled envelope"; g.drawText(name, 10, 10, getWidth(), getHeight(), Justification::topLeft); - const float linethickness = 1.0f; - g.setColour(m_env_color); - double y0 = m_envelope->GetInterpolatedNodeValue(0.0); - const int drawstep = 1; - for (int i = 1; i < getWidth(); ++i) + auto draw_env = [this, &g](Colour envcolor, bool drawTransformed, float linethickness) { - double y1 = m_envelope->GetInterpolatedNodeValue(1.0/getWidth()*i); - double foo_y0 = (double)getHeight() - jmap(y0, m_view_start_value, m_view_end_value, 0.0, getHeight()); - double foo_y1 = (double)getHeight() - jmap(y1, m_view_start_value, m_view_end_value, 0.0, getHeight()); - g.drawLine((float)i, foo_y0, (float)i + 1, foo_y1, linethickness); - y0 = y1; - } - if (m_envelope->isTransformed()) - { - g.setColour(Colours::aliceblue.darker()); - y0 = m_envelope->getTransformedValue(0.0); + g.setColour(envcolor); + double y0 = 0.0; + if (drawTransformed==false) + y0 = m_envelope->GetInterpolatedNodeValue(0.0); + else y0 = m_envelope->getTransformedValue(0.0); + const int drawstep = 1; for (int i = 1; i < getWidth(); ++i) { double env_x = 1.0 / getWidth()*i; - double y1 = m_envelope->getTransformedValue(env_x); + double y1 = 0.0; + if (drawTransformed==false) + y1 = m_envelope->GetInterpolatedNodeValue(env_x); + else y1 = m_envelope->getTransformedValue(env_x); double foo_y0 = (double)getHeight() - jmap(y0, m_view_start_value, m_view_end_value, 0.0, getHeight()); double foo_y1 = (double)getHeight() - jmap(y1, m_view_start_value, m_view_end_value, 0.0, getHeight()); g.drawLine((float)i, foo_y0, (float)i + 1, foo_y1, linethickness); y0 = y1; } - } + }; + draw_env(m_env_color, false, 1.0f); + draw_env(Colours::aquamarine.darker(), true, 1.0f); for (int i = 0; i < m_envelope->GetNumNodes(); ++i) { const envelope_node& pt = m_envelope->GetNodeAtIndex(i); diff --git a/Source/jcdp_envelope.h b/Source/jcdp_envelope.h index 533e4f6..fc78faf 100644 --- a/Source/jcdp_envelope.h +++ b/Source/jcdp_envelope.h @@ -579,7 +579,7 @@ public: sin(2*3.141592653*(x-m_transform_x_shift)*m_transform_y_sinus_freq); double tiltline = 0.5+m_transform_y_tilt*x; double tilted = shifted+tiltline; - return jlimit(0.0,1.0,tilted); + return jlimit(0.0,1.0,shifted); } bool isTransformed() const {