171 lines
3.7 KiB
C++
171 lines
3.7 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
FilterView.h
|
|
Created: 16 Jan 2026 5:06:31pm
|
|
Author: esca
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "juce_gui_basics/juce_gui_basics.h"
|
|
#include "juce_opengl/juce_opengl.h"
|
|
#include <JuceHeader.h>
|
|
#include "OpenGLUtils.h"
|
|
#include <string>
|
|
|
|
#define FILTERVIEW_SAMPLECOUNT 200
|
|
#define COLOUR {230, 230, 230, 1.0}
|
|
#define BGCOLOUR {255, 255, 255, 0.3}
|
|
|
|
|
|
#define VERTEXSHADERFILTER R"(#version 330 core
|
|
in vec2 position;
|
|
in vec4 colour;
|
|
out vec4 fragcolour;
|
|
float bounds = 0.8;
|
|
float xmult;
|
|
float ymult;
|
|
|
|
void main()
|
|
{
|
|
gl_Position = vec4(position, 1, 1);
|
|
fragcolour = colour;
|
|
if(position.x<-bounds){
|
|
xmult = (1/(1-bounds))*(position.x+1);
|
|
}
|
|
else if(position.x>bounds){
|
|
xmult= 1-(1/(1-bounds))*(position.x-bounds);
|
|
}
|
|
else{
|
|
xmult=1;
|
|
}
|
|
if(position.y<-bounds){
|
|
ymult = (1/(1-bounds))*(position.y+1);
|
|
}
|
|
else if(position.y>bounds){
|
|
ymult= 1-(1/(1-bounds))*(position.y-bounds);
|
|
}
|
|
else{
|
|
ymult=1;
|
|
}
|
|
|
|
fragcolour.a = xmult*ymult;
|
|
}
|
|
)"
|
|
|
|
#define VERTEXSHADERFILTERFILL R"(#version 330 core
|
|
in vec2 position;
|
|
in vec4 colour;
|
|
out vec4 fragcolour;
|
|
float bounds = 0.8;
|
|
float xmult;
|
|
float ymult;
|
|
|
|
void main()
|
|
{
|
|
gl_Position = vec4(position, 1, 1);
|
|
fragcolour = colour;
|
|
if(position.x<-bounds){
|
|
xmult = (1/(1-bounds))*(position.x+1);
|
|
}
|
|
else if(position.x>bounds){
|
|
xmult= 1-(1/(1-bounds))*(position.x-bounds);
|
|
}
|
|
else{
|
|
xmult=1;
|
|
}
|
|
if(position.y<-bounds){
|
|
ymult = (1/(1-bounds))*(position.y+1);
|
|
}
|
|
else if(position.y>bounds){
|
|
ymult= 1-(1/(1-bounds))*(position.y-bounds);
|
|
}
|
|
else{
|
|
ymult=1;
|
|
}
|
|
|
|
fragcolour.a = 0.5*xmult*ymult;
|
|
}
|
|
)"
|
|
|
|
#define FRAGSHADERFILTER R"(#version 330 core
|
|
in vec4 fragcolour;
|
|
void main()
|
|
{
|
|
gl_FragColor = fragcolour;
|
|
}
|
|
)"
|
|
|
|
|
|
|
|
class FilterView : public juce::Component, public juce::OpenGLRenderer
|
|
{
|
|
public:
|
|
FilterView();
|
|
~FilterView() override;
|
|
|
|
void renderFilter();
|
|
|
|
void newOpenGLContextCreated() override;
|
|
void renderOpenGL() override;
|
|
void openGLContextClosing() override;
|
|
|
|
void paint (juce::Graphics&) override;
|
|
void resized() override;
|
|
|
|
void genFilterArrays();
|
|
|
|
private:
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilterView)
|
|
|
|
void genFilterFillArrays();
|
|
|
|
bool isLowPass;
|
|
float *cutoff;
|
|
float *mix;
|
|
float tempcutoff = 0.5;
|
|
float tempmix = 0.5;
|
|
|
|
juce::OpenGLContext ctx;
|
|
|
|
std::vector<Vertex> filterVertices;
|
|
std::vector<unsigned int> filterIndices;
|
|
|
|
std::vector<Vertex> filterBackgroundVertices;
|
|
std::vector<unsigned int> filterBackgroundIndices;
|
|
|
|
std::vector<VertexTexture> backgroundVertices;
|
|
std::vector<unsigned int> backgroundIndices;
|
|
|
|
juce::ComponentListener listener;
|
|
|
|
GLuint vboFilter;
|
|
GLuint iboFilter;
|
|
|
|
GLuint vboFilterFill;
|
|
GLuint iboFilterFill;
|
|
|
|
GLuint vboBackground;
|
|
GLuint iboBackground;
|
|
|
|
std::string vertexShaderFilter;
|
|
std::string fragmentShaderFilter;
|
|
|
|
std::string vertexShaderFilterFill;
|
|
std::string fragmentShaderFilterFill;
|
|
|
|
std::string vertexShaderBackground;
|
|
std::string fragmentShaderBackground;
|
|
|
|
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilter;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilterFill;
|
|
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramBackground;
|
|
|
|
juce::Image background;
|
|
juce::OpenGLTexture bgTexture;
|
|
|
|
};
|