From 84164da2d78388a3f73ee1fe29fbedf90cf8eb43 Mon Sep 17 00:00:00 2001 From: xenakios Date: Tue, 30 Jan 2018 17:32:23 +0200 Subject: [PATCH] Finally added enabled buttons for the spectral steps. --- Source/PS_Source/ProcessedStretch.cpp | 29 ++++++---------------- Source/PS_Source/ProcessedStretch.h | 12 +++------ Source/PS_Source/StretchSource.cpp | 10 ++++---- Source/PS_Source/StretchSource.h | 10 ++++---- Source/PluginEditor.cpp | 35 +++++++++++++++++++++------ Source/PluginEditor.h | 2 +- Source/PluginProcessor.cpp | 12 ++++++--- 7 files changed, 58 insertions(+), 52 deletions(-) diff --git a/Source/PS_Source/ProcessedStretch.cpp b/Source/PS_Source/ProcessedStretch.cpp index 4a0956b..b7dbdd5 100644 --- a/Source/PS_Source/ProcessedStretch.cpp +++ b/Source/PS_Source/ProcessedStretch.cpp @@ -109,21 +109,21 @@ void ProcessedStretch::process_spectrum(REALTYPE *freq) for (auto& e : m_spectrum_processes) { spectrum_copy(nfreq, freq, infreq.data()); - if (e == 0 && pars.harmonics.enabled) + if (e.m_index == 0 && e.m_enabled == true) spectrum_do_harmonics(pars, tmpfreq1, nfreq, samplerate, infreq.data(), freq); - if (e == 1 && pars.tonal_vs_noise.enabled) + if (e.m_index == 1 && e.m_enabled == true) spectrum_do_tonal_vs_noise(pars,nfreq,samplerate,tmpfreq1, infreq.data(), freq); - if (e == 2 && pars.freq_shift.enabled) + if (e.m_index == 2 && e.m_enabled == true) spectrum_do_freq_shift(pars,nfreq,samplerate,infreq.data(), freq); - if (e == 3 && pars.pitch_shift.enabled) + if (e.m_index == 3 && e.m_enabled == true) spectrum_do_pitch_shift(pars,nfreq,infreq.data(), freq, pow(2.0f, pars.pitch_shift.cents / 1200.0f)); - if (e == 4 && pars.octave.enabled) + if (e.m_index == 4 && e.m_enabled == true) spectrum_do_octave(pars,nfreq,samplerate, sumfreq, tmpfreq1, infreq.data(), freq); - if (e == 5 && pars.spread.enabled) + if (e.m_index == 5 && e.m_enabled == true) spectrum_spread(nfreq,samplerate,tmpfreq1,infreq.data(), freq, pars.spread.bandwidth); - if (e == 6 && pars.filter.enabled) + if (e.m_index == 6 && e.m_enabled == true) spectrum_do_filter(pars,nfreq,samplerate,infreq.data(), freq); - if (e == 7 && pars.compressor.enabled) + if (e.m_index == 7 && e.m_enabled == true) spectrum_do_compressor(pars,nfreq, infreq.data(), freq); } @@ -197,16 +197,3 @@ void ProcessedStretch::update_free_filter() */ }; -std::vector make_spectrum_processes() -{ - std::vector m_spectrum_processes; - m_spectrum_processes.emplace_back("Harmonics",0); - m_spectrum_processes.emplace_back("Tonal vs Noise",1); - m_spectrum_processes.emplace_back("Frequency shift",2); - m_spectrum_processes.emplace_back("Pitch shift",3); - m_spectrum_processes.emplace_back("Octaves mix",4); - m_spectrum_processes.emplace_back("Spread",5); - m_spectrum_processes.emplace_back("Filter",6); - m_spectrum_processes.emplace_back("Compressor",7); - return m_spectrum_processes; -} diff --git a/Source/PS_Source/ProcessedStretch.h b/Source/PS_Source/ProcessedStretch.h index d65c333..8b0ddf2 100644 --- a/Source/PS_Source/ProcessedStretch.h +++ b/Source/PS_Source/ProcessedStretch.h @@ -440,16 +440,12 @@ inline void spectrum_do_filter(const ProcessParameters& pars, int nfreq, double class SpectrumProcess { public: - SpectrumProcess() {} - SpectrumProcess(String name, int index) : - m_name(name), m_index(index) {} - String m_name; + SpectrumProcess() {} + SpectrumProcess(int index, bool enabled) : m_index(index), m_enabled(enabled) {} int m_index = -1; -private: + bool m_enabled = true; }; -std::vector make_spectrum_processes(); - class ProcessedStretch final : public Stretch { public: @@ -458,7 +454,7 @@ public: ProcessedStretch(REALTYPE rap_,int in_bufsize_,FFTWindow w=W_HAMMING,bool bypass_=false,REALTYPE samplerate_=44100.0f,int stereo_mode=0); ~ProcessedStretch(); void set_parameters(ProcessParameters *ppar); - std::vector m_spectrum_processes; + std::vector m_spectrum_processes; void setBufferSize(int sz) override; private: REALTYPE get_stretch_multiplier(REALTYPE pos_percents) override; diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 1707f08..b9d0d1e 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -12,7 +12,7 @@ StretchAudioSource::StretchAudioSource(int initialnumoutchans, AudioFormatManage m_resampler = std::make_unique(); m_resampler_outbuf.resize(1024*1024); m_inputfile = std::make_unique(m_afm); - m_specproc_order = { 0,1,2,3,4,5,6,7 }; + m_specproc_order = { {0,false} , { 1, false} ,{2,true},{3,true},{4,true},{5,true},{6,true},{7,true} }; setNumOutChannels(initialnumoutchans); m_xfadetask.buffer.setSize(8, 65536); m_xfadetask.buffer.clear(); @@ -58,12 +58,12 @@ bool StretchAudioSource::isResampling() return (int)m_outsr!=m_inputfile->info.samplerate; } -std::vector StretchAudioSource::getSpectrumProcessOrder() +std::vector StretchAudioSource::getSpectrumProcessOrder() { return m_specproc_order; } -void StretchAudioSource::setSpectrumProcessOrder(std::vector order) +void StretchAudioSource::setSpectrumProcessOrder(std::vector order) { ScopedLock locker(m_cs); m_specproc_order = order; @@ -920,12 +920,12 @@ bool MultiStretchAudioSource::isResampling() return getActiveStretchSource()->isResampling(); } -std::vector MultiStretchAudioSource::getSpectrumProcessOrder() +std::vector MultiStretchAudioSource::getSpectrumProcessOrder() { return getActiveStretchSource()->getSpectrumProcessOrder(); } -void MultiStretchAudioSource::setSpectrumProcessOrder(std::vector order) +void MultiStretchAudioSource::setSpectrumProcessOrder(std::vector order) { getActiveStretchSource()->setSpectrumProcessOrder(order); } diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 312a58a..8377017 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -82,8 +82,8 @@ public: bool isLoopEnabled(); bool hasReachedEnd(); bool isResampling(); - std::vector getSpectrumProcessOrder(); - void setSpectrumProcessOrder(std::vector order); + std::vector getSpectrumProcessOrder(); + void setSpectrumProcessOrder(std::vector order); void setFFTWindowingType(int windowtype); int getFFTWindowingType() { return m_fft_window_type; } std::pair,Range> getFileCachedRangesNormalized(); @@ -135,7 +135,7 @@ private: std::unique_ptr m_resampler; std::vector m_resampler_outbuf; CriticalSection m_cs; - std::vector m_specproc_order; + std::vector m_specproc_order; bool m_stop_play_requested = false; double m_freeze_pos = 0.0; int64_t m_output_counter = 0; @@ -199,8 +199,8 @@ public: void setLoopingEnabled(bool b); bool hasReachedEnd(); bool isResampling(); - std::vector getSpectrumProcessOrder(); - void setSpectrumProcessOrder(std::vector order); + std::vector getSpectrumProcessOrder(); + void setSpectrumProcessOrder(std::vector order); void setFFTWindowingType(int windowtype); std::pair, Range> getFileCachedRangesNormalized(); void setFreezing(bool b) { m_freezing = b; } diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index ccfc986..27f7ece 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -720,6 +720,17 @@ void SpectralChainEditor::mouseDown(const MouseEvent & ev) int box_w = getWidth() / m_order.size(); int box_h = getHeight(); m_cur_index = ev.x / box_w; + if (m_cur_index >= 0) + { + juce::Rectangle r(box_w*m_cur_index, 1, 10, 10); + if (r.contains(ev.x, ev.y)) + { + m_order[m_cur_index].m_enabled = !m_order[m_cur_index].m_enabled; + m_src->setSpectrumProcessOrder(m_order); + repaint(); + return; + } + } m_drag_x = -1; repaint(); } @@ -753,21 +764,21 @@ void SpectralChainEditor::mouseUp(const MouseEvent & ev) void SpectralChainEditor::drawBox(Graphics & g, int index, int x, int y, int w, int h) { String txt; - if (m_order[index] == 0) + if (m_order[index].m_index == 0) txt = "Harmonics"; - if (m_order[index] == 1) + if (m_order[index].m_index == 1) txt = "Tonal vs Noise"; - if (m_order[index] == 2) + if (m_order[index].m_index == 2) txt = "Frequency shift"; - if (m_order[index] == 3) + if (m_order[index].m_index == 3) txt = "Pitch shift"; - if (m_order[index] == 4) + if (m_order[index].m_index == 4) txt = "Octaves"; - if (m_order[index] == 5) + if (m_order[index].m_index == 5) txt = "Spread"; - if (m_order[index] == 6) + if (m_order[index].m_index == 6) txt = "Filter"; - if (m_order[index] == 7) + if (m_order[index].m_index == 7) txt = "Compressor"; if (index == m_cur_index) { @@ -778,6 +789,14 @@ void SpectralChainEditor::drawBox(Graphics & g, int index, int x, int y, int w, g.setColour(Colours::white); g.drawRect(x, y, w, h); g.drawFittedText(txt, x,y,w,h, Justification::centred, 3); + g.setColour(Colours::gold); + g.drawRect(x + 2, y + 2, 10, 10); + if (m_order[index].m_enabled == true) + { + g.drawLine(x+2, y+2, x+12, y+12); + g.drawLine(x+2, y+12, x+12, y+2); + } + g.setColour(Colours::white); } ParameterComponent::ParameterComponent(AudioProcessorParameter * par, bool notifyOnlyOnRelease) : m_par(par) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 986b740..fb56adb 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -139,7 +139,7 @@ private: bool m_did_drag = false; int m_cur_index = -1; int m_drag_x = 0; - std::vector m_order; + std::vector m_order; void drawBox(Graphics& g, int index, int x, int y, int w, int h); }; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 82fff90..f6e1868 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -239,7 +239,8 @@ ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool paramtree.setProperty("numspectralstages", (int)specorder.size(), nullptr); for (int i = 0; i < specorder.size(); ++i) { - paramtree.setProperty("specorder" + String(i), specorder[i], nullptr); + paramtree.setProperty("specorder" + String(i), specorder[i].m_index, nullptr); + paramtree.setProperty("specstepenabled" + String(i), specorder[i].m_enabled, nullptr); } if (ignoreoptions == false) { @@ -261,11 +262,12 @@ void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree) m_load_file_with_state = tree.getProperty("loadfilewithstate", true); if (tree.hasProperty("numspectralstages")) { - std::vector order; + std::vector order; int ordersize = tree.getProperty("numspectralstages"); for (int i = 0; i < ordersize; ++i) { - order.push_back((int)tree.getProperty("specorder" + String(i))); + bool step_enabled = tree.getProperty("specstepenabled" + String(i)); + order.push_back({ (int)tree.getProperty("specorder" + String(i)), step_enabled }); } m_stretch_source->setSpectrumProcessOrder(order); } @@ -698,7 +700,9 @@ String PaulstretchpluginAudioProcessor::setAudioFile(File f) m_thumb->setSource(new FileInputSource(f)); ScopedLock locker(m_cs); m_stretch_source->setAudioFile(f); - m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart)); + //Range currange{ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }; + //if (currange.contains(m_stretch_source->getInfilePositionPercent())==false) + m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart)); m_current_file = f; m_current_file_date = m_current_file.getLastModificationTime(); m_using_memory_buffer = false;