Added ADSR envelope

This commit is contained in:
xenakios 2019-01-17 19:47:56 +02:00
parent aa740528f5
commit 2ac85fac1f
2 changed files with 15 additions and 1 deletions

View File

@ -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<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor());
if (ed != nullptr)
{

View File

@ -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<float> m_recbuffer;
@ -274,6 +275,8 @@ private:
void saveCaptureBuffer();
SharedResourcePointer<MyThreadPool> m_threadpool;
int m_midinote_to_use = -1;
ADSR m_adsr;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
};