Skip to content

Commit

Permalink
Fix notes getting stuck under high CPU conditions (LMMS#4908)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomClark authored Apr 24, 2019
1 parent a2064ea commit cbfe407
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/NotePlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class EXPORT NotePlayHandle : public PlayHandle, public Note
NotePlayHandleList m_subNotes; // used for chords and arpeggios
volatile bool m_released; // indicates whether note is released
bool m_releaseStarted;
bool m_hasMidiNote;
bool m_hasParent; // indicates whether note has parent
NotePlayHandle * m_parent; // parent note
bool m_hadChildren;
Expand Down
31 changes: 19 additions & 12 deletions src/core/NotePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack,
m_subNotes(),
m_released( false ),
m_releaseStarted( false ),
m_hasMidiNote( false ),
m_hasParent( parent != NULL ),
m_parent( parent ),
m_hadChildren( false ),
Expand Down Expand Up @@ -106,17 +107,6 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack,
m_instrumentTrack->midiNoteOn( *this );
}

if( hasParent() || ! m_instrumentTrack->isArpeggioEnabled() )
{
const int baseVelocity = m_instrumentTrack->midiPort()->baseVelocity();

// send MidiNoteOn event
m_instrumentTrack->processOutEvent(
MidiEvent( MidiNoteOn, midiChannel(), midiKey(), midiVelocity( baseVelocity ) ),
MidiTime::fromFrames( offset(), Engine::framesPerTick() ),
offset() );
}

if( m_instrumentTrack->instrument()->flags() & Instrument::IsSingleStreamed )
{
setUsesBuffer( false );
Expand Down Expand Up @@ -208,6 +198,21 @@ void NotePlayHandle::play( sampleFrame * _working_buffer )
}

lock();

if( m_totalFramesPlayed == 0 && !m_hasMidiNote
&& ( hasParent() || ! m_instrumentTrack->isArpeggioEnabled() ) )
{
m_hasMidiNote = true;

const int baseVelocity = m_instrumentTrack->midiPort()->baseVelocity();

// send MidiNoteOn event
m_instrumentTrack->processOutEvent(
MidiEvent( MidiNoteOn, midiChannel(), midiKey(), midiVelocity( baseVelocity ) ),
MidiTime::fromFrames( offset(), Engine::framesPerTick() ),
offset() );
}

if( m_frequencyNeedsUpdate )
{
updateFrequency();
Expand Down Expand Up @@ -360,8 +365,10 @@ void NotePlayHandle::noteOff( const f_cnt_t _s )
m_framesBeforeRelease = _s;
m_releaseFramesToDo = qMax<f_cnt_t>( 0, actualReleaseFramesToDo() );

if( hasParent() || ! m_instrumentTrack->isArpeggioEnabled() )
if( m_hasMidiNote )
{
m_hasMidiNote = false;

// send MidiNoteOff event
m_instrumentTrack->processOutEvent(
MidiEvent( MidiNoteOff, midiChannel(), midiKey(), 0 ),
Expand Down

0 comments on commit cbfe407

Please sign in to comment.