From 51049e4ae12e562e587c6a4721237b9b9cf5e552 Mon Sep 17 00:00:00 2001 From: xenakios Date: Tue, 27 Feb 2018 15:21:36 +0200 Subject: [PATCH] Mutex protect the envelope when manipulating the amount of nodes from the GUI. Should probably redesign this stuff a bit...Init envelope reset nodes. --- Source/PS_Source/StretchSource.h | 1 + Source/PluginEditor.cpp | 4 ++-- Source/PluginProcessor.cpp | 6 +++--- Source/envelope_component.cpp | 8 +++++++- Source/envelope_component.h | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 77c9809..e87296c 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -104,6 +104,7 @@ public: void setPreviewDry(bool b); bool isPreviewingDry() const; int m_param_change_count = 0; + CriticalSection* getMutex() { return &m_cs; } private: CircularBuffer m_stretchoutringbuf{ 1024 * 1024 }; AudioBuffer m_file_inbuf; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 1f479a7..ec08b83 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -29,8 +29,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau : AudioProcessorEditor(&p), m_wavecomponent(p.m_afm,p.m_thumb.get()), processor(p), m_perfmeter(&p), - m_wavefilter_tab(TabbedButtonBar::TabsAtTop) - + m_wavefilter_tab(TabbedButtonBar::TabsAtTop), + m_free_filter_component(p.getStretchSource()->getMutex()) { //addAndMakeVisible(&m_free_filter_component); m_free_filter_component.set_envelope(processor.m_free_filter_envelope); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 5f53501..6415efd 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -82,9 +82,9 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() m_playposinfo.timeInSeconds = 0.0; m_free_filter_envelope = std::make_shared(); - m_free_filter_envelope->AddNode({ 0.0,0.5 }); - m_free_filter_envelope->AddNode({ 1.0,0.5 }); - + m_free_filter_envelope->AddNode({ 0.0,0.75 }); + m_free_filter_envelope->AddNode({ 1.0,0.75 }); + m_free_filter_envelope->set_reset_nodes(m_free_filter_envelope->get_all_nodes()); m_recbuffer.setSize(2, 44100); m_recbuffer.clear(); if (m_afm->getNumKnownFormats()==0) diff --git a/Source/envelope_component.cpp b/Source/envelope_component.cpp index edfe4b3..42c9505 100644 --- a/Source/envelope_component.cpp +++ b/Source/envelope_component.cpp @@ -20,7 +20,7 @@ #include "envelope_component.h" -EnvelopeComponent::EnvelopeComponent() +EnvelopeComponent::EnvelopeComponent(CriticalSection* cs) : m_cs(cs) { OnEnvelopeEdited = [](breakpoint_envelope*) {}; setWantsKeyboardFocus(true); @@ -246,7 +246,9 @@ void EnvelopeComponent::mouseDown(const MouseEvent & ev) int r = menu.show(); if (r == 1) { + m_cs->enter(); m_envelope->ResetEnvelope(); + m_cs->exit(); } if (r == 2) { @@ -274,7 +276,9 @@ void EnvelopeComponent::mouseDown(const MouseEvent & ev) m_bubble.showAt({ ev.x,ev.y, 0,0 }, AttributedString("Can't remove last node"), 3000, false, false); return; } + m_cs->enter(); m_envelope->DeleteNode(m_node_to_drag); + m_cs->exit(); m_node_to_drag = -1; OnEnvelopeEdited(m_envelope.get()); repaint(); @@ -293,8 +297,10 @@ void EnvelopeComponent::mouseDown(const MouseEvent & ev) { double normx = jmap((double)ev.x, 0.0, (double)getWidth(), m_view_start_time, m_view_end_time); double normy = jmap((double)getHeight() - ev.y, 0.0, (double)getHeight(), m_view_start_value, m_view_end_value); + m_cs->enter(); m_envelope->AddNode ({ normx,normy, 0.5}); m_envelope->SortNodes(); + m_cs->exit(); m_mouse_down = false; OnEnvelopeEdited(m_envelope.get()); repaint(); diff --git a/Source/envelope_component.h b/Source/envelope_component.h index 0bc95b5..415b345 100644 --- a/Source/envelope_component.h +++ b/Source/envelope_component.h @@ -32,7 +32,7 @@ class EnvelopeComponent : public Component, //public TooltipClient { public: - EnvelopeComponent(); + EnvelopeComponent(CriticalSection* cs); ~EnvelopeComponent(); void paint(Graphics& g) override; void set_envelope(std::shared_ptr env, String name = String()); @@ -72,5 +72,6 @@ private: String m_last_tip; BubbleMessageComponent m_bubble; void show_bubble(int x, int y, const envelope_node &node); + CriticalSection* m_cs = nullptr; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EnvelopeComponent) };