From 0052c77bbbed98ad34b8398f52af1a20a0e92195 Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 20 Dec 2017 20:33:34 +0200 Subject: [PATCH] Add option to capture only when host transport active. Add option to always pass input audio through. That should probably be a plugin parameter though... --- Source/PluginEditor.cpp | 5 +++++ Source/PluginProcessor.cpp | 16 ++++++++++++++-- Source/PluginProcessor.h | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 1d4cd98..eb163fd 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -225,6 +225,7 @@ void PaulstretchpluginAudioProcessorEditor::showSettingsMenu() PopupMenu menu; menu.addItem(1, "Play when host transport running", true, processor.m_play_when_host_plays); menu.addItem(2, "Capture when host transport running", true, processor.m_capture_when_host_plays); + menu.addItem(3, "Always pass audio input through", true, processor.m_pass_input_through); //menu.addItem(3, "Prebuffering", true, processor.m_use_backgroundbuffering); PopupMenu bufferingmenu; int curbufamount = processor.getPreBufferAmount(); @@ -244,6 +245,10 @@ void PaulstretchpluginAudioProcessorEditor::showSettingsMenu() { processor.m_capture_when_host_plays = !processor.m_capture_when_host_plays; } + if (r == 3) + { + processor.m_pass_input_through = !processor.m_pass_input_through; + } if (r >= 100 && r < 200) { if (r == 100) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index a1e2ae7..92fb0fd 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -285,12 +285,14 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl ScopedLock locker(m_cs); m_cur_sr = sampleRate; m_curmaxblocksize = samplesPerBlock; + m_input_buffer.setSize(2, samplesPerBlock); int numoutchans = *m_outchansparam; if (numoutchans != m_cur_num_out_chans) m_ready_to_play = false; if (m_using_memory_buffer == true) { - int len = jlimit(100,m_recbuffer.getNumSamples(), m_rec_pos); + int len = jlimit(100,m_recbuffer.getNumSamples(), + int(getSampleRateChecked()*(*getFloatParameter(cpi_max_capture_len)))); m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), len); @@ -373,13 +375,16 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_cur_sr = srtemp; const int totalNumInputChannels = getTotalNumInputChannels(); const int totalNumOutputChannels = getTotalNumOutputChannels(); - + for (int i = 0; i < totalNumInputChannels; ++i) + m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples()); for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i) buffer.clear (i, 0, buffer.getNumSamples()); if (m_ready_to_play == false) return; if (m_is_recording == true) { + if (m_playposinfo.isPlaying == false && m_capture_when_host_plays == true) + return; int recbuflenframes = m_max_reclen * getSampleRate(); copyAudioBufferWrappingPosition(buffer, m_recbuffer, m_rec_pos, recbuflenframes); callGUI(this,[this, &buffer](PaulstretchpluginAudioProcessorEditor*ed) @@ -450,6 +455,13 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M { m_buffering_source->getNextAudioBlock(aif); } + if (m_pass_input_through == true) + { + for (int i = 0; i < totalNumInputChannels; ++i) + { + buffer.addFrom(i, 0, m_input_buffer, i, 0, buffer.getNumSamples()); + } + } for (int i = 0; i < buffer.getNumChannels(); ++i) { for (int j = 0; j < buffer.getNumSamples(); ++j) diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 6814146..ba007eb 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -139,6 +139,7 @@ public: bool m_play_when_host_plays = false; bool m_capture_when_host_plays = false; bool m_use_backgroundbuffering = true; + bool m_pass_input_through = false; void setPreBufferAmount(int x); int getPreBufferAmount() { @@ -180,6 +181,7 @@ private: int m_curmaxblocksize = 0; double m_cur_sr = 0.0; bool m_last_host_playing = false; + AudioBuffer m_input_buffer; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };