sine wave works now
This commit is contained in:
@@ -10,42 +10,147 @@
|
||||
|
||||
#include <JuceHeader.h>
|
||||
#include "CrushView.h"
|
||||
|
||||
#include "BinaryData.h"
|
||||
#include "OpenGLUtils.h"
|
||||
#include "juce_opengl/juce_opengl.h"
|
||||
#include "juce_opengl/opengl/juce_gl.h"
|
||||
//==============================================================================
|
||||
CrushView::CrushView()
|
||||
{
|
||||
// In your constructor, you should add any child components, and
|
||||
// initialise any special settings that your component needs.
|
||||
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
|
||||
waveform = generateSineWave(CRUSHVIEW_SAMPLECOUNT, 0, startingColour);
|
||||
distortedWaveform = waveform;
|
||||
vScale(distortedWaveform, 2, 0.75);
|
||||
vTransform(distortedWaveform, -1, 0);
|
||||
for(int i = 0; i<CRUSHVIEW_SAMPLECOUNT; i++){
|
||||
indices.push_back(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};
|
||||
|
||||
antialiasing.multisamplingLevel = 3;
|
||||
ctx.setPixelFormat(antialiasing);
|
||||
|
||||
setOpaque(true);
|
||||
ctx.setContinuousRepainting(true);
|
||||
ctx.setRenderer(this);
|
||||
ctx.attachTo(*this);
|
||||
}
|
||||
|
||||
CrushView::~CrushView()
|
||||
{
|
||||
bgTexture.release();
|
||||
shaderProgram->release();
|
||||
shaderProgramBackground->release();
|
||||
ctx.detach();
|
||||
}
|
||||
|
||||
void CrushView::distortWaveForm(int samplerate){
|
||||
Vertex lastVertex;
|
||||
int lastMultiplier = 0;
|
||||
for (int i = 0; i>waveform.size(); i++){
|
||||
if(floor((float)i/samplerate)>lastMultiplier){
|
||||
lastMultiplier = floor((float)i/samplerate);
|
||||
lastVertex = waveform[i];
|
||||
}
|
||||
distortedWaveform[i] = lastVertex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CrushView::paint (juce::Graphics& g)
|
||||
{
|
||||
/* This demo code just fills the component's background and
|
||||
draws some placeholder text to get you started.
|
||||
|
||||
You should replace everything in this method with your own
|
||||
drawing code..
|
||||
*/
|
||||
|
||||
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); // clear the background
|
||||
|
||||
g.setColour (juce::Colours::grey);
|
||||
g.drawRect (getLocalBounds(), 1); // draw an outline around the component
|
||||
|
||||
g.setColour (juce::Colours::white);
|
||||
g.setFont (14.0f);
|
||||
g.drawText ("CrushView", getLocalBounds(),
|
||||
juce::Justification::centred, true); // draw some placeholder text
|
||||
ctx.triggerRepaint();
|
||||
}
|
||||
|
||||
void CrushView::resized()
|
||||
{
|
||||
// This method is where you should set the bounds of any child
|
||||
// components that your component contains..
|
||||
|
||||
}
|
||||
|
||||
//OPENGL STUFF
|
||||
|
||||
void CrushView::newOpenGLContextCreated(){
|
||||
|
||||
background = juce::ImageCache::getFromMemory(BinaryData::panel_png, BinaryData::panel_pngSize);
|
||||
bgTexture.loadImage(background);
|
||||
|
||||
ctx.extensions.glGenBuffers(1, &vboBackground);
|
||||
ctx.extensions.glGenBuffers(1, &iboBackground);
|
||||
|
||||
ctx.extensions.glGenBuffers(1, &vbo);
|
||||
ctx.extensions.glGenBuffers(1, &ibo);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(VertexTexture)*backgroundVertices.size(), backgroundVertices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboBackground);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * backgroundIndices.size(), backgroundIndices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vbo); //bind vertex buffer objects
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(Vertex)*distortedWaveform.size(), distortedWaveform.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, ibo);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), indices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
//SHADERS
|
||||
vertexShader = VERTEXSHADER;
|
||||
fragmentShader = FRAGSHADER;
|
||||
vertexShaderBackground = VERTEXSHADERBACKGROUND;
|
||||
fragmentShaderBackground = FRAGSHADERBACKGROUND;
|
||||
|
||||
//actually render the shaders now
|
||||
shaderProgramBackground.reset(new juce::OpenGLShaderProgram(ctx));
|
||||
shaderProgramBackground->addVertexShader(vertexShaderBackground);
|
||||
shaderProgramBackground->addFragmentShader(fragmentShaderBackground);
|
||||
shaderProgramBackground->link();
|
||||
shaderProgramBackground->use();
|
||||
|
||||
shaderProgram.reset(new juce::OpenGLShaderProgram(ctx));
|
||||
shaderProgram->addVertexShader(vertexShader);
|
||||
shaderProgram->addFragmentShader(fragmentShader);
|
||||
shaderProgram->link();
|
||||
shaderProgram->use();
|
||||
}
|
||||
|
||||
void CrushView::renderOpenGL(){
|
||||
juce::gl::glLineWidth(2.5f);
|
||||
juce::OpenGLHelpers::clear(juce::Colours::black);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboBackground);
|
||||
|
||||
shaderProgramBackground->use();
|
||||
bgTexture.bind();
|
||||
|
||||
juce::gl::glEnable(juce::gl::GL_BLEND);
|
||||
juce::gl::glBlendFunc(juce::gl::GL_SRC_ALPHA, juce::gl::GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
ctx.extensions.glVertexAttribPointer(0, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), nullptr);
|
||||
ctx.extensions.glEnableVertexAttribArray(0);
|
||||
ctx.extensions.glVertexAttribPointer(1, 4, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), (GLvoid*)(sizeof(float)*2));
|
||||
ctx.extensions.glEnableVertexAttribArray(1);
|
||||
ctx.extensions.glVertexAttribPointer(2, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), (GLvoid*)(sizeof(float)*6));
|
||||
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);
|
||||
|
||||
shaderProgram->use();
|
||||
ctx.extensions.glVertexAttribPointer(0, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(Vertex), nullptr);
|
||||
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, indices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
void CrushView::openGLContextClosing(){
|
||||
|
||||
}
|
||||
|
||||
@@ -10,20 +10,61 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "juce_gui_basics/juce_gui_basics.h"
|
||||
#include "juce_opengl/juce_opengl.h"
|
||||
#include <JuceHeader.h>
|
||||
|
||||
#include "OpenGLUtils.h"
|
||||
#include <string>
|
||||
//==============================================================================
|
||||
/*
|
||||
*/
|
||||
class CrushView : public juce::Component
|
||||
#define CRUSHVIEW_SAMPLECOUNT 200
|
||||
|
||||
class CrushView : public juce::Component, public juce::OpenGLRenderer
|
||||
{
|
||||
public:
|
||||
CrushView();
|
||||
~CrushView() override;
|
||||
|
||||
void newOpenGLContextCreated() override;
|
||||
void renderOpenGL() override;
|
||||
void openGLContextClosing() override;
|
||||
|
||||
void paint (juce::Graphics&) override;
|
||||
void resized() override;
|
||||
|
||||
void distortWaveForm(int sampleRate);
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CrushView)
|
||||
juce::OpenGLContext ctx;
|
||||
juce::OpenGLPixelFormat antialiasing;
|
||||
|
||||
std::vector<Vertex> waveform;
|
||||
std::vector<Vertex> distortedWaveform;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
std::vector<VertexTexture> backgroundVertices;
|
||||
std::vector<unsigned int> backgroundIndices;
|
||||
|
||||
juce::ComponentListener listener;
|
||||
|
||||
GLuint vbo;
|
||||
GLuint ibo;
|
||||
|
||||
GLuint vboBackground;
|
||||
GLuint iboBackground;
|
||||
|
||||
std::string vertexShader;
|
||||
std::string fragmentShader;
|
||||
|
||||
std::string vertexShaderBackground;
|
||||
std::string fragmentShaderBackground;
|
||||
|
||||
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgram;
|
||||
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramBackground;
|
||||
|
||||
juce::Image background;
|
||||
juce::OpenGLTexture bgTexture;
|
||||
|
||||
};
|
||||
|
||||
@@ -11,41 +11,177 @@
|
||||
#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"
|
||||
#include "OpenGLUtils.h"
|
||||
#include "juce_opengl/juce_opengl.h"
|
||||
#include "juce_opengl/opengl/juce_gl.h"
|
||||
//==============================================================================
|
||||
FilterView::FilterView()
|
||||
{
|
||||
// In your constructor, you should add any child components, and
|
||||
// initialise any special settings that your component needs.
|
||||
float startingColour[4] = {128.0f, 255.0f, 255.0f, 255.0f};
|
||||
waveform = generateSineWave(CRUSHVIEW_SAMPLECOUNT, 0, startingColour);
|
||||
distortedWaveform = waveform;
|
||||
vScale(distortedWaveform, 2, 0.75);
|
||||
vTransform(distortedWaveform, -1, 0);
|
||||
for(int i = 0; i<CRUSHVIEW_SAMPLECOUNT; i++){
|
||||
indices.push_back(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};
|
||||
|
||||
antialiasing.multisamplingLevel = 3;
|
||||
ctx.setPixelFormat(antialiasing);
|
||||
|
||||
setOpaque(true);
|
||||
ctx.setContinuousRepainting(true);
|
||||
ctx.setRenderer(this);
|
||||
ctx.attachTo(*this);
|
||||
}
|
||||
|
||||
FilterView::~FilterView()
|
||||
{
|
||||
bgTexture.release();
|
||||
shaderProgram->release();
|
||||
shaderProgramBackground->release();
|
||||
ctx.detach();
|
||||
}
|
||||
|
||||
void FilterView::distortWaveForm(int samplerate){
|
||||
Vertex lastVertex;
|
||||
int lastMultiplier = 0;
|
||||
for (int i = 0; i>waveform.size(); i++){
|
||||
if(floor((float)i/samplerate)>lastMultiplier){
|
||||
lastMultiplier = floor((float)i/samplerate);
|
||||
lastVertex = waveform[i];
|
||||
}
|
||||
distortedWaveform[i] = lastVertex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FilterView::paint (juce::Graphics& g)
|
||||
{
|
||||
/* This demo code just fills the component's background and
|
||||
draws some placeholder text to get you started.
|
||||
|
||||
You should replace everything in this method with your own
|
||||
drawing code..
|
||||
*/
|
||||
|
||||
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); // clear the background
|
||||
|
||||
g.setColour (juce::Colours::grey);
|
||||
g.drawRect (getLocalBounds(), 1); // draw an outline around the component
|
||||
|
||||
g.setColour (juce::Colours::white);
|
||||
g.setFont (14.0f);
|
||||
g.drawText ("FilterView", getLocalBounds(),
|
||||
juce::Justification::centred, true); // draw some placeholder text
|
||||
ctx.triggerRepaint();
|
||||
}
|
||||
|
||||
void FilterView::resized()
|
||||
{
|
||||
// This method is where you should set the bounds of any child
|
||||
// components that your component contains..
|
||||
|
||||
}
|
||||
|
||||
//OPENGL STUFF
|
||||
|
||||
void FilterView::newOpenGLContextCreated(){
|
||||
|
||||
background = juce::ImageCache::getFromMemory(BinaryData::panel_png, BinaryData::panel_pngSize);
|
||||
bgTexture.loadImage(background);
|
||||
|
||||
//GENERATE BUFFERS
|
||||
|
||||
ctx.extensions.glGenBuffers(1, &vboBackground);
|
||||
ctx.extensions.glGenBuffers(1, &iboBackground);
|
||||
|
||||
ctx.extensions.glGenBuffers(1, &vbo);
|
||||
ctx.extensions.glGenBuffers(1, &ibo);
|
||||
|
||||
|
||||
|
||||
//BIND BACKGROUND BUFFERS
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vboBackground);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ARRAY_BUFFER, sizeof(VertexTexture)*backgroundVertices.size(), backgroundVertices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, iboBackground);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * backgroundIndices.size(), backgroundIndices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
//BIND FFT BUFFERS
|
||||
|
||||
//BIND FILTER BUFFERS
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vbo);
|
||||
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, ibo);
|
||||
ctx.extensions.glBufferData(juce::gl::GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * filterIndices.size(), filterIndices.data(), juce::gl::GL_STATIC_DRAW);
|
||||
|
||||
//SHADERS
|
||||
vertexShader = VERTEXSHADER;
|
||||
fragmentShader = FRAGSHADER;
|
||||
vertexShaderBackground = VERTEXSHADERBACKGROUND;
|
||||
fragmentShaderBackground = FRAGSHADERBACKGROUND;
|
||||
|
||||
//actually render the shaders now
|
||||
shaderProgramBackground.reset(new juce::OpenGLShaderProgram(ctx));
|
||||
shaderProgramBackground->addVertexShader(vertexShaderBackground);
|
||||
shaderProgramBackground->addFragmentShader(fragmentShaderBackground);
|
||||
shaderProgramBackground->link();
|
||||
shaderProgramBackground->use();
|
||||
|
||||
shaderProgram.reset(new juce::OpenGLShaderProgram(ctx));
|
||||
shaderProgram->addVertexShader(vertexShader);
|
||||
shaderProgram->addFragmentShader(fragmentShader);
|
||||
shaderProgram->link();
|
||||
shaderProgram->use();
|
||||
}
|
||||
|
||||
void FilterView::renderOpenGL(){
|
||||
juce::gl::glLineWidth(2.5f);
|
||||
juce::OpenGLHelpers::clear(juce::Colours::black);
|
||||
|
||||
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();
|
||||
|
||||
juce::gl::glEnable(juce::gl::GL_BLEND);
|
||||
juce::gl::glBlendFunc(juce::gl::GL_SRC_ALPHA, juce::gl::GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
ctx.extensions.glVertexAttribPointer(0, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), nullptr);
|
||||
ctx.extensions.glEnableVertexAttribArray(0);
|
||||
ctx.extensions.glVertexAttribPointer(1, 4, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), (GLvoid*)(sizeof(float)*2));
|
||||
ctx.extensions.glEnableVertexAttribArray(1);
|
||||
ctx.extensions.glVertexAttribPointer(2, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(VertexTexture), (GLvoid*)(sizeof(float)*6));
|
||||
ctx.extensions.glEnableVertexAttribArray(2);
|
||||
|
||||
juce::gl::glDrawElements(juce::gl::GL_TRIANGLES, backgroundIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
|
||||
bgTexture.unbind();
|
||||
|
||||
//RENDER FFT
|
||||
|
||||
//RENDER FILTER
|
||||
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ARRAY_BUFFER, vbo);
|
||||
ctx.extensions.glBindBuffer(juce::gl::GL_ELEMENT_ARRAY_BUFFER, ibo);
|
||||
|
||||
shaderProgram->use();
|
||||
ctx.extensions.glVertexAttribPointer(0, 2, juce::gl::GL_FLOAT, juce::gl::GL_FALSE, sizeof(Vertex), nullptr);
|
||||
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, filterIndices.size(), juce::gl::GL_UNSIGNED_INT, nullptr);
|
||||
}
|
||||
|
||||
void FilterView::openGLContextClosing(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,91 @@
|
||||
//==============================================================================
|
||||
/*
|
||||
*/
|
||||
class FilterView : public juce::Component
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* CrushView.h
|
||||
* Created: 16 Jan 2026 5:05:38pm
|
||||
* 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 CRUSHVIEW_SAMPLECOUNT 200
|
||||
|
||||
class FilterView : public juce::Component, public juce::OpenGLRenderer
|
||||
{
|
||||
public:
|
||||
FilterView();
|
||||
~FilterView() override;
|
||||
FilterView();
|
||||
~FilterView() override;
|
||||
|
||||
void paint (juce::Graphics&) override;
|
||||
void resized() override;
|
||||
void renderFilter();
|
||||
|
||||
void newOpenGLContextCreated() override;
|
||||
void renderOpenGL() override;
|
||||
void openGLContextClosing() override;
|
||||
|
||||
void paint (juce::Graphics&) override;
|
||||
void resized() override;
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilterView)
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilterView)
|
||||
|
||||
bool isLowPass;
|
||||
float cutoff;
|
||||
float mix;
|
||||
|
||||
juce::OpenGLContext ctx;
|
||||
juce::OpenGLPixelFormat antialiasing;
|
||||
|
||||
std::vector<Vertex> filterVertices;
|
||||
std::vector<unsigned int> filterIndices;
|
||||
|
||||
std::vector<Vertex> filterBackgroundVertices;
|
||||
std::vector<unsigned int> filterBackgroundIndices;
|
||||
|
||||
std::vector<Vertex> fftVertices;
|
||||
std::vector<unsigned int> fftIndices;
|
||||
|
||||
std::vector<VertexTexture> backgroundVertices;
|
||||
std::vector<unsigned int> backgroundIndices;
|
||||
|
||||
juce::ComponentListener listener;
|
||||
|
||||
GLuint vboFilter;
|
||||
GLuint iboFilter;
|
||||
|
||||
GLuint vbofft;
|
||||
GLuint ibofft;
|
||||
|
||||
GLuint vboBackground;
|
||||
GLuint iboBackground;
|
||||
|
||||
std::string vertexShader;
|
||||
std::string fragmentShader;
|
||||
std::string vertexShaderFill;
|
||||
std::string fragmentShaderFill;
|
||||
|
||||
std::string vertexShaderBackground;
|
||||
std::string fragmentShaderBackground;
|
||||
|
||||
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgram;
|
||||
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgermFilter;
|
||||
std::unique_ptr<juce::OpenGLShaderProgram> shaderProgramBackground;
|
||||
|
||||
juce::Image background;
|
||||
juce::OpenGLTexture bgTexture;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
*/
|
||||
|
||||
#include "OpenGLUtils.h"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
|
||||
void svCol(Vertex &v, float newColour[4]){
|
||||
memcpy(&v.colour, &newColour, 4*sizeof(float));
|
||||
v.colour[0] = newColour[0];
|
||||
v.colour[1] = newColour[1];
|
||||
v.colour[2] = newColour[2];
|
||||
v.colour[3] = newColour[3];
|
||||
}
|
||||
|
||||
void setColour(std::vector<Vertex> &verticeList, float newColour[4]){
|
||||
@@ -23,10 +25,17 @@ void setColour(std::vector<Vertex> &verticeList, float newColour[4]){
|
||||
}
|
||||
}
|
||||
|
||||
void vTransform(std::vector<Vertex> &verticeList, int transform[2]){
|
||||
void vTransform(std::vector<Vertex> &verticeList, float x, float y){
|
||||
for(Vertex &v : verticeList){
|
||||
v.position[0] = transform[0];
|
||||
v.position[1] = transform[1];
|
||||
v.position[0] += x;
|
||||
v.position[1] += y;
|
||||
}
|
||||
}
|
||||
|
||||
void vScale(std::vector<Vertex> &verticeList, float x, float y){
|
||||
for(Vertex &v : verticeList){
|
||||
v.position[0] = v.position[0]*x;
|
||||
v.position[1] = v.position[1]*y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,31 +12,81 @@
|
||||
#include <vector>
|
||||
//random shit for convenience
|
||||
|
||||
// fragcolour = vec4(colour.xyz, colour.w*pow(10, -(position.x*position.y)));
|
||||
|
||||
|
||||
#define VERTEXSHADER R"(#version 330 core
|
||||
in vec2 position;
|
||||
in vec4 colour;
|
||||
out vec4 fragcolour;
|
||||
void main(){
|
||||
gl_Position = vec4(position, 1, 1);
|
||||
fragcolour = colour;
|
||||
}
|
||||
in vec2 position;
|
||||
in vec4 colour;
|
||||
out vec4 fragcolour;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(position, 1, 1);
|
||||
fragcolour = colour;
|
||||
if(position.x<0){
|
||||
fragcolour.a = position.x+1;
|
||||
}
|
||||
else{
|
||||
fragcolour.a = 1-position.x;
|
||||
}
|
||||
}
|
||||
)"
|
||||
|
||||
#define FRAGSHADER R"(#version 330 core
|
||||
in vec4 fragcolour;
|
||||
void main(){
|
||||
gl_FragColour = fragcolour;
|
||||
}
|
||||
)";
|
||||
in vec4 fragcolour;
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = fragcolour;
|
||||
}
|
||||
)"
|
||||
|
||||
#define VERTEXSHADERBACKGROUND R"(#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
out vec3 ourColor;
|
||||
out vec2 TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
ourColor = aColor;
|
||||
TexCoord = aTexCoord;
|
||||
}
|
||||
)"
|
||||
|
||||
#define FRAGSHADERBACKGROUND R"(#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(ourTexture, TexCoord);
|
||||
}
|
||||
)"
|
||||
|
||||
struct Vertex{
|
||||
float position[2];
|
||||
float colour[4];
|
||||
};
|
||||
|
||||
struct VertexTexture{
|
||||
float position[2];
|
||||
float colour[4];
|
||||
float texturePosition[2];
|
||||
};
|
||||
|
||||
void svCol(Vertex &v, float newColour[4]);
|
||||
|
||||
void setColour(std::vector<Vertex> &verticeList, float newColour[4]);
|
||||
|
||||
void vTransform(std::vector<Vertex> &verticeList, int transform[2]);
|
||||
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]);
|
||||
|
||||
@@ -6,17 +6,50 @@
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "BinaryData.h"
|
||||
#include "FilterButtonLook.h"
|
||||
#include "PluginProcessor.h"
|
||||
#include "juce_gui_basics/juce_gui_basics.h"
|
||||
#include "PluginEditor.h"
|
||||
|
||||
//==============================================================================
|
||||
CrushFXAudioProcessorEditor::CrushFXAudioProcessorEditor (CrushFXAudioProcessor& p)
|
||||
: AudioProcessorEditor (&p), audioProcessor (p)
|
||||
{
|
||||
// Make sure that before the constructor has finished, you've set the
|
||||
// editor's size to whatever you need it to be.
|
||||
//images
|
||||
bg = juce::ImageCache::getFromMemory(BinaryData::BG_png, BinaryData::BG_pngSize);
|
||||
setSize (696, 400);
|
||||
dialLookandFeel.setImage();
|
||||
filterButtonLookAndFeel.setImages();
|
||||
crushSliderLookAndFeel.setImages();
|
||||
|
||||
addAndMakeVisible(dial1);
|
||||
addAndMakeVisible(dial2);
|
||||
addAndMakeVisible(crushSlider);
|
||||
addAndMakeVisible(filterButton);
|
||||
addAndMakeVisible(crushView);
|
||||
|
||||
//styling
|
||||
dial1.setLookAndFeel(&dialLookandFeel);
|
||||
dial1.setSliderStyle(juce::Slider::SliderStyle::Rotary);
|
||||
dial1.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, true, 0, 0);
|
||||
|
||||
dial2.setLookAndFeel(&dialLookandFeel);
|
||||
dial2.setSliderStyle(juce::Slider::SliderStyle::Rotary);
|
||||
dial2.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, true, 0, 0);
|
||||
|
||||
crushSlider.setLookAndFeel(&crushSliderLookAndFeel);
|
||||
crushSlider.setRange(juce::Range(0.0, 1.0), 0.0);
|
||||
crushSlider.setSliderStyle(juce::Slider::SliderStyle::LinearHorizontal);
|
||||
crushSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, true, 0, 0);
|
||||
|
||||
filterButton.setLookAndFeel(&filterButtonLookAndFeel);
|
||||
filterButton.setToggleable(true);
|
||||
filterButton.setClickingTogglesState(true);
|
||||
filterButton.setButtonText("");
|
||||
|
||||
//sizing
|
||||
setSize (812, 350);
|
||||
setResizable(false, false);
|
||||
}
|
||||
|
||||
CrushFXAudioProcessorEditor::~CrushFXAudioProcessorEditor()
|
||||
@@ -26,11 +59,14 @@ CrushFXAudioProcessorEditor::~CrushFXAudioProcessorEditor()
|
||||
//==============================================================================
|
||||
void CrushFXAudioProcessorEditor::paint (juce::Graphics& g)
|
||||
{
|
||||
g.drawImage(bg, getLocalBounds().toFloat());
|
||||
g.drawImageAt(bg, 0,0);
|
||||
}
|
||||
|
||||
void CrushFXAudioProcessorEditor::resized()
|
||||
{
|
||||
// This is generally where you'll want to lay out the positions of any
|
||||
// subcomponents in your editor..
|
||||
crushView.setBounds(408, 11, 393, 273);
|
||||
dial1.setBounds(269, 287, 55, 56);
|
||||
dial2.setBounds(331, 287, 55, 56);
|
||||
crushSlider.setBounds(578, 293, 205, 43);
|
||||
filterButton.setBounds(165, 300, 94, 29);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuceHeader.h>
|
||||
#include "CrushSliderLook.h"
|
||||
#include "FilterButtonLook.h"
|
||||
#include "PluginProcessor.h"
|
||||
#include "juce_gui_basics/juce_gui_basics.h"
|
||||
#include "DialLook.h"
|
||||
#include "CrushView.h"
|
||||
//==============================================================================
|
||||
/**
|
||||
*/
|
||||
@@ -22,12 +27,21 @@ public:
|
||||
//==============================================================================
|
||||
void paint (juce::Graphics&) override;
|
||||
void resized() override;
|
||||
private:
|
||||
|
||||
CrushView crushView;
|
||||
|
||||
DialLook dialLookandFeel;
|
||||
juce::Slider dial1;
|
||||
juce::Slider dial2;
|
||||
|
||||
CrushSliderLook crushSliderLookAndFeel;
|
||||
juce::Slider crushSlider;
|
||||
|
||||
FilterButtonLook filterButtonLookAndFeel;
|
||||
juce::TextButton filterButton;
|
||||
|
||||
private:
|
||||
juce::Image bg;
|
||||
// This reference is provided as a quick way for your editor to
|
||||
// access the processor object that created it.
|
||||
CrushFXAudioProcessor& audioProcessor;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CrushFXAudioProcessorEditor)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user