From c6151c55ff3ede08a6330579a3caf9e798b65f34 Mon Sep 17 00:00:00 2001 From: Tatsuya Shiozawa Date: Sat, 7 Nov 2020 14:32:00 +0900 Subject: [PATCH] Apply clang-format --- GLSLPlugIn/Source/GLSLComponent.cpp | 371 ++++++------ GLSLPlugIn/Source/GLSLComponent.h | 72 +-- GLSLPlugIn/Source/GLSLTypes.h | 177 +++--- GLSLPlugIn/Source/PlayerWindow.cpp | 237 ++++---- GLSLPlugIn/Source/PlayerWindow.h | 89 +-- GLSLPlugIn/Source/PluginEditor.cpp | 539 +++++++++--------- GLSLPlugIn/Source/PluginEditor.h | 127 +++-- GLSLPlugIn/Source/PluginProcessor.cpp | 186 +++--- GLSLPlugIn/Source/PluginProcessor.h | 16 +- .../Source/Resources/WavefrontObjParser.h | 129 ++++- GLSLPlugIn/Source/StaticValues.cpp | 20 +- GLSLPlugIn/Source/StaticValues.h | 18 +- 12 files changed, 1039 insertions(+), 942 deletions(-) diff --git a/GLSLPlugIn/Source/GLSLComponent.cpp b/GLSLPlugIn/Source/GLSLComponent.cpp index 7c51778..106aa8c 100644 --- a/GLSLPlugIn/Source/GLSLComponent.cpp +++ b/GLSLPlugIn/Source/GLSLComponent.cpp @@ -11,7 +11,7 @@ #include "StaticValues.h" //============================================================================== -const String GLSLComponent::defaultVertexShader = String(std::string(R"( +const String GLSLComponent::defaultVertexShader = String (std::string (R"( attribute vec3 position; attribute vec3 normal; attribute vec4 sourceColour; @@ -34,10 +34,9 @@ void main() trnsmat = trnsmat*0.5; surfacePosition = (vec4(position, 1.0) * trnsmat).xy; gl_Position = vec4(position, 1.0); -})" -)); +})")); -const String GLSLComponent::defaultFragmentShader = String(std::string(R"( +const String GLSLComponent::defaultFragmentShader = String (std::string (R"( #if JUCE_OPENGL_ES varying lowp vec4 destinationColour; varying lowp vec2 textureCoordOut; @@ -64,8 +63,7 @@ void main() float g = abs(sin(position.x - position.y + time + mouse.x)); float b = abs(tan(position.y + time + mouse.y * wave[64])); gl_FragColor = vec4(r, g, b, 1.0); -})" -)); +})")); //============================================================================== GLSLComponent::GLSLComponent() @@ -74,293 +72,302 @@ GLSLComponent::GLSLComponent() GLSLComponent::~GLSLComponent() { - shutdownOpenGL(); + shutdownOpenGL(); } void GLSLComponent::initialise() { - vertexShader = defaultVertexShader; - fragmentShader = defaultFragmentShader; - - if (StaticValues::getShaderCacheReady()) - { - setShaderProgramFragment(StaticValues::getShaderCacheVerified()); - updateShader(); - } - else - { - createShaders(); - } - isInitialised = true; - - triggerAsyncUpdate(); + vertexShader = defaultVertexShader; + fragmentShader = defaultFragmentShader; + + if (StaticValues::getShaderCacheReady()) + { + setShaderProgramFragment (StaticValues::getShaderCacheVerified()); + updateShader(); + } + else + { + createShaders(); + } + isInitialised = true; + + triggerAsyncUpdate(); } void GLSLComponent::shutdown() { - shader = nullptr; - shape = nullptr; - attributes = nullptr; - uniforms = nullptr; + shader = nullptr; + shape = nullptr; + attributes = nullptr; + uniforms = nullptr; } void GLSLComponent::render() { - if (!openGLContext.isAttached()) - return; + if (! openGLContext.isAttached()) + return; - if (!openGLContext.isActive()) - return; + if (! openGLContext.isActive()) + return; - jassert(OpenGLHelpers::isContextActive()); + jassert (OpenGLHelpers::isContextActive()); - if (shader == nullptr) - return; + if (shader == nullptr) + return; - if (isShaderCompileReady) - updateShader(); + if (isShaderCompileReady) + updateShader(); - const float desktopScale = (float)openGLContext.getRenderingScale(); - OpenGLHelpers::clear(Colour::greyLevel(0.1f)); + const float desktopScale = (float) openGLContext.getRenderingScale(); + OpenGLHelpers::clear (Colour::greyLevel (0.1f)); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glViewport(0, 0, roundToInt(desktopScale * getWidth()), roundToInt(desktopScale * getHeight())); + glViewport (0, 0, roundToInt (desktopScale * getWidth()), roundToInt (desktopScale * getHeight())); - shader->use(); + shader->use(); - ////////////////////// VertextShader //////////////// + ////////////////////// VertextShader //////////////// - if (uniforms->projectionMatrix != nullptr) - uniforms->projectionMatrix->setMatrix4(getProjectionMatrix().mat, 1, false); + if (uniforms->projectionMatrix != nullptr) + uniforms->projectionMatrix->setMatrix4 (getProjectionMatrix().mat, 1, false); - if (uniforms->viewMatrix != nullptr) - uniforms->viewMatrix->setMatrix4(getViewMatrix().mat, 1, false); + if (uniforms->viewMatrix != nullptr) + uniforms->viewMatrix->setMatrix4 (getViewMatrix().mat, 1, false); - ////////////////////// FragmentShader //////////////// + ////////////////////// FragmentShader //////////////// - if (uniforms->time != nullptr) { - uniforms->time->set(timeCounter); - } + if (uniforms->time != nullptr) + { + uniforms->time->set (timeCounter); + } - if (uniforms->resolution != nullptr) { - uniforms->resolution->set(getWidth(), getHeight()); - } + if (uniforms->resolution != nullptr) + { + uniforms->resolution->set (getWidth(), getHeight()); + } - if (uniforms->mouse != nullptr) { - if (isMouseButtonDown()) - uniforms->mouse->set(mouseX, mouseY); - } + if (uniforms->mouse != nullptr) + { + if (isMouseButtonDown()) + uniforms->mouse->set (mouseX, mouseY); + } - if (uniforms->midiCC != nullptr) { - uniforms->midiCC->set(m_midiCC, 128); - } + if (uniforms->midiCC != nullptr) + { + uniforms->midiCC->set (m_midiCC, 128); + } - if (uniforms->spectrum != nullptr) { - uniforms->spectrum->set(m_spectrum, 256); - } + if (uniforms->spectrum != nullptr) + { + uniforms->spectrum->set (m_spectrum, 256); + } - if (uniforms->wave != nullptr) { - uniforms->wave->set(m_wave, 256); - } + if (uniforms->wave != nullptr) + { + uniforms->wave->set (m_wave, 256); + } - ////////////////////////////////////// + ////////////////////////////////////// - shape->draw(openGLContext, *attributes); + shape->draw (openGLContext, *attributes); - // Reset the element buffers so child Components draw correctly - openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, 0); - openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + // Reset the element buffers so child Components draw correctly + openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, 0); + openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); - /**/ - timeCounter += 0.02f; - /**/ + /**/ + timeCounter += 0.02f; + /**/ } -void GLSLComponent::paint(Graphics& g) +void GLSLComponent::paint (Graphics& g) { - // You can add your component specific drawing code here! - // This will draw over the top of the openGL background. + // You can add your component specific drawing code here! + // This will draw over the top of the openGL background. } void GLSLComponent::resized() { - // This is called when the MainContentComponent is resized. - // If you add any child components, this is where you should - // update their positions. + // This is called when the MainContentComponent is resized. + // If you add any child components, this is where you should + // update their positions. } -void GLSLComponent::setStatusLabelPtr(Label* _statusLabel) +void GLSLComponent::setStatusLabelPtr (Label* _statusLabel) { - statusLabel = _statusLabel; + statusLabel = _statusLabel; } -void GLSLComponent::setFragmentDocPtr(CodeDocument* _fragmentDoc) +void GLSLComponent::setFragmentDocPtr (CodeDocument* _fragmentDoc) { - fragmentDoc = _fragmentDoc; + fragmentDoc = _fragmentDoc; } //============================================================================== -void GLSLComponent::setShaderProgram(const String& vertexShader, const String& fragmentShader) +void GLSLComponent::setShaderProgram (const String& vertexShader, const String& fragmentShader) { - newVertexShader = vertexShader; - newFragmentShader = fragmentShader; - isShaderCompileReady = true; + newVertexShader = vertexShader; + newFragmentShader = fragmentShader; + isShaderCompileReady = true; } -void GLSLComponent::setShaderProgramFragment(const String& _fragmentShader) +void GLSLComponent::setShaderProgramFragment (const String& _fragmentShader) { - newVertexShader = vertexShader; - newFragmentShader = _fragmentShader; - isShaderCompileReady = true; + newVertexShader = vertexShader; + newFragmentShader = _fragmentShader; + isShaderCompileReady = true; } -void GLSLComponent::setShaderProgramVertex(const String& _vertexShader) +void GLSLComponent::setShaderProgramVertex (const String& _vertexShader) { - newVertexShader = _vertexShader; - newFragmentShader = fragmentShader; - isShaderCompileReady = true; + newVertexShader = _vertexShader; + newFragmentShader = fragmentShader; + isShaderCompileReady = true; } //============================================================================== -void GLSLComponent::setMidiCCValue(int ccNumber, float value) +void GLSLComponent::setMidiCCValue (int ccNumber, float value) { - if (ccNumber < 128) { - m_midiCC[ccNumber] = value; + if (ccNumber < 128) + { + m_midiCC[ccNumber] = value; #ifdef DEBUG - if (statusLabel != nullptr) - { - auto cText = statusLabel->getText(); - cText += " /" + String(ccNumber) + "-" + String(value, 1); - statusLabel->setText(cText, dontSendNotification); - } + if (statusLabel != nullptr) + { + auto cText = statusLabel->getText(); + cText += " /" + String (ccNumber) + "-" + String (value, 1); + statusLabel->setText (cText, dontSendNotification); + } #endif // DEBUG - } + } } -void GLSLComponent::setSpectrumValue(int spectrumNumber, float value) +void GLSLComponent::setSpectrumValue (int spectrumNumber, float value) { - if (spectrumNumber < 256) { - m_spectrum[spectrumNumber] = value; - } + if (spectrumNumber < 256) + { + m_spectrum[spectrumNumber] = value; + } } -void GLSLComponent::setWaveValue(int waveNumber, float value) +void GLSLComponent::setWaveValue (int waveNumber, float value) { - if (waveNumber < 256) { - m_wave[waveNumber] = value; - } + if (waveNumber < 256) + { + m_wave[waveNumber] = value; + } } //============================================================================== void GLSLComponent::handleAsyncUpdate() { - if (statusLabel != nullptr) - statusLabel->setText(statusText, dontSendNotification); + if (statusLabel != nullptr) + statusLabel->setText (statusText, dontSendNotification); } //============================================================================== void GLSLComponent::createShaders() { - if (!openGLContext.isAttached()) - return; + if (! openGLContext.isAttached()) + return; - if (!openGLContext.isActive()) - return; + if (! openGLContext.isActive()) + return; - std::unique_ptr newShader(new OpenGLShaderProgram(openGLContext)); + std::unique_ptr newShader (new OpenGLShaderProgram (openGLContext)); - if (newShader->addVertexShader(OpenGLHelpers::translateVertexShaderToV3(vertexShader)) - && newShader->addFragmentShader(OpenGLHelpers::translateFragmentShaderToV3(fragmentShader)) - && newShader->link()) - { - shader = std::move(newShader); - shader->use(); + if (newShader->addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (vertexShader)) + && newShader->addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (fragmentShader)) + && newShader->link()) + { + shader = std::move (newShader); + shader->use(); - shape.reset(new Shape(openGLContext)); - attributes.reset(new Attributes(openGLContext, *shader)); - uniforms.reset(new Uniforms(openGLContext, *shader)); + shape.reset (new Shape (openGLContext)); + attributes.reset (new Attributes (openGLContext, *shader)); + uniforms.reset (new Uniforms (openGLContext, *shader)); - statusText = "GLSL: v" + String(OpenGLShaderProgram::getLanguageVersion(), 2); - isShaderCompileSuccess = true; + statusText = "GLSL: v" + String (OpenGLShaderProgram::getLanguageVersion(), 2); + isShaderCompileSuccess = true; - StaticValues::setShaderCacheVerified(newFragmentShader); - } - else - { - statusText = newShader->getLastError(); - isShaderCompileSuccess = false; - } + StaticValues::setShaderCacheVerified (newFragmentShader); + } + else + { + statusText = newShader->getLastError(); + isShaderCompileSuccess = false; + } - isShaderCompileReady = false; + isShaderCompileReady = false; - triggerAsyncUpdate(); + triggerAsyncUpdate(); } void GLSLComponent::updateShader() { - if (!openGLContext.isAttached()) - return; + if (! openGLContext.isAttached()) + return; - if (!openGLContext.isActive()) - return; + if (! openGLContext.isActive()) + return; - if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty()) - { - std::unique_ptr newShader(new OpenGLShaderProgram(openGLContext)); + if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty()) + { + std::unique_ptr newShader (new OpenGLShaderProgram (openGLContext)); - if (newShader->addVertexShader(OpenGLHelpers::translateVertexShaderToV3(newVertexShader)) - && newShader->addFragmentShader(OpenGLHelpers::translateFragmentShaderToV3(newFragmentShader)) - && newShader->link()) - { - shader = std::move(newShader); - shader->use(); + if (newShader->addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (newVertexShader)) + && newShader->addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (newFragmentShader)) + && newShader->link()) + { + shader = std::move (newShader); + shader->use(); - shape.reset(new Shape(openGLContext)); - attributes.reset(new Attributes(openGLContext, *shader)); - uniforms.reset(new Uniforms(openGLContext, *shader)); + shape.reset (new Shape (openGLContext)); + attributes.reset (new Attributes (openGLContext, *shader)); + uniforms.reset (new Uniforms (openGLContext, *shader)); - statusText = "GLSL: v" + String(OpenGLShaderProgram::getLanguageVersion(), 2); - isShaderCompileSuccess = true; + statusText = "GLSL: v" + String (OpenGLShaderProgram::getLanguageVersion(), 2); + isShaderCompileSuccess = true; - StaticValues::setShaderCacheVerified(newFragmentShader); - } - else - { - statusText = newShader->getLastError(); - isShaderCompileSuccess = false; - } + StaticValues::setShaderCacheVerified (newFragmentShader); + } + else + { + statusText = newShader->getLastError(); + isShaderCompileSuccess = false; + } - newVertexShader = String(); - newFragmentShader = String(); + newVertexShader = String(); + newFragmentShader = String(); - isShaderCompileReady = false; - } + isShaderCompileReady = false; + } - triggerAsyncUpdate(); + triggerAsyncUpdate(); } -void GLSLComponent::mouseDrag(const MouseEvent& event) +void GLSLComponent::mouseDrag (const MouseEvent& event) { - mouseX = float(event.getPosition().getX()) / getWidth(); - mouseY = 1.0f - float(event.getPosition().getY()) / getHeight(); + mouseX = float (event.getPosition().getX()) / getWidth(); + mouseY = 1.0f - float (event.getPosition().getY()) / getHeight(); - mouseX = std::min(std::max(0.0f, mouseX), 1.0f); - mouseY = std::min(std::max(0.0f, mouseY), 1.0f); + mouseX = std::min (std::max (0.0f, mouseX), 1.0f); + mouseY = std::min (std::max (0.0f, mouseY), 1.0f); } Matrix3D GLSLComponent::getProjectionMatrix() const { - float w = 1.0f / (0.5f + 0.1f); - float h = w * getLocalBounds().toFloat().getAspectRatio(false); - return Matrix3D::fromFrustum(-w, w, -h, h, 4.0f, 30.0f); + float w = 1.0f / (0.5f + 0.1f); + float h = w * getLocalBounds().toFloat().getAspectRatio (false); + return Matrix3D::fromFrustum (-w, w, -h, h, 4.0f, 30.0f); } Matrix3D GLSLComponent::getViewMatrix() const { - Matrix3D viewMatrix(Vector3D(0.0f, 0.0f, -5.0f /*-10.0f*/)); - Matrix3D rotationMatrix = viewMatrix.rotation(Vector3D(-0.3f, 5.0f * std::sin(getFrameCounter() * 0.01f), 0.0f)); + Matrix3D viewMatrix (Vector3D (0.0f, 0.0f, -5.0f /*-10.0f*/)); + Matrix3D rotationMatrix = viewMatrix.rotation (Vector3D (-0.3f, 5.0f * std::sin (getFrameCounter() * 0.01f), 0.0f)); - return /*rotationMatrix * */viewMatrix; + return /*rotationMatrix * */ viewMatrix; } diff --git a/GLSLPlugIn/Source/GLSLComponent.h b/GLSLPlugIn/Source/GLSLComponent.h index 60fb5f2..6e4e4c8 100644 --- a/GLSLPlugIn/Source/GLSLComponent.h +++ b/GLSLPlugIn/Source/GLSLComponent.h @@ -18,40 +18,40 @@ This component lives inside our window, and this is where you should put all your controls and content. */ -class GLSLComponent : public OpenGLAppComponent, - public AsyncUpdater +class GLSLComponent : public OpenGLAppComponent, + public AsyncUpdater { public: //============================================================================== - GLSLComponent(); - ~GLSLComponent(); + GLSLComponent(); + ~GLSLComponent(); //============================================================================== - void initialise() override; - void shutdown() override; - void render() override; + void initialise() override; + void shutdown() override; + void render() override; //============================================================================== - void paint(Graphics& g) override; - void resized() override; + void paint (Graphics& g) override; + void resized() override; //============================================================================== - void setStatusLabelPtr(Label* _statusLabel); - void setFragmentDocPtr(CodeDocument* _fragmentDoc); + void setStatusLabelPtr (Label* _statusLabel); + void setFragmentDocPtr (CodeDocument* _fragmentDoc); //============================================================================== - void setShaderProgram(const String& vertexShader, const String& fragmentShader); - void setShaderProgramFragment(const String& _fragmentShader); - void setShaderProgramVertex(const String& _vertexShader); + void setShaderProgram (const String& vertexShader, const String& fragmentShader); + void setShaderProgramFragment (const String& _fragmentShader); + void setShaderProgramVertex (const String& _vertexShader); //============================================================================== - void setMidiCCValue(int ccNumber, float value); - void setSpectrumValue(int spectrumNumber, float value); - void setWaveValue(int waveNumber, float value); + void setMidiCCValue (int ccNumber, float value); + void setSpectrumValue (int spectrumNumber, float value); + void setWaveValue (int waveNumber, float value); //============================================================================== - bool isInitialised = false; - bool isShaderCompileSuccess = false; + bool isInitialised = false; + bool isShaderCompileSuccess = false; static const String defaultVertexShader; static const String defaultFragmentShader; @@ -60,36 +60,36 @@ class GLSLComponent : public OpenGLAppComponent, //============================================================================== virtual void handleAsyncUpdate() override; - //============================================================================== - void createShaders(); - void updateShader(); - void mouseDrag(const MouseEvent& event) override; + //============================================================================== + void createShaders(); + void updateShader(); + void mouseDrag (const MouseEvent& event) override; //============================================================================== - Matrix3D getProjectionMatrix() const; - Matrix3D getViewMatrix() const; - + Matrix3D getProjectionMatrix() const; + Matrix3D getViewMatrix() const; + //============================================================================== String vertexShader; String fragmentShader; - String statusText{}; - Label* statusLabel = nullptr; - CodeDocument* fragmentDoc = nullptr; + String statusText {}; + Label* statusLabel = nullptr; + CodeDocument* fragmentDoc = nullptr; std::unique_ptr shader; std::unique_ptr shape; std::unique_ptr attributes; std::unique_ptr uniforms; - GLfloat timeCounter = 0.0f; + GLfloat timeCounter = 0.0f; String newVertexShader, newFragmentShader; - bool isShaderCompileReady = false; - float mouseX, mouseY; - float m_midiCC[128] = {0}; - float m_spectrum[256] = {0}; - float m_wave[256] = {0}; + bool isShaderCompileReady = false; + float mouseX, mouseY; + float m_midiCC[128] = { 0 }; + float m_spectrum[256] = { 0 }; + float m_wave[256] = { 0 }; - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GLSLComponent) + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GLSLComponent) }; diff --git a/GLSLPlugIn/Source/GLSLTypes.h b/GLSLPlugIn/Source/GLSLTypes.h index 810790c..65796bd 100644 --- a/GLSLPlugIn/Source/GLSLTypes.h +++ b/GLSLPlugIn/Source/GLSLTypes.h @@ -22,7 +22,7 @@ struct Vertex float colour[4]; float texCoord[2]; - JUCE_LEAK_DETECTOR(Vertex) + JUCE_LEAK_DETECTOR (Vertex) }; //============================================================================== @@ -30,48 +30,52 @@ struct Vertex struct Attributes { //============================================================================== - Attributes(OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram) + Attributes (OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram) { - position.reset(createAttribute(openGLContext, shaderProgram, "position")); - normal.reset(createAttribute(openGLContext, shaderProgram, "normal")); - sourceColour.reset(createAttribute(openGLContext, shaderProgram, "sourceColour")); - texureCoordIn.reset(createAttribute(openGLContext, shaderProgram, "texureCoordIn")); + position.reset (createAttribute (openGLContext, shaderProgram, "position")); + normal.reset (createAttribute (openGLContext, shaderProgram, "normal")); + sourceColour.reset (createAttribute (openGLContext, shaderProgram, "sourceColour")); + texureCoordIn.reset (createAttribute (openGLContext, shaderProgram, "texureCoordIn")); } //============================================================================== - void enable(OpenGLContext& openGLContext) + void enable (OpenGLContext& openGLContext) { if (position != nullptr) { - openGLContext.extensions.glVertexAttribPointer(position->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); - openGLContext.extensions.glEnableVertexAttribArray(position->attributeID); + openGLContext.extensions.glVertexAttribPointer (position->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof (Vertex), 0); + openGLContext.extensions.glEnableVertexAttribArray (position->attributeID); } if (normal != nullptr) { - openGLContext.extensions.glVertexAttribPointer(normal->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 3)); - openGLContext.extensions.glEnableVertexAttribArray(normal->attributeID); + openGLContext.extensions.glVertexAttribPointer (normal->attributeID, 3, GL_FLOAT, GL_FALSE, sizeof (Vertex), (GLvoid*) (sizeof (float) * 3)); + openGLContext.extensions.glEnableVertexAttribArray (normal->attributeID); } if (sourceColour != nullptr) { - openGLContext.extensions.glVertexAttribPointer(sourceColour->attributeID, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 6)); - openGLContext.extensions.glEnableVertexAttribArray(sourceColour->attributeID); + openGLContext.extensions.glVertexAttribPointer (sourceColour->attributeID, 4, GL_FLOAT, GL_FALSE, sizeof (Vertex), (GLvoid*) (sizeof (float) * 6)); + openGLContext.extensions.glEnableVertexAttribArray (sourceColour->attributeID); } if (texureCoordIn != nullptr) { - openGLContext.extensions.glVertexAttribPointer(texureCoordIn->attributeID, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(float) * 10)); - openGLContext.extensions.glEnableVertexAttribArray(texureCoordIn->attributeID); + openGLContext.extensions.glVertexAttribPointer (texureCoordIn->attributeID, 2, GL_FLOAT, GL_FALSE, sizeof (Vertex), (GLvoid*) (sizeof (float) * 10)); + openGLContext.extensions.glEnableVertexAttribArray (texureCoordIn->attributeID); } } - void disable(OpenGLContext& openGLContext) + void disable (OpenGLContext& openGLContext) { - if (position.get() != nullptr) openGLContext.extensions.glDisableVertexAttribArray(position->attributeID); - if (normal.get() != nullptr) openGLContext.extensions.glDisableVertexAttribArray(normal->attributeID); - if (sourceColour.get() != nullptr) openGLContext.extensions.glDisableVertexAttribArray(sourceColour->attributeID); - if (texureCoordIn.get() != nullptr) openGLContext.extensions.glDisableVertexAttribArray(texureCoordIn->attributeID); + if (position.get() != nullptr) + openGLContext.extensions.glDisableVertexAttribArray (position->attributeID); + if (normal.get() != nullptr) + openGLContext.extensions.glDisableVertexAttribArray (normal->attributeID); + if (sourceColour.get() != nullptr) + openGLContext.extensions.glDisableVertexAttribArray (sourceColour->attributeID); + if (texureCoordIn.get() != nullptr) + openGLContext.extensions.glDisableVertexAttribArray (texureCoordIn->attributeID); } //============================================================================== @@ -82,18 +86,18 @@ struct Attributes private: //============================================================================== - static OpenGLShaderProgram::Attribute* createAttribute(OpenGLContext& openGLContext, - OpenGLShaderProgram& shader, - const char* attributeName) + static OpenGLShaderProgram::Attribute* createAttribute (OpenGLContext& openGLContext, + OpenGLShaderProgram& shader, + const char* attributeName) { - if (openGLContext.extensions.glGetAttribLocation(shader.getProgramID(), attributeName) < 0) + if (openGLContext.extensions.glGetAttribLocation (shader.getProgramID(), attributeName) < 0) return nullptr; - return new OpenGLShaderProgram::Attribute(shader, attributeName); + return new OpenGLShaderProgram::Attribute (shader, attributeName); } //============================================================================== - JUCE_LEAK_DETECTOR(Attributes) + JUCE_LEAK_DETECTOR (Attributes) }; //============================================================================== @@ -101,16 +105,16 @@ struct Attributes struct Uniforms { //============================================================================== - Uniforms(OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram) + Uniforms (OpenGLContext& openGLContext, OpenGLShaderProgram& shaderProgram) { - projectionMatrix.reset(createUniform(openGLContext, shaderProgram, "projectionMatrix")); - viewMatrix.reset(createUniform(openGLContext, shaderProgram, "viewMatrix")); - time.reset(createUniform(openGLContext, shaderProgram, "time")); - resolution.reset(createUniform(openGLContext, shaderProgram, "resolution")); - mouse.reset(createUniform(openGLContext, shaderProgram, "mouse")); - midiCC.reset(createUniform(openGLContext, shaderProgram, "midiCC")); - spectrum.reset(createUniform(openGLContext, shaderProgram, "spectrum")); - wave.reset(createUniform(openGLContext, shaderProgram, "wave")); + projectionMatrix.reset (createUniform (openGLContext, shaderProgram, "projectionMatrix")); + viewMatrix.reset (createUniform (openGLContext, shaderProgram, "viewMatrix")); + time.reset (createUniform (openGLContext, shaderProgram, "time")); + resolution.reset (createUniform (openGLContext, shaderProgram, "resolution")); + mouse.reset (createUniform (openGLContext, shaderProgram, "mouse")); + midiCC.reset (createUniform (openGLContext, shaderProgram, "midiCC")); + spectrum.reset (createUniform (openGLContext, shaderProgram, "spectrum")); + wave.reset (createUniform (openGLContext, shaderProgram, "wave")); } //============================================================================== @@ -125,18 +129,18 @@ struct Uniforms private: //============================================================================== - static OpenGLShaderProgram::Uniform* createUniform(OpenGLContext& openGLContext, - OpenGLShaderProgram& shaderProgram, - const char* uniformName) + static OpenGLShaderProgram::Uniform* createUniform (OpenGLContext& openGLContext, + OpenGLShaderProgram& shaderProgram, + const char* uniformName) { - if (openGLContext.extensions.glGetUniformLocation(shaderProgram.getProgramID(), uniformName) < 0) + if (openGLContext.extensions.glGetUniformLocation (shaderProgram.getProgramID(), uniformName) < 0) return nullptr; - return new OpenGLShaderProgram::Uniform(shaderProgram, uniformName); + return new OpenGLShaderProgram::Uniform (shaderProgram, uniformName); } //============================================================================== - JUCE_LEAK_DETECTOR(Uniforms) + JUCE_LEAK_DETECTOR (Uniforms) }; //============================================================================== @@ -146,24 +150,24 @@ struct Uniforms struct Shape { //============================================================================== - Shape(OpenGLContext& openGLContext) + Shape (OpenGLContext& openGLContext) { - if (shapeFile.load(BinaryData::base_obj).wasOk()) + if (shapeFile.load (BinaryData::base_obj).wasOk()) for (int i = 0; i < shapeFile.shapes.size(); ++i) - vertexBuffers.add(new VertexBuffer(openGLContext, *shapeFile.shapes.getUnchecked(i))); + vertexBuffers.add (new VertexBuffer (openGLContext, *shapeFile.shapes.getUnchecked (i))); } //============================================================================== - void draw(OpenGLContext& openGLContext, Attributes& glAttributes) + void draw (OpenGLContext& openGLContext, Attributes& glAttributes) { for (int i = 0; i < vertexBuffers.size(); ++i) { - VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked(i); + VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked (i); vertexBuffer.bind(); - glAttributes.enable(openGLContext); - glDrawElements(GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0); - glAttributes.disable(openGLContext); + glAttributes.enable (openGLContext); + glDrawElements (GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0); + glAttributes.disable (openGLContext); } } @@ -172,38 +176,40 @@ struct Shape struct VertexBuffer { //============================================================================== - VertexBuffer(OpenGLContext& context, WavefrontObjFile::Shape& aShape) : openGLContext(context) + VertexBuffer (OpenGLContext& context, WavefrontObjFile::Shape& aShape) : openGLContext (context) { numIndices = aShape.mesh.indices.size(); - openGLContext.extensions.glGenBuffers(1, &vertexBuffer); - openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); + openGLContext.extensions.glGenBuffers (1, &vertexBuffer); + openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, vertexBuffer); Array vertices; - createVertexListFromMesh(aShape.mesh, vertices, Colours::green); - - openGLContext.extensions.glBufferData(GL_ARRAY_BUFFER, - static_cast (static_cast (vertices.size()) * sizeof(Vertex)), - vertices.getRawDataPointer(), GL_STATIC_DRAW); - - openGLContext.extensions.glGenBuffers(1, &indexBuffer); - openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - openGLContext.extensions.glBufferData(GL_ELEMENT_ARRAY_BUFFER, - static_cast (static_cast (numIndices) * sizeof(juce::uint32)), - aShape.mesh.indices.getRawDataPointer(), GL_STATIC_DRAW); + createVertexListFromMesh (aShape.mesh, vertices, Colours::green); + + openGLContext.extensions.glBufferData (GL_ARRAY_BUFFER, + static_cast (static_cast (vertices.size()) * sizeof (Vertex)), + vertices.getRawDataPointer(), + GL_STATIC_DRAW); + + openGLContext.extensions.glGenBuffers (1, &indexBuffer); + openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, indexBuffer); + openGLContext.extensions.glBufferData (GL_ELEMENT_ARRAY_BUFFER, + static_cast (static_cast (numIndices) * sizeof (juce::uint32)), + aShape.mesh.indices.getRawDataPointer(), + GL_STATIC_DRAW); } ~VertexBuffer() { - openGLContext.extensions.glDeleteBuffers(1, &vertexBuffer); - openGLContext.extensions.glDeleteBuffers(1, &indexBuffer); + openGLContext.extensions.glDeleteBuffers (1, &vertexBuffer); + openGLContext.extensions.glDeleteBuffers (1, &indexBuffer); } //============================================================================== void bind() { - openGLContext.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - openGLContext.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); + openGLContext.extensions.glBindBuffer (GL_ARRAY_BUFFER, vertexBuffer); + openGLContext.extensions.glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, indexBuffer); } //============================================================================== @@ -212,11 +218,11 @@ struct Shape OpenGLContext& openGLContext; //============================================================================== - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VertexBuffer) + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VertexBuffer) }; //============================================================================== - static void createVertexListFromMesh(const WavefrontObjFile::Mesh& mesh, Array& list, Colour colour) + static void createVertexListFromMesh (const WavefrontObjFile::Mesh& mesh, Array& list, Colour colour) { const float scale = 1.0f; //0.2f; WavefrontObjFile::TextureCoord defaultTexCoord = { 0.5f, 0.5f }; @@ -224,23 +230,28 @@ struct Shape for (int i = 0; i < mesh.vertices.size(); ++i) { - const WavefrontObjFile::Vertex& v = mesh.vertices.getReference(i); - - const WavefrontObjFile::Vertex& n - = i < mesh.normals.size() ? mesh.normals.getReference(i) : defaultNormal; - - const WavefrontObjFile::TextureCoord& tc - = i < mesh.textureCoords.size() ? mesh.textureCoords.getReference(i) : defaultTexCoord; - - Vertex vert = - { - { scale * v.x, scale * v.y, scale * v.z, }, - { scale * n.x, scale * n.y, scale * n.z, }, + const WavefrontObjFile::Vertex& v = mesh.vertices.getReference (i); + + const WavefrontObjFile::Vertex& n = i < mesh.normals.size() ? mesh.normals.getReference (i) : defaultNormal; + + const WavefrontObjFile::TextureCoord& tc = i < mesh.textureCoords.size() ? mesh.textureCoords.getReference (i) : defaultTexCoord; + + Vertex vert = { + { + scale * v.x, + scale * v.y, + scale * v.z, + }, + { + scale * n.x, + scale * n.y, + scale * n.z, + }, { colour.getFloatRed(), colour.getFloatGreen(), colour.getFloatBlue(), colour.getFloatAlpha() }, { tc.x, tc.y } }; - list.add(vert); + list.add (vert); } } @@ -249,5 +260,5 @@ struct Shape OwnedArray vertexBuffers; //============================================================================== - JUCE_LEAK_DETECTOR(Shape) + JUCE_LEAK_DETECTOR (Shape) }; \ No newline at end of file diff --git a/GLSLPlugIn/Source/PlayerWindow.cpp b/GLSLPlugIn/Source/PlayerWindow.cpp index 0254293..6d5d717 100644 --- a/GLSLPlugIn/Source/PlayerWindow.cpp +++ b/GLSLPlugIn/Source/PlayerWindow.cpp @@ -10,169 +10,170 @@ #include "StaticValues.h" #include "PlayerWindow.h" -PlayerWindow::PlayerWindow(String name) - : DocumentWindow(name, Colours::lightgrey, DocumentWindow::allButtons), - forwardFFT(fftOrder), - fifoIndex(0), - nextFFTBlockReady(false) +PlayerWindow::PlayerWindow (String name) + : DocumentWindow (name, Colours::lightgrey, DocumentWindow::allButtons), + forwardFFT (fftOrder), + fifoIndex (0), + nextFFTBlockReady (false) { - addKeyListener(this); + addKeyListener (this); - setBackgroundColour(Colours::black); + setBackgroundColour (Colours::black); - setUsingNativeTitleBar(false); - setTitleBarHeight(TITLEBAR_HEIGHT); + setUsingNativeTitleBar (false); + setTitleBarHeight (TITLEBAR_HEIGHT); - setResizable(true, true); - centreWithSize(600, 600); - - m_GLSLCompo.setBounds(0, 0, getWidth(), getHeight()); - setContentOwned(&m_GLSLCompo, true); + setResizable (true, true); + centreWithSize (600, 600); - setVisible(true); - startTimer(shaderLinkDelay); + m_GLSLCompo.setBounds (0, 0, getWidth(), getHeight()); + setContentOwned (&m_GLSLCompo, true); + + setVisible (true); + startTimer (shaderLinkDelay); } PlayerWindow::~PlayerWindow() { - stopTimer(); - setContentNonOwned(&m_GLSLCompo, true); + stopTimer(); + setContentNonOwned (&m_GLSLCompo, true); } void PlayerWindow::closeButtonPressed() { - // This is called when the user tries to close this window. Here, we'll just - // ask the app to quit when this happens, but you can change this to do - // whatever you need. - centreWithSize(600, 600); + // This is called when the user tries to close this window. Here, we'll just + // ask the app to quit when this happens, but you can change this to do + // whatever you need. + centreWithSize (600, 600); } void PlayerWindow::maximiseButtonPressed() { - setFullScreen(!isFullScreen()); - - if (isFullScreen()) - { - setTitleBarHeight(0); - } - else - { - setTitleBarHeight(TITLEBAR_HEIGHT); - } + setFullScreen (! isFullScreen()); + + if (isFullScreen()) + { + setTitleBarHeight (0); + } + else + { + setTitleBarHeight (TITLEBAR_HEIGHT); + } } -bool PlayerWindow::keyPressed(const KeyPress& key, Component* originatingComponent) +bool PlayerWindow::keyPressed (const KeyPress& key, Component* originatingComponent) { - if (key.getKeyCode() == key.escapeKey) - { - maximiseButtonPressed(); - } - else if (key.getKeyCode() == key.tabKey) - { - updateShader(); - } - return true; + if (key.getKeyCode() == key.escapeKey) + { + maximiseButtonPressed(); + } + else if (key.getKeyCode() == key.tabKey) + { + updateShader(); + } + return true; } //============================================================================== void PlayerWindow::timerCallback() { - if (StaticValues::getNeedShaderSync()) - { - StaticValues::setNeedShaderSync(false); - - stopTimer(); - - if(m_GLSLCompo.isInitialised) - m_GLSLCompo.setShaderProgramFragment(StaticValues::getShaderCache()); - - startTimer(20); - } - - // MIDI CC - if (!m_midiCCqueue.empty()) { - sendMidiCCValue(); - } - - // Wave - if (nextWaveBlockReady) - { - sendNextWave(); - nextWaveBlockReady = false; - } - - // FFT - if (nextFFTBlockReady) - { - sendNextSpectrum(); - nextFFTBlockReady = false; - } + if (StaticValues::getNeedShaderSync()) + { + StaticValues::setNeedShaderSync (false); + + stopTimer(); + + if (m_GLSLCompo.isInitialised) + m_GLSLCompo.setShaderProgramFragment (StaticValues::getShaderCache()); + + startTimer (20); + } + + // MIDI CC + if (! m_midiCCqueue.empty()) + { + sendMidiCCValue(); + } + + // Wave + if (nextWaveBlockReady) + { + sendNextWave(); + nextWaveBlockReady = false; + } + + // FFT + if (nextFFTBlockReady) + { + sendNextSpectrum(); + nextFFTBlockReady = false; + } } void PlayerWindow::updateShader() { - m_GLSLCompo.setShaderProgramFragment(StaticValues::getShaderCache()); + m_GLSLCompo.setShaderProgramFragment (StaticValues::getShaderCache()); } -void PlayerWindow::setMidiCCValue(juce::MidiMessage midiCC) +void PlayerWindow::setMidiCCValue (juce::MidiMessage midiCC) { - m_midiCCqueue.push(midiCC); + m_midiCCqueue.push (midiCC); } void PlayerWindow::sendMidiCCValue() { - while (!m_midiCCqueue.empty()) - { - juce::MidiMessage midiCC = m_midiCCqueue.front(); - m_midiCCqueue.pop(); - m_GLSLCompo.setMidiCCValue(midiCC.getControllerNumber(), midiCC.getControllerValue()); - } + while (! m_midiCCqueue.empty()) + { + juce::MidiMessage midiCC = m_midiCCqueue.front(); + m_midiCCqueue.pop(); + m_GLSLCompo.setMidiCCValue (midiCC.getControllerNumber(), midiCC.getControllerValue()); + } } -void PlayerWindow::pushNextSampleIntoFifo(float sample) noexcept +void PlayerWindow::pushNextSampleIntoFifo (float sample) noexcept { - // if the fifo contains enough data, set a flag to say - // that the next line should now be rendered.. - if (fifoIndex == fftSize) - { - if (!nextWaveBlockReady) - { - zeromem(waveData, sizeof(waveData)); - memcpy(waveData, fifo, sizeof(fifo)); - nextWaveBlockReady = true; - } - - if (!nextFFTBlockReady) - { - zeromem(fftData, sizeof(fftData)); - memcpy(fftData, fifo, sizeof(fifo)); - nextFFTBlockReady = true; - } - - fifoIndex = 0; - } - - fifo[fifoIndex++] = sample; + // if the fifo contains enough data, set a flag to say + // that the next line should now be rendered.. + if (fifoIndex == fftSize) + { + if (! nextWaveBlockReady) + { + zeromem (waveData, sizeof (waveData)); + memcpy (waveData, fifo, sizeof (fifo)); + nextWaveBlockReady = true; + } + + if (! nextFFTBlockReady) + { + zeromem (fftData, sizeof (fftData)); + memcpy (fftData, fifo, sizeof (fifo)); + nextFFTBlockReady = true; + } + + fifoIndex = 0; + } + + fifo[fifoIndex++] = sample; } void PlayerWindow::sendNextSpectrum() { - // then render our FFT data.. - forwardFFT.performFrequencyOnlyForwardTransform(fftData); - - // find the range of values produced, so we can scale our rendering to - // show up the detail clearly - for (int i = 0; i < fftSize; i++) - { - auto spectrumVal = fftData[i]; - m_GLSLCompo.setSpectrumValue(i, spectrumVal * spectrumVal); - } + // then render our FFT data.. + forwardFFT.performFrequencyOnlyForwardTransform (fftData); + + // find the range of values produced, so we can scale our rendering to + // show up the detail clearly + for (int i = 0; i < fftSize; i++) + { + auto spectrumVal = fftData[i]; + m_GLSLCompo.setSpectrumValue (i, spectrumVal * spectrumVal); + } } void PlayerWindow::sendNextWave() { - for (int i = 0; i < fftSize; i++) - { - m_GLSLCompo.setWaveValue(i, waveData[i]); - } + for (int i = 0; i < fftSize; i++) + { + m_GLSLCompo.setWaveValue (i, waveData[i]); + } } diff --git a/GLSLPlugIn/Source/PlayerWindow.h b/GLSLPlugIn/Source/PlayerWindow.h index 3664f03..8a619bf 100644 --- a/GLSLPlugIn/Source/PlayerWindow.h +++ b/GLSLPlugIn/Source/PlayerWindow.h @@ -20,60 +20,63 @@ This class implements the desktop window that contains an instance of our MainContentComponent class. */ class PlayerWindow : public DocumentWindow, - public KeyListener, - private Timer + public KeyListener, + private Timer { public: - PlayerWindow(String name); - ~PlayerWindow(); + PlayerWindow (String name); + ~PlayerWindow(); - //============================================================================== - /* Note: Be careful if you override any DocumentWindow methods - the base + //============================================================================== + /* Note: Be careful if you override any DocumentWindow methods - the base class uses a lot of them, so by overriding you might break its functionality. It's best to do all your work in your content component instead, but if you really have to override any DocumentWindow methods, make sure your subclass also calls the superclass's method. */ - void closeButtonPressed() override; - void maximiseButtonPressed() override; - bool keyPressed(const KeyPress& key, Component* originatingComponent) override; + void closeButtonPressed() override; + void maximiseButtonPressed() override; + bool keyPressed (const KeyPress& key, Component* originatingComponent) override; - void updateShader(); - void timerCallback() override; - void setMidiCCValue(juce::MidiMessage midiCC); + void updateShader(); + void timerCallback() override; + void setMidiCCValue (juce::MidiMessage midiCC); - enum - { - fftOrder = 9, - fftSize = 1 << fftOrder - }; + enum + { + fftOrder = 9, + fftSize = 1 << fftOrder + }; - void pushNextSampleIntoFifo(float sample) noexcept; + void pushNextSampleIntoFifo (float sample) noexcept; private: - const int TITLEBAR_HEIGHT = 26; - GLSLComponent m_GLSLCompo; - - enum { shaderLinkDelay = 500 }; - - std::queue m_midiCCqueue; - void sendMidiCCValue(); - void sendNextSpectrum(); - void sendNextWave(); - - // FFT - dsp::FFT forwardFFT; - float fifo[fftSize]; - float fftData[2 * fftSize]; - int fifoIndex; - bool nextFFTBlockReady; - - // Wave - bool nextWaveBlockReady; - float waveData[fftSize]; - - bool isCodeEditorShow = true; - bool isNeedShaderCompile = false; - - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PlayerWindow) + const int TITLEBAR_HEIGHT = 26; + GLSLComponent m_GLSLCompo; + + enum + { + shaderLinkDelay = 500 + }; + + std::queue m_midiCCqueue; + void sendMidiCCValue(); + void sendNextSpectrum(); + void sendNextWave(); + + // FFT + dsp::FFT forwardFFT; + float fifo[fftSize]; + float fftData[2 * fftSize]; + int fifoIndex; + bool nextFFTBlockReady; + + // Wave + bool nextWaveBlockReady; + float waveData[fftSize]; + + bool isCodeEditorShow = true; + bool isNeedShaderCompile = false; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PlayerWindow) }; diff --git a/GLSLPlugIn/Source/PluginEditor.cpp b/GLSLPlugIn/Source/PluginEditor.cpp index 4270fa7..2166ae8 100644 --- a/GLSLPlugIn/Source/PluginEditor.cpp +++ b/GLSLPlugIn/Source/PluginEditor.cpp @@ -14,332 +14,331 @@ //============================================================================== GlslplugInAudioProcessorEditor::GlslplugInAudioProcessorEditor (GlslplugInAudioProcessor& p) - : AudioProcessorEditor (&p), processor (p), - fragmentEditorComp(fragmentDocument, nullptr), - forwardFFT(fftOrder), - fifoIndex(0), - nextFFTBlockReady(false) + : AudioProcessorEditor (&p), processor (p), fragmentEditorComp (fragmentDocument, nullptr), forwardFFT (fftOrder), fifoIndex (0), nextFFTBlockReady (false) { // Make sure that before the constructor has finished, you've set the // editor's size to whatever you need it to be. setSize (wndFullSizeW, wndFullSizeH); - getTopLevelComponent()->addKeyListener(this); - - m_GLSLCompo.setStatusLabelPtr(&m_statusLabel); - m_GLSLCompo.setFragmentDocPtr(&fragmentDocument); - addAndMakeVisible(m_GLSLCompo); - - Colour editorBackground(Colours::darkgrey); - Colour editorForeground(Colours::white); - - Colour windowBackground(Colours::darkcyan); - Colour windowForeground(Colours::white); - - fragmentEditorComp.setColour(CodeEditorComponent::backgroundColourId, editorBackground); - fragmentEditorComp.setColour(CodeEditorComponent::defaultTextColourId, editorForeground); - fragmentDocument.addListener(this); - addAndMakeVisible(fragmentEditorComp); - - m_statusLabel.setJustificationType(Justification::topLeft); - m_statusLabel.setColour(Label::backgroundColourId, windowBackground); - m_statusLabel.setColour(Label::textColourId, windowForeground); - m_statusLabel.setFont(Font(14.0f)); - addAndMakeVisible(m_statusLabel); - - m_SyncModeSwitch.setToggleState(false, dontSendNotification); - m_SyncModeSwitch.setColour(Label::backgroundColourId, windowBackground); - m_SyncModeSwitch.setColour(Label::textColourId, windowForeground); - m_SyncModeSwitch.setButtonText("Auto Sync"); - m_SyncModeSwitch.setName("AUTO_MODE"); - m_SyncModeSwitch.addListener(this); - addAndMakeVisible(m_SyncModeSwitch); - - m_SyncButton.setColour(Label::backgroundColourId, Colours::darkmagenta); - m_SyncButton.setColour(Label::textColourId, Colours::white); - m_SyncButton.setButtonText("Sync Player"); - m_SyncButton.setName("SYNC"); - m_SyncButton.addListener(this); - addAndMakeVisible(m_SyncButton); - - m_PlayWndButton.setColour(Label::backgroundColourId, Colours::darkmagenta); - m_PlayWndButton.setColour(Label::textColourId, Colours::white); - m_PlayWndButton.setButtonText("Player Window"); - m_PlayWndButton.setName("PLAY_WND"); - m_PlayWndButton.addListener(this); - addAndMakeVisible(m_PlayWndButton); - - fragmentDocument.replaceAllContent(GLSLComponent::defaultFragmentShader); - - startTimer(shaderLinkDelay); + getTopLevelComponent()->addKeyListener (this); + + m_GLSLCompo.setStatusLabelPtr (&m_statusLabel); + m_GLSLCompo.setFragmentDocPtr (&fragmentDocument); + addAndMakeVisible (m_GLSLCompo); + + Colour editorBackground (Colours::darkgrey); + Colour editorForeground (Colours::white); + + Colour windowBackground (Colours::darkcyan); + Colour windowForeground (Colours::white); + + fragmentEditorComp.setColour (CodeEditorComponent::backgroundColourId, editorBackground); + fragmentEditorComp.setColour (CodeEditorComponent::defaultTextColourId, editorForeground); + fragmentDocument.addListener (this); + addAndMakeVisible (fragmentEditorComp); + + m_statusLabel.setJustificationType (Justification::topLeft); + m_statusLabel.setColour (Label::backgroundColourId, windowBackground); + m_statusLabel.setColour (Label::textColourId, windowForeground); + m_statusLabel.setFont (Font (14.0f)); + addAndMakeVisible (m_statusLabel); + + m_SyncModeSwitch.setToggleState (false, dontSendNotification); + m_SyncModeSwitch.setColour (Label::backgroundColourId, windowBackground); + m_SyncModeSwitch.setColour (Label::textColourId, windowForeground); + m_SyncModeSwitch.setButtonText ("Auto Sync"); + m_SyncModeSwitch.setName ("AUTO_MODE"); + m_SyncModeSwitch.addListener (this); + addAndMakeVisible (m_SyncModeSwitch); + + m_SyncButton.setColour (Label::backgroundColourId, Colours::darkmagenta); + m_SyncButton.setColour (Label::textColourId, Colours::white); + m_SyncButton.setButtonText ("Sync Player"); + m_SyncButton.setName ("SYNC"); + m_SyncButton.addListener (this); + addAndMakeVisible (m_SyncButton); + + m_PlayWndButton.setColour (Label::backgroundColourId, Colours::darkmagenta); + m_PlayWndButton.setColour (Label::textColourId, Colours::white); + m_PlayWndButton.setButtonText ("Player Window"); + m_PlayWndButton.setName ("PLAY_WND"); + m_PlayWndButton.addListener (this); + addAndMakeVisible (m_PlayWndButton); + + fragmentDocument.replaceAllContent (GLSLComponent::defaultFragmentShader); + + startTimer (shaderLinkDelay); } GlslplugInAudioProcessorEditor::~GlslplugInAudioProcessorEditor() { - stopTimer(); + stopTimer(); } //============================================================================== void GlslplugInAudioProcessorEditor::paint (Graphics& g) { - g.fillAll(Colours::darkcyan); + g.fillAll (Colours::darkcyan); } void GlslplugInAudioProcessorEditor::resized() { - Rectangle area(getLocalBounds().reduced(4)); - Rectangle bottom(area.removeFromBottom(75)); + Rectangle area (getLocalBounds().reduced (4)); + Rectangle bottom (area.removeFromBottom (75)); // This is generally where you'll want to lay out the positions of any // subcomponents in your editor.. - int glSide = wndFullSizeH; - int glBottom = wndFullSizeH; - m_GLSLCompo.setBounds(0, 0, glSide, glBottom); - - int editorBottom = wndFullSizeH - 80; - int editorSide = wndFullSizeW - wndFullSizeH; - - switch (m_guiState) - { - case GUIState::Default: - fragmentEditorComp.setBounds(glSide, 0, editorSide, editorBottom); - m_statusLabel.setBounds(glSide, editorBottom, editorSide, 60); - m_SyncModeSwitch.setBounds(glSide, editorBottom + 60, 108, 20); - m_SyncButton.setBounds(glSide + 108, editorBottom + 60, 170, 20); - m_PlayWndButton.setBounds(glSide + 278, editorBottom + 60, 170, 20); - m_GLSLCompo.setVisible(true); - fragmentEditorComp.setVisible(true); - m_SyncModeSwitch.setVisible(true); - m_SyncButton.setVisible(true); - m_PlayWndButton.setVisible(true); - m_statusLabel.setVisible(true); - this->setSize(wndFullSizeW, wndFullSizeH); - break; - - case GUIState::EditorOnly: - fragmentEditorComp.setBounds(0, 0, wndFullSizeW, editorBottom); - m_statusLabel.setBounds(0, editorBottom, wndFullSizeW, 60); - m_SyncModeSwitch.setBounds(glSide, editorBottom + 60, 108, 20); - m_SyncButton.setBounds(glSide + 108, editorBottom + 60, 170, 20); - m_PlayWndButton.setBounds(glSide + 278, editorBottom + 60, 170, 20); - m_GLSLCompo.setVisible(false); - fragmentEditorComp.setVisible(true); - m_SyncModeSwitch.setVisible(true); - m_SyncButton.setVisible(true); - m_PlayWndButton.setVisible(true); - m_statusLabel.setVisible(true); - this->setSize(wndFullSizeW, wndFullSizeH); - break; - - case GUIState::PreviewOnly: - fragmentEditorComp.setBounds(glSide, 0, editorSide, editorBottom); - m_statusLabel.setBounds(glSide, editorBottom, editorSide, 60); - m_SyncModeSwitch.setBounds(glSide, editorBottom + 60, 108, 20); - m_SyncButton.setBounds(glSide + 108, editorBottom + 60, 170, 20); - m_PlayWndButton.setBounds(glSide + 278, editorBottom + 60, 170, 20); - m_GLSLCompo.setVisible(true); - fragmentEditorComp.setVisible(false); - m_SyncModeSwitch.setVisible(false); - m_SyncButton.setVisible(false); - m_PlayWndButton.setVisible(false); - m_statusLabel.setVisible(false); - this->setSize(glSide, glBottom); - break; - } + int glSide = wndFullSizeH; + int glBottom = wndFullSizeH; + m_GLSLCompo.setBounds (0, 0, glSide, glBottom); + + int editorBottom = wndFullSizeH - 80; + int editorSide = wndFullSizeW - wndFullSizeH; + + switch (m_guiState) + { + case GUIState::Default: + fragmentEditorComp.setBounds (glSide, 0, editorSide, editorBottom); + m_statusLabel.setBounds (glSide, editorBottom, editorSide, 60); + m_SyncModeSwitch.setBounds (glSide, editorBottom + 60, 108, 20); + m_SyncButton.setBounds (glSide + 108, editorBottom + 60, 170, 20); + m_PlayWndButton.setBounds (glSide + 278, editorBottom + 60, 170, 20); + m_GLSLCompo.setVisible (true); + fragmentEditorComp.setVisible (true); + m_SyncModeSwitch.setVisible (true); + m_SyncButton.setVisible (true); + m_PlayWndButton.setVisible (true); + m_statusLabel.setVisible (true); + this->setSize (wndFullSizeW, wndFullSizeH); + break; + + case GUIState::EditorOnly: + fragmentEditorComp.setBounds (0, 0, wndFullSizeW, editorBottom); + m_statusLabel.setBounds (0, editorBottom, wndFullSizeW, 60); + m_SyncModeSwitch.setBounds (glSide, editorBottom + 60, 108, 20); + m_SyncButton.setBounds (glSide + 108, editorBottom + 60, 170, 20); + m_PlayWndButton.setBounds (glSide + 278, editorBottom + 60, 170, 20); + m_GLSLCompo.setVisible (false); + fragmentEditorComp.setVisible (true); + m_SyncModeSwitch.setVisible (true); + m_SyncButton.setVisible (true); + m_PlayWndButton.setVisible (true); + m_statusLabel.setVisible (true); + this->setSize (wndFullSizeW, wndFullSizeH); + break; + + case GUIState::PreviewOnly: + fragmentEditorComp.setBounds (glSide, 0, editorSide, editorBottom); + m_statusLabel.setBounds (glSide, editorBottom, editorSide, 60); + m_SyncModeSwitch.setBounds (glSide, editorBottom + 60, 108, 20); + m_SyncButton.setBounds (glSide + 108, editorBottom + 60, 170, 20); + m_PlayWndButton.setBounds (glSide + 278, editorBottom + 60, 170, 20); + m_GLSLCompo.setVisible (true); + fragmentEditorComp.setVisible (false); + m_SyncModeSwitch.setVisible (false); + m_SyncButton.setVisible (false); + m_PlayWndButton.setVisible (false); + m_statusLabel.setVisible (false); + this->setSize (glSide, glBottom); + break; + } } //============================================================================== void GlslplugInAudioProcessorEditor::timerCallback() { - if (isNeedShaderCompile) - { - isNeedShaderCompile = false; - - stopTimer(); - - StaticValues::setShaderCache(fragmentDocument.getAllContent()); - - if (m_GLSLCompo.isInitialised) - m_GLSLCompo.setShaderProgramFragment(StaticValues::getShaderCache()); - - if(isShaderSyncAuto) - setShaderSync(); - - startTimer(20); - } - - // MIDI CC - if (!m_midiCCqueue.empty()) { - sendMidiCCValue(); - } - - // Wave - if (nextWaveBlockReady) - { - sendNextWave(); - nextWaveBlockReady = false; - } - - // FFT - if (nextFFTBlockReady) - { - sendNextSpectrum(); - nextFFTBlockReady = false; - } + if (isNeedShaderCompile) + { + isNeedShaderCompile = false; + + stopTimer(); + + StaticValues::setShaderCache (fragmentDocument.getAllContent()); + + if (m_GLSLCompo.isInitialised) + m_GLSLCompo.setShaderProgramFragment (StaticValues::getShaderCache()); + + if (isShaderSyncAuto) + setShaderSync(); + + startTimer (20); + } + + // MIDI CC + if (! m_midiCCqueue.empty()) + { + sendMidiCCValue(); + } + + // Wave + if (nextWaveBlockReady) + { + sendNextWave(); + nextWaveBlockReady = false; + } + + // FFT + if (nextFFTBlockReady) + { + sendNextSpectrum(); + nextFFTBlockReady = false; + } } -void GlslplugInAudioProcessorEditor::codeDocumentTextInserted(const String& /*newText*/, int /*insertIndex*/) +void GlslplugInAudioProcessorEditor::codeDocumentTextInserted (const String& /*newText*/, int /*insertIndex*/) { - startTimer(shaderLinkDelay); - isNeedShaderCompile = true; + startTimer (shaderLinkDelay); + isNeedShaderCompile = true; } -void GlslplugInAudioProcessorEditor::codeDocumentTextDeleted(int /*startIndex*/, int /*endIndex*/) +void GlslplugInAudioProcessorEditor::codeDocumentTextDeleted (int /*startIndex*/, int /*endIndex*/) { - startTimer(shaderLinkDelay); - isNeedShaderCompile = true; + startTimer (shaderLinkDelay); + isNeedShaderCompile = true; } -void GlslplugInAudioProcessorEditor::setMidiCCValue(juce::MidiMessage midiCC) +void GlslplugInAudioProcessorEditor::setMidiCCValue (juce::MidiMessage midiCC) { - m_midiCCqueue.push(midiCC); + m_midiCCqueue.push (midiCC); } void GlslplugInAudioProcessorEditor::sendMidiCCValue() { - while (!m_midiCCqueue.empty()) - { - juce::MidiMessage midiCC = m_midiCCqueue.front(); - m_midiCCqueue.pop(); - if (m_GLSLCompo.isInitialised) - m_GLSLCompo.setMidiCCValue(midiCC.getControllerNumber(), midiCC.getControllerValue()); - } + while (! m_midiCCqueue.empty()) + { + juce::MidiMessage midiCC = m_midiCCqueue.front(); + m_midiCCqueue.pop(); + if (m_GLSLCompo.isInitialised) + m_GLSLCompo.setMidiCCValue (midiCC.getControllerNumber(), midiCC.getControllerValue()); + } } -void GlslplugInAudioProcessorEditor::pushNextSampleIntoFifo(float sample) noexcept +void GlslplugInAudioProcessorEditor::pushNextSampleIntoFifo (float sample) noexcept { - // if the fifo contains enough data, set a flag to say - // that the next line should now be rendered.. - if (fifoIndex == fftSize) - { - if (!nextWaveBlockReady) - { - zeromem(waveData, sizeof(waveData)); - memcpy(waveData, fifo, sizeof(fifo)); - nextWaveBlockReady = true; - } - - if (!nextFFTBlockReady) - { - zeromem(fftData, sizeof(fftData)); - memcpy(fftData, fifo, sizeof(fifo)); - nextFFTBlockReady = true; - } - - fifoIndex = 0; - } - - fifo[fifoIndex++] = sample; + // if the fifo contains enough data, set a flag to say + // that the next line should now be rendered.. + if (fifoIndex == fftSize) + { + if (! nextWaveBlockReady) + { + zeromem (waveData, sizeof (waveData)); + memcpy (waveData, fifo, sizeof (fifo)); + nextWaveBlockReady = true; + } + + if (! nextFFTBlockReady) + { + zeromem (fftData, sizeof (fftData)); + memcpy (fftData, fifo, sizeof (fifo)); + nextFFTBlockReady = true; + } + + fifoIndex = 0; + } + + fifo[fifoIndex++] = sample; } void GlslplugInAudioProcessorEditor::setShaderSync() { - StaticValues::setNeedShaderSync(true); + StaticValues::setNeedShaderSync (true); } void GlslplugInAudioProcessorEditor::sendNextSpectrum() { - // then render our FFT data.. - forwardFFT.performFrequencyOnlyForwardTransform(fftData); - - // find the range of values produced, so we can scale our rendering to - // show up the detail clearly - for (int i = 0; i < fftSize; i++) - { - auto spectrumVal = fftData[i]; - if (m_GLSLCompo.isInitialised) - m_GLSLCompo.setSpectrumValue(i, spectrumVal * spectrumVal); - } + // then render our FFT data.. + forwardFFT.performFrequencyOnlyForwardTransform (fftData); + + // find the range of values produced, so we can scale our rendering to + // show up the detail clearly + for (int i = 0; i < fftSize; i++) + { + auto spectrumVal = fftData[i]; + if (m_GLSLCompo.isInitialised) + m_GLSLCompo.setSpectrumValue (i, spectrumVal * spectrumVal); + } } -void GlslplugInAudioProcessorEditor::sendNextWave() +void GlslplugInAudioProcessorEditor::sendNextWave() { - for (int i = 0; i < fftSize; i++) - { - if (m_GLSLCompo.isInitialised) - m_GLSLCompo.setWaveValue(i, waveData[i]); - } + for (int i = 0; i < fftSize; i++) + { + if (m_GLSLCompo.isInitialised) + m_GLSLCompo.setWaveValue (i, waveData[i]); + } } -bool GlslplugInAudioProcessorEditor::keyPressed(const KeyPress& key, Component* originatingComponent) +bool GlslplugInAudioProcessorEditor::keyPressed (const KeyPress& key, Component* originatingComponent) { - //m_statusLabel.setText(m_statusLabel.getText() + "keyCode:" + String(key.getKeyCode()) + "/keyChar:" + String(key.getTextCharacter()), dontSendNotification); - - if (key.getModifiers() == ModifierKeys::ctrlModifier) - { - if (key.getKeyCode() == 75) // "k" - { - switch (m_guiState) - { - case GUIState::Default: - m_guiState = GUIState::PreviewOnly; - break; - case GUIState::EditorOnly: - break; - case GUIState::PreviewOnly: - m_guiState = GUIState::Default; - break; - } - this->resized(); - } - if (key.getKeyCode() == 80) // "p" - { - switch (m_guiState) - { - case GUIState::Default: - m_guiState = GUIState::EditorOnly; - break; - case GUIState::EditorOnly: - m_guiState = GUIState::Default; - break; - case GUIState::PreviewOnly: - break; - } - this->resized(); - } - if (key.getKeyCode() == 43 || key.getKeyCode() == 59) // "+ or ;" - { - auto fs = fragmentEditorComp.getFont(); - if (fs.getHeight() < 52) { - fragmentEditorComp.setFont(Font(fs.getHeight() + 1.0f)); - } - } - if (key.getKeyCode() == 45) // "-" - { - auto fs = fragmentEditorComp.getFont(); - if (fs.getHeight() > 7) { - fragmentEditorComp.setFont(Font(fs.getHeight() - 1.0f)); - } - } - } - return true; + //m_statusLabel.setText(m_statusLabel.getText() + "keyCode:" + String(key.getKeyCode()) + "/keyChar:" + String(key.getTextCharacter()), dontSendNotification); + + if (key.getModifiers() == ModifierKeys::ctrlModifier) + { + if (key.getKeyCode() == 75) // "k" + { + switch (m_guiState) + { + case GUIState::Default: + m_guiState = GUIState::PreviewOnly; + break; + case GUIState::EditorOnly: + break; + case GUIState::PreviewOnly: + m_guiState = GUIState::Default; + break; + } + this->resized(); + } + if (key.getKeyCode() == 80) // "p" + { + switch (m_guiState) + { + case GUIState::Default: + m_guiState = GUIState::EditorOnly; + break; + case GUIState::EditorOnly: + m_guiState = GUIState::Default; + break; + case GUIState::PreviewOnly: + break; + } + this->resized(); + } + if (key.getKeyCode() == 43 || key.getKeyCode() == 59) // "+ or ;" + { + auto fs = fragmentEditorComp.getFont(); + if (fs.getHeight() < 52) + { + fragmentEditorComp.setFont (Font (fs.getHeight() + 1.0f)); + } + } + if (key.getKeyCode() == 45) // "-" + { + auto fs = fragmentEditorComp.getFont(); + if (fs.getHeight() > 7) + { + fragmentEditorComp.setFont (Font (fs.getHeight() - 1.0f)); + } + } + } + return true; } -void GlslplugInAudioProcessorEditor::buttonClicked(Button* _button) +void GlslplugInAudioProcessorEditor::buttonClicked (Button* _button) { - if (_button->getName() == "SYNC") - { - setShaderSync(); - } - if (_button->getName() == "AUTO_MODE") - { - isShaderSyncAuto = _button->getToggleState(); - setShaderSync(); - } - if (_button->getName() == "PLAY_WND") - { - if (processor.existPlayerWindow()) - processor.deletePlayerWindow(); - else - processor.createPlayerWindow(); - } + if (_button->getName() == "SYNC") + { + setShaderSync(); + } + if (_button->getName() == "AUTO_MODE") + { + isShaderSyncAuto = _button->getToggleState(); + setShaderSync(); + } + if (_button->getName() == "PLAY_WND") + { + if (processor.existPlayerWindow()) + processor.deletePlayerWindow(); + else + processor.createPlayerWindow(); + } } diff --git a/GLSLPlugIn/Source/PluginEditor.h b/GLSLPlugIn/Source/PluginEditor.h index ff339e5..377f6ef 100644 --- a/GLSLPlugIn/Source/PluginEditor.h +++ b/GLSLPlugIn/Source/PluginEditor.h @@ -17,11 +17,11 @@ //============================================================================== /** */ -class GlslplugInAudioProcessorEditor : public AudioProcessorEditor, - public CodeDocument::Listener, - public KeyListener, - public Button::Listener, - private Timer +class GlslplugInAudioProcessorEditor : public AudioProcessorEditor, + public CodeDocument::Listener, + public KeyListener, + public Button::Listener, + private Timer { public: GlslplugInAudioProcessorEditor (GlslplugInAudioProcessor&); @@ -30,69 +30,72 @@ class GlslplugInAudioProcessorEditor : public AudioProcessorEditor, //============================================================================== void paint (Graphics&) override; void resized() override; - void timerCallback() override; - void setMidiCCValue(juce::MidiMessage midiCC); - void setShaderSync(); - void pushNextSampleIntoFifo(float sample) noexcept; + void timerCallback() override; + void setMidiCCValue (juce::MidiMessage midiCC); + void setShaderSync(); + void pushNextSampleIntoFifo (float sample) noexcept; - GlslplugInAudioProcessor& processor; + GlslplugInAudioProcessor& processor; private: // This reference is provided as a quick way for your editor to // access the processor object that created it. - GLSLComponent m_GLSLCompo; - Label m_statusLabel; - CodeDocument /*vertexDocument,*/ fragmentDocument; - CodeEditorComponent /*vertexEditorComp,*/ fragmentEditorComp; - ToggleButton m_SyncModeSwitch; - TextButton m_SyncButton; - TextButton m_PlayWndButton; - - enum { shaderLinkDelay = 500 }; - enum - { - fftOrder = 9, - fftSize = 1 << fftOrder - }; - void codeDocumentTextInserted(const String& /*newText*/, int /*insertIndex*/) override; - void codeDocumentTextDeleted(int /*startIndex*/, int /*endIndex*/) override; - - std::queue m_midiCCqueue; - void sendMidiCCValue(); - void sendNextSpectrum(); - void sendNextWave(); - - // FFT + GLSLComponent m_GLSLCompo; + Label m_statusLabel; + CodeDocument /*vertexDocument,*/ fragmentDocument; + CodeEditorComponent /*vertexEditorComp,*/ fragmentEditorComp; + ToggleButton m_SyncModeSwitch; + TextButton m_SyncButton; + TextButton m_PlayWndButton; + + enum + { + shaderLinkDelay = 500 + }; + enum + { + fftOrder = 9, + fftSize = 1 << fftOrder + }; + void codeDocumentTextInserted (const String& /*newText*/, int /*insertIndex*/) override; + void codeDocumentTextDeleted (int /*startIndex*/, int /*endIndex*/) override; + + std::queue m_midiCCqueue; + void sendMidiCCValue(); + void sendNextSpectrum(); + void sendNextWave(); + + // FFT dsp::FFT forwardFFT; - float fifo[fftSize]; - float fftData[2 * fftSize]; - int fifoIndex; - bool nextFFTBlockReady; - - // Wave - bool nextWaveBlockReady; - float waveData[fftSize]; - - // KeyListener - //bool keyPressed(const KeyPress& key) override; - bool keyPressed(const KeyPress& key, Component* originatingComponent) override; - - /** Called when the button is clicked. */ - virtual void buttonClicked(Button*) override; - - bool isShaderSyncAuto = false; - bool isNeedShaderCompile = false; - - int wndFullSizeW = 1024; - int wndFullSizeH = 576; - - enum GUIState { - Default, - PreviewOnly, - EditorOnly, - }; - GUIState m_guiState = GUIState::Default; - + float fifo[fftSize]; + float fftData[2 * fftSize]; + int fifoIndex; + bool nextFFTBlockReady; + + // Wave + bool nextWaveBlockReady; + float waveData[fftSize]; + + // KeyListener + //bool keyPressed(const KeyPress& key) override; + bool keyPressed (const KeyPress& key, Component* originatingComponent) override; + + /** Called when the button is clicked. */ + virtual void buttonClicked (Button*) override; + + bool isShaderSyncAuto = false; + bool isNeedShaderCompile = false; + + int wndFullSizeW = 1024; + int wndFullSizeH = 576; + + enum GUIState + { + Default, + PreviewOnly, + EditorOnly, + }; + GUIState m_guiState = GUIState::Default; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlslplugInAudioProcessorEditor) }; diff --git a/GLSLPlugIn/Source/PluginProcessor.cpp b/GLSLPlugIn/Source/PluginProcessor.cpp index f58b02c..3311b6e 100644 --- a/GLSLPlugIn/Source/PluginProcessor.cpp +++ b/GLSLPlugIn/Source/PluginProcessor.cpp @@ -14,34 +14,34 @@ //============================================================================== GlslplugInAudioProcessor::GlslplugInAudioProcessor() #ifndef JucePlugin_PreferredChannelConfigurations - : AudioProcessor (BusesProperties() - #if ! JucePlugin_IsMidiEffect - #if ! JucePlugin_IsSynth - .withInput ("Input", AudioChannelSet::stereo(), true) - #endif - .withOutput ("Output", AudioChannelSet::stereo(), true) - #endif - ) + : AudioProcessor (BusesProperties() +#if ! JucePlugin_IsMidiEffect +#if ! JucePlugin_IsSynth + .withInput ("Input", AudioChannelSet::stereo(), true) +#endif + .withOutput ("Output", AudioChannelSet::stereo(), true) +#endif + ) #endif { - StaticValues::setShaderCache(""); - StaticValues::setShaderCacheReady(false); + StaticValues::setShaderCache (""); + StaticValues::setShaderCacheReady (false); } GlslplugInAudioProcessor::~GlslplugInAudioProcessor() { - delete playerWindow; // (deletes our window) + delete playerWindow; // (deletes our window) } void GlslplugInAudioProcessor::createPlayerWindow() { - playerWindow = new PlayerWindow("GLSL Player"); + playerWindow = new PlayerWindow ("GLSL Player"); } void GlslplugInAudioProcessor::deletePlayerWindow() { - delete playerWindow; - playerWindow = nullptr; + delete playerWindow; + playerWindow = nullptr; } //============================================================================== @@ -52,20 +52,20 @@ const String GlslplugInAudioProcessor::getName() const bool GlslplugInAudioProcessor::acceptsMidi() const { - #if JucePlugin_WantsMidiInput +#if JucePlugin_WantsMidiInput return true; - #else +#else return false; - #endif +#endif } bool GlslplugInAudioProcessor::producesMidi() const { - #if JucePlugin_ProducesMidiOutput +#if JucePlugin_ProducesMidiOutput return true; - #else +#else return false; - #endif +#endif } double GlslplugInAudioProcessor::getTailLengthSeconds() const @@ -75,8 +75,8 @@ double GlslplugInAudioProcessor::getTailLengthSeconds() const int GlslplugInAudioProcessor::getNumPrograms() { - return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs, - // so this should be at least 1, even if you're not really implementing programs. + return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs, + // so this should be at least 1, even if you're not really implementing programs. } int GlslplugInAudioProcessor::getCurrentProgram() @@ -113,61 +113,61 @@ void GlslplugInAudioProcessor::releaseResources() #ifndef JucePlugin_PreferredChannelConfigurations bool GlslplugInAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const { - #if JucePlugin_IsMidiEffect +#if JucePlugin_IsMidiEffect ignoreUnused (layouts); return true; - #else +#else // This is the place where you check if the layout is supported. // In this template code we only support mono or stereo. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono() - && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo()) + && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo()) return false; - // This checks if the input layout matches the output layout - #if ! JucePlugin_IsSynth + // This checks if the input layout matches the output layout +#if ! JucePlugin_IsSynth if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet()) return false; - #endif +#endif return true; - #endif +#endif } #endif void GlslplugInAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { - auto editor = static_cast(getActiveEditor()); - - /////////////////////////////////////////////////////////// - int time; - MidiMessage m; - - for (MidiBuffer::Iterator i(midiMessages); i.getNextEvent(m, time);) - { - if (m.isNoteOn()) - { - } - else if (m.isNoteOff()) - { - } - else if (m.isAftertouch()) - { - } - else if (m.isPitchWheel()) - { - } - else if (m.isController()) - { - if(editor != nullptr) - editor->setMidiCCValue(m); - - if (playerWindow != nullptr) - playerWindow->setMidiCCValue(m); - } - } - - /////////////////////////////////////////////////////////// - const int totalNumInputChannels = getTotalNumInputChannels(); + auto editor = static_cast (getActiveEditor()); + + /////////////////////////////////////////////////////////// + int time; + MidiMessage m; + + for (MidiBuffer::Iterator i (midiMessages); i.getNextEvent (m, time);) + { + if (m.isNoteOn()) + { + } + else if (m.isNoteOff()) + { + } + else if (m.isAftertouch()) + { + } + else if (m.isPitchWheel()) + { + } + else if (m.isController()) + { + if (editor != nullptr) + editor->setMidiCCValue (m); + + if (playerWindow != nullptr) + playerWindow->setMidiCCValue (m); + } + } + + /////////////////////////////////////////////////////////// + const int totalNumInputChannels = getTotalNumInputChannels(); const int totalNumOutputChannels = getTotalNumOutputChannels(); // In case we have more outputs than inputs, this code clears any output @@ -186,20 +186,20 @@ void GlslplugInAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuff float* channelData = buffer.getWritePointer (channel); // ..do something to the data... - if (channel == 0) - { - if (editor != nullptr) - { - for (int i = 0; i < buffer.getNumSamples(); ++i) - editor->pushNextSampleIntoFifo(channelData[i]); - } - - if (playerWindow != nullptr) - { - for (int i = 0; i < buffer.getNumSamples(); ++i) - playerWindow->pushNextSampleIntoFifo(channelData[i]); - } - } + if (channel == 0) + { + if (editor != nullptr) + { + for (int i = 0; i < buffer.getNumSamples(); ++i) + editor->pushNextSampleIntoFifo (channelData[i]); + } + + if (playerWindow != nullptr) + { + for (int i = 0; i < buffer.getNumSamples(); ++i) + playerWindow->pushNextSampleIntoFifo (channelData[i]); + } + } } } @@ -221,11 +221,11 @@ void GlslplugInAudioProcessor::getStateInformation (MemoryBlock& destData) // You could do that either as raw data, or use the XML or ValueTree classes // as intermediaries to make it easy to save and load complex data. - XmlElement root("Root"); - XmlElement *el; - el = root.createNewChildElement("FragmentShader"); - el->addTextElement(StaticValues::getShaderCache()); - copyXmlToBinary(root, destData); + XmlElement root ("Root"); + XmlElement* el; + el = root.createNewChildElement ("FragmentShader"); + el->addTextElement (StaticValues::getShaderCache()); + copyXmlToBinary (root, destData); } void GlslplugInAudioProcessor::setStateInformation (const void* data, int sizeInBytes) @@ -233,19 +233,19 @@ void GlslplugInAudioProcessor::setStateInformation (const void* data, int sizeIn // You should use this method to restore your parameters from this memory block, // whose contents will have been created by the getStateInformation() call. - auto pRoot = getXmlFromBinary(data, sizeInBytes); - if (pRoot != nullptr) - { - juce::XmlElement* pChild; - for (pChild = (*pRoot).getFirstChildElement(); pChild != nullptr; pChild = pChild->getNextElement() ) - { - if (pChild->hasTagName("FragmentShader")) - { - String text = pChild->getAllSubText(); - StaticValues::setShaderCache(text); - } - } - } + auto pRoot = getXmlFromBinary (data, sizeInBytes); + if (pRoot != nullptr) + { + juce::XmlElement* pChild; + for (pChild = (*pRoot).getFirstChildElement(); pChild != nullptr; pChild = pChild->getNextElement()) + { + if (pChild->hasTagName ("FragmentShader")) + { + String text = pChild->getAllSubText(); + StaticValues::setShaderCache (text); + } + } + } } //============================================================================== diff --git a/GLSLPlugIn/Source/PluginProcessor.h b/GLSLPlugIn/Source/PluginProcessor.h index 6ba140d..9e75d0b 100644 --- a/GLSLPlugIn/Source/PluginProcessor.h +++ b/GLSLPlugIn/Source/PluginProcessor.h @@ -16,7 +16,7 @@ //============================================================================== /** */ -class GlslplugInAudioProcessor : public AudioProcessor +class GlslplugInAudioProcessor : public AudioProcessor { public: //============================================================================== @@ -27,9 +27,9 @@ class GlslplugInAudioProcessor : public AudioProcessor void prepareToPlay (double sampleRate, int samplesPerBlock) override; void releaseResources() override; - #ifndef JucePlugin_PreferredChannelConfigurations +#ifndef JucePlugin_PreferredChannelConfigurations bool isBusesLayoutSupported (const BusesLayout& layouts) const override; - #endif +#endif void processBlock (AudioSampleBuffer&, MidiBuffer&) override; @@ -55,14 +55,14 @@ class GlslplugInAudioProcessor : public AudioProcessor void getStateInformation (MemoryBlock& destData) override; void setStateInformation (const void* data, int sizeInBytes) override; - void createPlayerWindow(); - void deletePlayerWindow(); - bool existPlayerWindow() { return playerWindow != nullptr; }; + void createPlayerWindow(); + void deletePlayerWindow(); + bool existPlayerWindow() { return playerWindow != nullptr; }; private: //============================================================================== - //ScopedPointer playerWindow; - PlayerWindow* playerWindow = nullptr; + //ScopedPointer playerWindow; + PlayerWindow* playerWindow = nullptr; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlslplugInAudioProcessor) }; diff --git a/GLSLPlugIn/Source/Resources/WavefrontObjParser.h b/GLSLPlugIn/Source/Resources/WavefrontObjParser.h index fdd642f..0fc676e 100644 --- a/GLSLPlugIn/Source/Resources/WavefrontObjParser.h +++ b/GLSLPlugIn/Source/Resources/WavefrontObjParser.h @@ -54,8 +54,14 @@ class WavefrontObjFile //============================================================================== typedef juce::uint32 Index; - struct Vertex { float x, y, z; }; - struct TextureCoord { float x, y; }; + struct Vertex + { + float x, y, z; + }; + struct TextureCoord + { + float x, y; + }; struct Mesh { @@ -63,12 +69,12 @@ class WavefrontObjFile Array textureCoords; Array indices; - JUCE_LEAK_DETECTOR(Mesh) + JUCE_LEAK_DETECTOR (Mesh) }; struct Material { - Material() noexcept : shininess (1.0f), refractiveIndex (0.0f) + Material() noexcept : shininess (1.0f), refractiveIndex (0.0f) { zerostruct (ambient); zerostruct (diffuse); @@ -83,11 +89,11 @@ class WavefrontObjFile float shininess, refractiveIndex; String ambientTextureName, diffuseTextureName, - specularTextureName, normalTextureName; + specularTextureName, normalTextureName; StringPairArray parameters; - JUCE_LEAK_DETECTOR(Material) + JUCE_LEAK_DETECTOR (Material) }; struct Shape @@ -96,7 +102,7 @@ class WavefrontObjFile Mesh mesh; Material material; - JUCE_LEAK_DETECTOR(Shape) + JUCE_LEAK_DETECTOR (Shape) }; OwnedArray shapes; @@ -125,7 +131,7 @@ class WavefrontObjFile int vertexIndex, textureIndex, normalIndex; - JUCE_LEAK_DETECTOR(TripleIndex) + JUCE_LEAK_DETECTOR (TripleIndex) }; struct IndexMap @@ -154,7 +160,7 @@ class WavefrontObjFile return index; } - JUCE_LEAK_DETECTOR(IndexMap) + JUCE_LEAK_DETECTOR (IndexMap) }; static float parseFloat (String::CharPointerType& t) @@ -257,7 +263,7 @@ class WavefrontObjFile return CharacterFunctions::findEndOfToken (t, CharPointer_ASCII ("/ \t"), String().getCharPointer()); } - JUCE_LEAK_DETECTOR(Face) + JUCE_LEAK_DETECTOR (Face) }; static Shape* parseFaceGroup (const Mesh& srcMesh, @@ -275,7 +281,7 @@ class WavefrontObjFile IndexMap indexMap; for (int i = 0; i < faceGroup.size(); ++i) - faceGroup.getUnchecked(i).addIndices (shape->mesh, srcMesh, indexMap); + faceGroup.getUnchecked (i).addIndices (shape->mesh, srcMesh, indexMap); return shape.release(); } @@ -293,10 +299,26 @@ class WavefrontObjFile { String::CharPointerType l = lines[lineNum].getCharPointer().findEndOfWhitespace(); - if (matchToken (l, "v")) { mesh.vertices.add (parseVertex (l)); continue; } - if (matchToken (l, "vn")) { mesh.normals.add (parseVertex (l)); continue; } - if (matchToken (l, "vt")) { mesh.textureCoords.add (parseTextureCoord (l)); continue; } - if (matchToken (l, "f")) { faceGroup.add (Face (l)); continue; } + if (matchToken (l, "v")) + { + mesh.vertices.add (parseVertex (l)); + continue; + } + if (matchToken (l, "vn")) + { + mesh.normals.add (parseVertex (l)); + continue; + } + if (matchToken (l, "vt")) + { + mesh.textureCoords.add (parseTextureCoord (l)); + continue; + } + if (matchToken (l, "f")) + { + faceGroup.add (Face (l)); + continue; + } if (matchToken (l, "usemtl")) { @@ -304,9 +326,9 @@ class WavefrontObjFile for (int i = knownMaterials.size(); --i >= 0;) { - if (knownMaterials.getReference(i).name == name) + if (knownMaterials.getReference (i).name == name) { - lastMaterial = knownMaterials.getReference(i); + lastMaterial = knownMaterials.getReference (i); break; } } @@ -355,20 +377,69 @@ class WavefrontObjFile { String::CharPointerType l (lines[i].getCharPointer().findEndOfWhitespace()); - if (matchToken (l, "newmtl")) { materials.add (material); material.name = String (l).trim(); continue; } + if (matchToken (l, "newmtl")) + { + materials.add (material); + material.name = String (l).trim(); + continue; + } - if (matchToken (l, "Ka")) { material.ambient = parseVertex (l); continue; } - if (matchToken (l, "Kd")) { material.diffuse = parseVertex (l); continue; } - if (matchToken (l, "Ks")) { material.specular = parseVertex (l); continue; } - if (matchToken (l, "Kt")) { material.transmittance = parseVertex (l); continue; } - if (matchToken (l, "Ke")) { material.emission = parseVertex (l); continue; } - if (matchToken (l, "Ni")) { material.refractiveIndex = parseFloat (l); continue; } - if (matchToken (l, "Ns")) { material.shininess = parseFloat (l); continue; } + if (matchToken (l, "Ka")) + { + material.ambient = parseVertex (l); + continue; + } + if (matchToken (l, "Kd")) + { + material.diffuse = parseVertex (l); + continue; + } + if (matchToken (l, "Ks")) + { + material.specular = parseVertex (l); + continue; + } + if (matchToken (l, "Kt")) + { + material.transmittance = parseVertex (l); + continue; + } + if (matchToken (l, "Ke")) + { + material.emission = parseVertex (l); + continue; + } + if (matchToken (l, "Ni")) + { + material.refractiveIndex = parseFloat (l); + continue; + } + if (matchToken (l, "Ns")) + { + material.shininess = parseFloat (l); + continue; + } - if (matchToken (l, "map_Ka")) { material.ambientTextureName = String (l).trim(); continue; } - if (matchToken (l, "map_Kd")) { material.diffuseTextureName = String (l).trim(); continue; } - if (matchToken (l, "map_Ks")) { material.specularTextureName = String (l).trim(); continue; } - if (matchToken (l, "map_Ns")) { material.normalTextureName = String (l).trim(); continue; } + if (matchToken (l, "map_Ka")) + { + material.ambientTextureName = String (l).trim(); + continue; + } + if (matchToken (l, "map_Kd")) + { + material.diffuseTextureName = String (l).trim(); + continue; + } + if (matchToken (l, "map_Ks")) + { + material.specularTextureName = String (l).trim(); + continue; + } + if (matchToken (l, "map_Ns")) + { + material.normalTextureName = String (l).trim(); + continue; + } StringArray tokens; tokens.addTokens (l, " \t", ""); diff --git a/GLSLPlugIn/Source/StaticValues.cpp b/GLSLPlugIn/Source/StaticValues.cpp index 95ace1a..49f7513 100644 --- a/GLSLPlugIn/Source/StaticValues.cpp +++ b/GLSLPlugIn/Source/StaticValues.cpp @@ -16,19 +16,21 @@ static bool isShaderCacheReady; static bool isNeedShaderSync; const String StaticValues::getShaderCache() { return ShaderCache; } -void StaticValues::setShaderCache(String str) { - ShaderCache = str; - isShaderCacheReady = true; +void StaticValues::setShaderCache (String str) +{ + ShaderCache = str; + isShaderCacheReady = true; } const String StaticValues::getShaderCacheVerified() { return ShaderCacheVerified; } -void StaticValues::setShaderCacheVerified(String str) { - ShaderCacheVerified = str; - isShaderCacheReady = true; +void StaticValues::setShaderCacheVerified (String str) +{ + ShaderCacheVerified = str; + isShaderCacheReady = true; } bool StaticValues::getShaderCacheReady() { return isShaderCacheReady; } -void StaticValues::setShaderCacheReady(bool b) { isShaderCacheReady = b; } +void StaticValues::setShaderCacheReady (bool b) { isShaderCacheReady = b; } -bool StaticValues::getNeedShaderSync() { return isNeedShaderSync; } -void StaticValues::setNeedShaderSync(bool b) { isNeedShaderSync = b; } \ No newline at end of file +bool StaticValues::getNeedShaderSync() { return isNeedShaderSync; } +void StaticValues::setNeedShaderSync (bool b) { isNeedShaderSync = b; } \ No newline at end of file diff --git a/GLSLPlugIn/Source/StaticValues.h b/GLSLPlugIn/Source/StaticValues.h index 4d54727..fa07ff0 100644 --- a/GLSLPlugIn/Source/StaticValues.h +++ b/GLSLPlugIn/Source/StaticValues.h @@ -15,17 +15,17 @@ class StaticValues { public: - static const String getShaderCache(); - static void setShaderCache(String str); + static const String getShaderCache(); + static void setShaderCache (String str); - static const String getShaderCacheVerified(); - static void setShaderCacheVerified(String str); + static const String getShaderCacheVerified(); + static void setShaderCacheVerified (String str); - static bool getShaderCacheReady(); - static void setShaderCacheReady(bool b); + static bool getShaderCacheReady(); + static void setShaderCacheReady (bool b); - static bool getNeedShaderSync(); - static void setNeedShaderSync(bool b); + static bool getNeedShaderSync(); + static void setNeedShaderSync (bool b); - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StaticValues) + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StaticValues) };