diff --git a/Source/CrushView.cpp b/Source/CrushView.cpp index b285b1c..19094ad 100644 --- a/Source/CrushView.cpp +++ b/Source/CrushView.cpp @@ -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); diff --git a/Source/CrushView.h b/Source/CrushView.h index 9c9156f..b9acda5 100644 --- a/Source/CrushView.h +++ b/Source/CrushView.h @@ -63,7 +63,6 @@ public: private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CrushView) juce::OpenGLContext ctx; - juce::OpenGLPixelFormat antialiasing; std::vector waveform; std::vector distortedWaveform; diff --git a/Source/FilterView.cpp b/Source/FilterView.cpp index e358f06..cd4a2f2 100644 --- a/Source/FilterView.cpp +++ b/Source/FilterView.cpp @@ -8,20 +8,6 @@ ============================================================================== */ -#include -#include "FilterView.h" - -//============================================================================== -/* - * ============================================================================== - * - * FilterView.cpp - * Created: 16 Jan 2026 5:05:38pm - * Author: esca - * - * ============================================================================== - */ - #include #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; irelease(); 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; iaddFragmentShader(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(){ } - diff --git a/Source/FilterView.h b/Source/FilterView.h index d0c7d4e..023462a 100644 --- a/Source/FilterView.h +++ b/Source/FilterView.h @@ -16,76 +16,155 @@ #include "OpenGLUtils.h" #include -#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 filterVertices; - std::vector filterIndices; + juce::OpenGLContext ctx; - std::vector filterBackgroundVertices; - std::vector filterBackgroundIndices; + std::vector filterVertices; + std::vector filterIndices; - std::vector backgroundVertices; - std::vector backgroundIndices; + std::vector filterBackgroundVertices; + std::vector filterBackgroundIndices; - juce::ComponentListener listener; + std::vector backgroundVertices; + std::vector 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 shaderProgramFilter; - std::unique_ptr shaderProgramFilterFill; - std::unique_ptr shaderProgramBackground; + std::string vertexShaderBackground; + std::string fragmentShaderBackground; - juce::Image background; - juce::OpenGLTexture bgTexture; + std::unique_ptr shaderProgramFilter; + std::unique_ptr shaderProgramFilterFill; + std::unique_ptr shaderProgramBackground; + + juce::Image background; + juce::OpenGLTexture bgTexture; }; diff --git a/Source/OpenGLUtils.cpp b/Source/OpenGLUtils.cpp index 0d74b46..9de365b 100644 --- a/Source/OpenGLUtils.cpp +++ b/Source/OpenGLUtils.cpp @@ -11,6 +11,7 @@ #include "OpenGLUtils.h" #include #include +#include void svCol(Vertex &v, float newColour[4]){ v.colour[0] = newColour[0]; @@ -50,3 +51,13 @@ std::vector generateSineWave(int numVertices, float angle, float startin } return ret; } + + +void printBufferData(std::vector vertices){ + for(Vertex v: vertices){ + std::cout << "V: "; + std::cout << v.position[0] << ", " << v.position[1] << ", "; + std::cout << std::endl; + } +} + diff --git a/Source/OpenGLUtils.h b/Source/OpenGLUtils.h index 523e5ac..7f0a72b 100644 --- a/Source/OpenGLUtils.h +++ b/Source/OpenGLUtils.h @@ -64,3 +64,5 @@ void vTransform(std::vector &verticeList, float x, float y); void vScale(std::vector & verticeList, float x, float y); std::vector generateSineWave(int numVertices, float angle, float startingColour[4]); + +void printBufferData(std::vector vertices); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index ebf4808..3e26369 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -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); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index ee17e7e..8d7b517 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -11,10 +11,12 @@ #include #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;