filterview

This commit is contained in:
2026-01-23 17:18:02 +13:00
parent 87cafe3a05
commit 7dd7ec43cd
8 changed files with 247 additions and 90 deletions

View File

@@ -32,21 +32,15 @@ CrushView::CrushView()
backgroundVertices.push_back(VertexTexture{{1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 1.0f}});
backgroundIndices = {0,1,2,1,2,3};
antialiasing.multisamplingLevel = 3;
ctx.setPixelFormat(antialiasing);
setOpaque(true);
ctx.setContinuousRepainting(true);
ctx.setRenderer(this);
ctx.attachTo(*this);
}
CrushView::~CrushView()
{
bgTexture.bind();
bgTexture.release();
shaderProgram->release();
shaderProgramBackground->release();
ctx.detach();
}
void CrushView::distortWaveForm(int samplerate){
@@ -76,7 +70,13 @@ void CrushView::resized()
void CrushView::newOpenGLContextCreated(){
// antialiasing.multisamplingLevel = 3;
// ctx.setPixelFormat(antialiasing);
background = juce::ImageCache::getFromMemory(BinaryData::panel_png, BinaryData::panel_pngSize);
printf("loaded bg\n");
background.duplicateIfShared();
printf("duplicatedBackground\n");
bgTexture.loadImage(background);
ctx.extensions.glGenBuffers(1, &vboBackground);
@@ -138,7 +138,6 @@ void CrushView::renderOpenGL(){
ctx.extensions.glEnableVertexAttribArray(2);
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, backgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
bgTexture.unbind();
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vbo);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, ibo);

View File

@@ -63,7 +63,6 @@ public:
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CrushView)
juce::OpenGLContext ctx;
juce::OpenGLPixelFormat antialiasing;
std::vector<Vertex> waveform;
std::vector<Vertex> distortedWaveform;

View File

@@ -8,20 +8,6 @@
==============================================================================
*/
#include <JuceHeader.h>
#include "FilterView.h"
//==============================================================================
/*
* ==============================================================================
*
* FilterView.cpp
* Created: 16 Jan 2026 5:05:38pm
* Author: esca
*
* ==============================================================================
*/
#include <JuceHeader.h>
#include "FilterView.h"
#include "BinaryData.h"
@@ -31,32 +17,81 @@
//==============================================================================
FilterView::FilterView()
{
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
cutoff = &tempcutoff;
mix = &tempmix;
//generate filter arrays for first time
for(unsigned int i=0; i<FILTERVIEW_SAMPLECOUNT; i++){
filterVertices.push_back(Vertex{{0,0}, COLOUR});
filterIndices.push_back(i);
filterBackgroundVertices.push_back(Vertex{{0,0}, BGCOLOUR});
//BACKGROUND INDICES
if(i!=0&&i%2==0){
filterBackgroundIndices.insert(filterBackgroundIndices.end(), { i-2, i-1, i });
}
backgroundVertices.push_back(VertexTexture{{-1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{-1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 1.0f}});
backgroundVertices.push_back(VertexTexture{{1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 1.0f}});
backgroundIndices = {0,1,2,1,2,3};
if(i!=1&&i%2!=0){
filterBackgroundIndices.insert(filterBackgroundIndices.end(), { i-2, i-1, i });
}
}
genFilterArrays();
antialiasing.multisamplingLevel = 3;
ctx.setPixelFormat(antialiasing);
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
backgroundVertices.push_back(VertexTexture{{-1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{-1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {0.0f, 1.0f}});
backgroundVertices.push_back(VertexTexture{{1, -1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 0.0f}});
backgroundVertices.push_back(VertexTexture{{1, 1}, {255.0f, 255.0f, 255.0f, 255.0f}, {1.0f, 1.0f}});
backgroundIndices = {0,1,2,1,2,3};
setOpaque(true);
ctx.setContinuousRepainting(true);
ctx.setRenderer(this);
ctx.attachTo(*this);
setOpaque(true);
}
FilterView::~FilterView()
{
bgTexture.bind();
bgTexture.release();
shaderProgramFilter->release();
shaderProgramFilterFill->release();
shaderProgramBackground->release();
ctx.detach();
// ctx.detach(); //failing here
}
void FilterView::genFilterArrays(){
int i = 0;
float yposition = *mix;
for(Vertex &v : filterVertices){
float xposition = (float)i/FILTERVIEW_SAMPLECOUNT;
float deltaCutoff = xposition-*cutoff;
v.position[0] = xposition;
if(deltaCutoff>0){
v.position[1] = yposition-5*(deltaCutoff*deltaCutoff);
if(v.position[1]<0){
v.position[1]=0;
}
}
else v.position[1] = yposition;
i++;
}
vScale(filterVertices, 2, 2);
vTransform(filterVertices, -1, -1);
genFilterFillArrays();
}
void FilterView::genFilterFillArrays(){
for(unsigned int i = 0; i<FILTERVIEW_SAMPLECOUNT; i++){
if(i%2==0){
filterBackgroundVertices.at(i) = filterVertices.at(i);
filterBackgroundVertices.at(i).position[1]=-1;
}
else{
filterBackgroundVertices.at(i) = filterVertices.at(i-1);
}
}
}
void FilterView::paint (juce::Graphics& g)
@@ -74,8 +109,8 @@ void FilterView::resized()
void FilterView::newOpenGLContextCreated(){
background = juce::ImageCache::getFromMemory(BinaryData::panel_png, BinaryData::panel_pngSize);
background.duplicateIfShared();
bgTexture.loadImage(background);
//GENERATE BUFFERS
ctx.extensions.glGenBuffers(1, &vboBackground);
@@ -87,7 +122,6 @@ void FilterView::newOpenGLContextCreated(){
ctx.extensions.glGenBuffers(1, &vboFilter);
ctx.extensions.glGenBuffers(1, &iboFilter);
//BIND BACKGROUND BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
@@ -99,16 +133,23 @@ void FilterView::newOpenGLContextCreated(){
//BIND FILTER FILL BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilterFill);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterVertices.size(), filterVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterBackgroundVertices.size(), filterBackgroundVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboFilterFill);
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * filterBackgroundIndices.size(), filterBackgroundIndices.data(), juce::gl::GL_STATIC_DRAW);
//BIND FILTER BUFFERS
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilter);
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*filterVertices.size(), filterVertices.data(), juce::gl::GL_STATIC_DRAW);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboFilter);
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * filterIndices.size(), filterIndices.data(), juce::gl::GL_STATIC_DRAW);
//SHADERS
vertexShaderFilter = "placeholder";
fragmentShaderFilter = "placeholder";
vertexShaderFilterFill = "placeholder";
fragmentShaderFilterFill = "placeholder";
vertexShaderFilter = VERTEXSHADERFILTER;
fragmentShaderFilter = FRAGSHADERFILTER;
vertexShaderFilterFill = VERTEXSHADERFILTERFILL;
fragmentShaderFilterFill = FRAGSHADERFILTER;
vertexShaderBackground = VERTEXSHADERBACKGROUND;
fragmentShaderBackground = FRAGSHADERBACKGROUND;
@@ -130,6 +171,7 @@ void FilterView::newOpenGLContextCreated(){
shaderProgramFilter->addFragmentShader(fragmentShaderFilter);
shaderProgramFilter->link();
shaderProgramFilter->use();
}
void FilterView::renderOpenGL(){
@@ -139,7 +181,6 @@ void FilterView::renderOpenGL(){
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboBackground);
//RENDER BACKGROUND
shaderProgramBackground->use();
bgTexture.bind();
@@ -155,7 +196,6 @@ void FilterView::renderOpenGL(){
ctx.extensions.glEnableVertexAttribArray(2);
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, backgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
bgTexture.unbind();
//RENDER FILTER FILL
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilterFill);
@@ -166,7 +206,7 @@ void FilterView::renderOpenGL(){
ctx.extensions.glEnableVertexAttribArray(2);
ctx.extensions.glVertexAttribPointer(1, 4, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float)*2));
ctx.extensions.glEnableVertexAttribArray(3);
juce::gl::glDrawElements(juce::gl::GL_LINE_STRIP, filterBackgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, filterBackgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
//RENDER FILTER
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboFilter);
@@ -183,4 +223,3 @@ void FilterView::renderOpenGL(){
void FilterView::openGLContextClosing(){
}

View File

@@ -16,76 +16,155 @@
#include "OpenGLUtils.h"
#include <string>
#define CRUSHVIEW_SAMPLECOUNT 200
#define FILTERVIEW_SAMPLECOUNT 200
#define COLOUR {230, 230, 230, 1.0}
#define BGCOLOUR {255, 255, 255, 0.3}
#define VERTEXSHADERFILTERFILL R"(placeholder)"
#define FRAGSHADERFILTERFILL R"(placeholder)"
#define VERTEXSHADERFILTER R"(#version 330 core
in vec2 position;
in vec4 colour;
out vec4 fragcolour;
float bounds = 0.8;
float xmult;
float ymult;
#define VERTEXSHADERFILTER R"(placeholder)"
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;
}
)"
#define FRAGSHADERFILTER R"(placeholder)"
class FilterView : public juce::Component, public juce::OpenGLRenderer
{
public:
FilterView();
~FilterView() override;
FilterView();
~FilterView() override;
void renderFilter();
void renderFilter();
void newOpenGLContextCreated() override;
void renderOpenGL() override;
void openGLContextClosing() override;
void newOpenGLContextCreated() override;
void renderOpenGL() override;
void openGLContextClosing() override;
void paint (juce::Graphics&) override;
void resized() override;
void paint (juce::Graphics&) override;
void resized() override;
void genFilterArrays();
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilterView)
bool isLowPass;
float cutoff;
float mix;
void genFilterFillArrays();
juce::OpenGLContext ctx;
juce::OpenGLPixelFormat antialiasing;
bool isLowPass;
float *cutoff;
float *mix;
float tempcutoff = 0.5;
float tempmix = 0.5;
std::vector<Vertex> filterVertices;
std::vector<unsigned int> filterIndices;
juce::OpenGLContext ctx;
std::vector<Vertex> filterBackgroundVertices;
std::vector<unsigned int> filterBackgroundIndices;
std::vector<Vertex> filterVertices;
std::vector<unsigned int> filterIndices;
std::vector<VertexTexture> backgroundVertices;
std::vector<unsigned int> backgroundIndices;
std::vector<Vertex> filterBackgroundVertices;
std::vector<unsigned int> filterBackgroundIndices;
juce::ComponentListener listener;
std::vector<VertexTexture> backgroundVertices;
std::vector<unsigned int> backgroundIndices;
GLuint vboFilter;
GLuint iboFilter;
juce::ComponentListener listener;
GLuint vboFilterFill;
GLuint iboFilterFill;
GLuint vboFilter;
GLuint iboFilter;
GLuint vboBackground;
GLuint iboBackground;
GLuint vboFilterFill;
GLuint iboFilterFill;
std::string vertexShaderFilter;
std::string fragmentShaderFilter;
GLuint vboBackground;
GLuint iboBackground;
std::string vertexShaderFilterFill;
std::string fragmentShaderFilterFill;
std::string vertexShaderFilter;
std::string fragmentShaderFilter;
std::string vertexShaderBackground;
std::string fragmentShaderBackground;
std::string vertexShaderFilterFill;
std::string fragmentShaderFilterFill;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilter;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilterFill;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramBackground;
std::string vertexShaderBackground;
std::string fragmentShaderBackground;
juce::Image background;
juce::OpenGLTexture bgTexture;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilter;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramFilterFill;
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramBackground;
juce::Image background;
juce::OpenGLTexture bgTexture;
};

View File

@@ -11,6 +11,7 @@
#include "OpenGLUtils.h"
#include <vector>
#include <math.h>
#include <iostream>
void svCol(Vertex &v, float newColour[4]){
v.colour[0] = newColour[0];
@@ -50,3 +51,13 @@ std::vector<Vertex> generateSineWave(int numVertices, float angle, float startin
}
return ret;
}
void printBufferData(std::vector<Vertex> vertices){
for(Vertex v: vertices){
std::cout << "V: ";
std::cout << v.position[0] << ", " << v.position[1] << ", ";
std::cout << std::endl;
}
}

View File

@@ -64,3 +64,5 @@ void vTransform(std::vector<Vertex> &verticeList, float x, float y);
void vScale(std::vector<Vertex> & verticeList, float x, float y);
std::vector<Vertex> generateSineWave(int numVertices, float angle, float startingColour[4]);
void printBufferData(std::vector<Vertex> vertices);

View File

@@ -1,13 +1,14 @@
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
this shit is held together by thoughts and prayers and i dont even pray
==============================================================================
*/
#include "BinaryData.h"
#include "FilterButtonLook.h"
#include "FilterView.h"
#include "PluginProcessor.h"
#include "juce_gui_basics/juce_gui_basics.h"
#include "PluginEditor.h"
@@ -16,6 +17,17 @@
CrushFXAudioProcessorEditor::CrushFXAudioProcessorEditor (CrushFXAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
ctxC.setRenderer(&crushView);
ctxC.attachTo(crushView);
ctxV.setRenderer(&filterView);
ctxV.attachTo(filterView);
antialiasing.multisamplingLevel = 3;
ctxC.setPixelFormat(antialiasing);
ctxV.setPixelFormat(antialiasing);
//images
bg = juce::ImageCache::getFromMemory(BinaryData::BG_png, BinaryData::BG_pngSize);
dialLookandFeel.setImage();
@@ -26,8 +38,10 @@ CrushFXAudioProcessorEditor::CrushFXAudioProcessorEditor (CrushFXAudioProcessor&
addAndMakeVisible(dial2);
addAndMakeVisible(crushSlider);
addAndMakeVisible(filterButton);
addAndMakeVisible(filterView);
addAndMakeVisible(crushView);
//styling
dial1.setLookAndFeel(&dialLookandFeel);
dial1.setSliderStyle(juce::Slider::SliderStyle::Rotary);
@@ -54,17 +68,24 @@ CrushFXAudioProcessorEditor::CrushFXAudioProcessorEditor (CrushFXAudioProcessor&
CrushFXAudioProcessorEditor::~CrushFXAudioProcessorEditor()
{
printf("detaching\n");
ctxC.detach();
ctxV.detach();
}
//==============================================================================
void CrushFXAudioProcessorEditor::paint (juce::Graphics& g)
{
g.drawImageAt(bg, 0,0);
ctxC.triggerRepaint();
ctxV.triggerRepaint();
}
void CrushFXAudioProcessorEditor::resized()
{
crushView.setBounds(408, 11, 393, 273);
filterView.setBounds(11, 11, 393, 273);
dial1.setBounds(269, 287, 55, 56);
dial2.setBounds(331, 287, 55, 56);
crushSlider.setBounds(578, 293, 205, 43);

View File

@@ -11,10 +11,12 @@
#include <JuceHeader.h>
#include "CrushSliderLook.h"
#include "FilterButtonLook.h"
#include "FilterView.h"
#include "PluginProcessor.h"
#include "juce_gui_basics/juce_gui_basics.h"
#include "DialLook.h"
#include "CrushView.h"
#include "juce_opengl/juce_opengl.h"
//==============================================================================
/**
*/
@@ -29,8 +31,13 @@ public:
void resized() override;
private:
FilterView filterView;
CrushView crushView;
juce::OpenGLContext ctxC;
juce::OpenGLContext ctxV;
juce::OpenGLPixelFormat antialiasing;
DialLook dialLookandFeel;
juce::Slider dial1;
juce::Slider dial2;