diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 5edc2df..68893a6 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -585,6 +585,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl { ++m_prepare_count; ScopedLock locker(m_cs); + m_adsr.setSampleRate(sampleRate); m_cur_sr = sampleRate; m_curmaxblocksize = samplesPerBlock; m_input_buffer.setSize(getMainBusNumInputChannels(), samplesPerBlock); @@ -787,16 +788,19 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M if (midi_msg.isNoteOff() && midi_msg.getNoteNumber()==m_midinote_to_use) { m_midinote_to_use = -1; + m_adsr.noteOff(); break; } if (midi_msg.isNoteOn()) { m_midinote_to_use = midi_msg.getNoteNumber(); + m_adsr.setParameters({1.0,0.5,0.5,1.0}); + m_adsr.noteOn(); break; } } - if (m_midinote_to_use >= 0) + if (m_midinote_control == true && m_midinote_to_use >= 0) { int note_offset = m_midinote_to_use - 60; m_ppar.pitch_shift.cents += 100.0*note_offset; @@ -836,6 +840,13 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M { buffer.clear(); } + else + { + if (m_midinote_control == true) + { + m_adsr.applyEnvelopeToBuffer(buffer, 0, buffer.getNumSamples()); + } + } auto ed = dynamic_cast(getActiveEditor()); if (ed != nullptr) { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 6fde7fb..40f1fd9 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -227,6 +227,7 @@ public: bool m_is_recording = false; bool m_save_captured_audio = true; String m_capture_location; + bool m_midinote_control = true; private: bool m_prebuffering_inited = false; AudioBuffer m_recbuffer; @@ -274,6 +275,8 @@ private: void saveCaptureBuffer(); SharedResourcePointer m_threadpool; int m_midinote_to_use = -1; + ADSR m_adsr; + //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };