diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index 82be6b92f..8f437eb5a 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -378,10 +378,13 @@ void NotePlayHandle::noteOff( const f_cnt_t _s ) } // inform attached components about MIDI finished (used for recording in Piano Roll) - if( m_origin == OriginMidiInput ) + if (!instrumentTrack()->isSustainPedalPressed()) { - setLength( MidiTime( static_cast( totalFramesPlayed() / Engine::framesPerTick() ) ) ); - m_instrumentTrack->midiNoteOff( *this ); + if( m_origin == OriginMidiInput ) + { + setLength( MidiTime( static_cast( totalFramesPlayed() / Engine::framesPerTick() ) ) ); + m_instrumentTrack->midiNoteOff( *this ); + } } } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index b847c85e6..e9e4aac45 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -273,7 +273,14 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti // be deleted later automatically) Engine::mixer()->requestChangeInModel(); m_notes[event.key()]->noteOff( offset ); - m_notes[event.key()] = NULL; + + if (!(isSustainPedalPressed()) || + !(m_notes[event.key()]->origin() == + m_notes[event.key()]->OriginMidiInput)) + { + m_notes[event.key()] = NULL; + } + Engine::mixer()->doneChangeInModel(); } eventHandled = true; @@ -302,8 +309,24 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti { m_sustainPedalPressed = true; } - else + else if (isSustainPedalPressed()) { + for (NotePlayHandle*& nph : m_notes) + { + if (nph && nph->isReleased()) + { + if( nph->origin() == + nph->OriginMidiInput) + { + nph->setLength( + MidiTime( static_cast( + nph->totalFramesPlayed() / + Engine::framesPerTick() ) ) ); + midiNoteOff( *nph ); + } + nph = NULL; + } + } m_sustainPedalPressed = false; } }