From 8c8ccb2a02b2bdb4b43ebb0b09f3568deda6e8b0 Mon Sep 17 00:00:00 2001 From: James Ball Date: Tue, 5 Sep 2023 22:57:29 +0100 Subject: [PATCH] Get MIDI working, and MASSIVELY speed up calculating arc length --- .gitignore | 2 ++ Source/PluginProcessor.cpp | 12 ++++-------- Source/PluginProcessor.h | 2 +- Source/parser/FileParser.h | 2 +- Source/shape/CircleArc.cpp | 7 ++++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 17616004..9c3a0ea7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +.DS_Store + # ignore JUCE **/Builds **/JuceLibraryCode diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 54c7d1a0..f0dbed2e 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -139,6 +139,8 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() for (int i = 0; i < 4; i++) { synth.addVoice(new ShapeVoice(*this)); } + + synth.addSound(defaultSound); } OscirenderAudioProcessor::~OscirenderAudioProcessor() {} @@ -373,13 +375,13 @@ void OscirenderAudioProcessor::openFile(int index) { // TODO: This should change whatever the ShapeSound is to the new index void OscirenderAudioProcessor::changeCurrentFile(int index) { - synth.clearSounds(); if (index == -1) { currentFile = -1; } if (index < 0 || index >= fileBlocks.size()) { return; } + synth.clearSounds(); synth.addSound(sounds[index]); currentFile = index; updateLuaValues(); @@ -416,14 +418,8 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer& buffer, ju auto totalNumOutputChannels = getTotalNumOutputChannels(); buffer.clear(); - midiMessages.clear(); - // TODO: Make this less hacky and more permanent - if (!playedNote) { - playedNote = true; - midiMessages.addEvent(juce::MidiMessage::noteOn(1, 60, 1.0f), 0); - } synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples()); - + midiMessages.clear(); auto* channelData = buffer.getArrayOfWritePointers(); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 16f5a180..c3704395 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -218,7 +218,7 @@ private: std::vector> allEffects; std::vector> permanentEffects; - bool playedNote = false; + ShapeSound::Ptr defaultSound = new ShapeSound(std::make_shared()); juce::Synthesiser synth; juce::SpinLock consumerLock; diff --git a/Source/parser/FileParser.h b/Source/parser/FileParser.h index 9d876680..102abf08 100644 --- a/Source/parser/FileParser.h +++ b/Source/parser/FileParser.h @@ -37,4 +37,4 @@ private: std::shared_ptr svg; std::shared_ptr text; std::shared_ptr lua; -}; \ No newline at end of file +}; diff --git a/Source/shape/CircleArc.cpp b/Source/shape/CircleArc.cpp index d8722474..ed287394 100644 --- a/Source/shape/CircleArc.cpp +++ b/Source/shape/CircleArc.cpp @@ -56,9 +56,10 @@ void CircleArc::translate(double x, double y) { double CircleArc::length() { if (len < 0) { len = 0; - for (int i = 0; i < 500; i++) { - Vector2 v1 = nextVector(i / 500.0); - Vector2 v2 = nextVector((i + 1) / 500.0); + int segments = 5; + for (int i = 0; i < segments; i++) { + Vector2 v1 = nextVector(i / (double) segments); + Vector2 v2 = nextVector((i + 1) / (double) segments); len += Line(v1.x, v1.y, v2.x, v2.y).length(); } }