From 44028c8594229e0e0c43080194ed918dd09d9ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 2 Aug 2017 02:20:09 -0300 Subject: [PATCH] Midi sustain working when envelope is on (#3730) * midi sustain working when envelope is on * pressing sustain pedal again doesn't pause release --- include/NotePlayHandle.h | 6 ++++++ src/core/InstrumentSoundShaping.cpp | 3 ++- src/core/NotePlayHandle.cpp | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/NotePlayHandle.h b/include/NotePlayHandle.h index bf5c266ca..344980eb6 100644 --- a/include/NotePlayHandle.h +++ b/include/NotePlayHandle.h @@ -156,6 +156,11 @@ public: return m_released; } + bool isReleaseStarted() const + { + return m_releaseStarted; + } + /*! Returns total numbers of frames played so far */ f_cnt_t totalFramesPlayed() const { @@ -297,6 +302,7 @@ private: // release of note NotePlayHandleList m_subNotes; // used for chords and arpeggios volatile bool m_released; // indicates whether note is released + bool m_releaseStarted; bool m_hasParent; // indicates whether note has parent NotePlayHandle * m_parent; // parent note bool m_hadChildren; diff --git a/src/core/InstrumentSoundShaping.cpp b/src/core/InstrumentSoundShaping.cpp index 2a5a71e86..22327ae8e 100644 --- a/src/core/InstrumentSoundShaping.cpp +++ b/src/core/InstrumentSoundShaping.cpp @@ -137,7 +137,8 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer, const f_cnt_t envTotalFrames = n->totalFramesPlayed(); f_cnt_t envReleaseBegin = envTotalFrames - n->releaseFramesDone() + n->framesBeforeRelease(); - if( n->isReleased() == false ) + if( !n->isReleased() || ( n->instrumentTrack()->isSustainPedalPressed() && + !n->isReleaseStarted() ) ) { envReleaseBegin += frames; } diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index 8f437eb5a..84d888fee 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -62,6 +62,7 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack, m_releaseFramesDone( 0 ), m_subNotes(), m_released( false ), + m_releaseStarted( false ), m_hasParent( parent != NULL ), m_parent( parent ), m_hadChildren( false ), @@ -248,8 +249,11 @@ void NotePlayHandle::play( sampleFrame * _working_buffer ) m_instrumentTrack->playNote( this, _working_buffer ); } - if( m_released ) + if( m_released && (!instrumentTrack()->isSustainPedalPressed() || + m_releaseStarted) ) { + m_releaseStarted = true; + f_cnt_t todo = framesThisPeriod; // if this note is base-note for arpeggio, always set