From 18e08087a74b47e41ff230b0e6cae8b87c592203 Mon Sep 17 00:00:00 2001 From: Hyunin Song Date: Sat, 2 Sep 2017 16:13:46 +0900 Subject: [PATCH 1/2] Revert "same note layering when sustain pedal is pressed (#3774)" This reverts commit e387e7744521d933b9e8455623eef55119b8403d. --- src/core/NotePlayHandle.cpp | 21 +++++++++++---------- src/tracks/InstrumentTrack.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index 0dff48fc02b..84d888fee6b 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -252,17 +252,8 @@ void NotePlayHandle::play( sampleFrame * _working_buffer ) if( m_released && (!instrumentTrack()->isSustainPedalPressed() || m_releaseStarted) ) { - if (m_releaseStarted == false) - { + m_releaseStarted = true; - if( m_origin == OriginMidiInput ) - { - setLength( MidiTime( static_cast( totalFramesPlayed() / Engine::framesPerTick() ) ) ); - m_instrumentTrack->midiNoteOff( *this ); - } - - m_releaseStarted = true; - } f_cnt_t todo = framesThisPeriod; // if this note is base-note for arpeggio, always set @@ -389,6 +380,16 @@ void NotePlayHandle::noteOff( const f_cnt_t _s ) MidiTime::fromFrames( _s, Engine::framesPerTick() ), _s ); } + + // inform attached components about MIDI finished (used for recording in Piano Roll) + if (!instrumentTrack()->isSustainPedalPressed()) + { + 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 71cc43fb56e..dc101dbf411 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; } } From 5173a8b2eee816cb669a25c3ff76ca13dda33aee Mon Sep 17 00:00:00 2001 From: Hyunin Song Date: Sun, 3 Sep 2017 15:40:48 +0900 Subject: [PATCH 2/2] Fix recording of sustained notes --- include/InstrumentTrack.h | 1 + src/tracks/InstrumentTrack.cpp | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 6d2e42c3d6a..5ef604defb8 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -237,6 +237,7 @@ protected slots: MidiPort m_midiPort; NotePlayHandle* m_notes[NumKeys]; + NotePlayHandleList m_sustainedNotes; int m_runningMidiNotes[NumKeys]; QMutex m_midiNotesMutex; diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index dc101dbf411..21a589c4152 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -273,14 +273,13 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti // be deleted later automatically) Engine::mixer()->requestChangeInModel(); m_notes[event.key()]->noteOff( offset ); - - if (!(isSustainPedalPressed()) || - !(m_notes[event.key()]->origin() == - m_notes[event.key()]->OriginMidiInput)) + if (isSustainPedalPressed() && + m_notes[event.key()]->origin() == + m_notes[event.key()]->OriginMidiInput) { - m_notes[event.key()] = NULL; + m_sustainedNotes << m_notes[event.key()]; } - + m_notes[event.key()] = NULL; Engine::mixer()->doneChangeInModel(); } eventHandled = true; @@ -311,7 +310,7 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti } else if (isSustainPedalPressed()) { - for (NotePlayHandle*& nph : m_notes) + for (NotePlayHandle* nph : m_sustainedNotes) { if (nph && nph->isReleased()) { @@ -324,9 +323,9 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti Engine::framesPerTick() ) ) ); midiNoteOff( *nph ); } - nph = NULL; } } + m_sustainedNotes.clear(); m_sustainPedalPressed = false; } }