Skip to content

Commit

Permalink
Midi sustain working when envelope is on (#3730)
Browse files Browse the repository at this point in the history
* midi sustain working when envelope is on

* pressing sustain pedal again doesn't pause release

[cherry-picked from master]
  • Loading branch information
serdnab authored and zonkmachine committed Aug 2, 2017
1 parent 2e841e4 commit 31126b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/NotePlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class EXPORT NotePlayHandle : public PlayHandle, public Note
return m_released;
}

bool isReleaseStarted() const
{
return m_releaseStarted;
}

/*! Returns total numbers of frames played so far */
f_cnt_t totalFramesPlayed() const
{
Expand Down Expand Up @@ -297,6 +302,7 @@ class EXPORT NotePlayHandle : public PlayHandle, public Note
// 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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/InstrumentSoundShaping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/NotePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31126b0

Please sign in to comment.