From d4e30d5ff8f84ef97eb08f3493aa42bb11b13982 Mon Sep 17 00:00:00 2001 From: Vesa Date: Mon, 14 Jul 2014 00:37:43 +0300 Subject: [PATCH 1/3] Add safeguard for beat pattern wheelevent Fix #963 --- src/tracks/pattern.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/tracks/pattern.cpp b/src/tracks/pattern.cpp index d11a7b980..6e8b23187 100644 --- a/src/tracks/pattern.cpp +++ b/src/tracks/pattern.cpp @@ -855,27 +855,27 @@ void patternView::wheelEvent( QWheelEvent * _we ) { vol = n->getVolume(); len = n->length(); - } - if( len == 0 && _we->delta() > 0 ) - { - n->setLength( -DefaultTicksPerTact ); - n->setVolume( 5 ); - } - else if( _we->delta() > 0 ) - { - n->setVolume( qMin( 100, vol + 5 ) ); - } - else - { - n->setVolume( qMax( 0, vol - 5 ) ); - } + if( len == 0 && _we->delta() > 0 ) + { + n->setLength( -DefaultTicksPerTact ); + n->setVolume( 5 ); + } + else if( _we->delta() > 0 ) + { + n->setVolume( qMin( 100, vol + 5 ) ); + } + else + { + n->setVolume( qMax( 0, vol - 5 ) ); + } - engine::getSong()->setModified(); - update(); - if( engine::pianoRoll()->currentPattern() == m_pat ) - { - engine::pianoRoll()->update(); + engine::getSong()->setModified(); + update(); + if( engine::pianoRoll()->currentPattern() == m_pat ) + { + engine::pianoRoll()->update(); + } } _we->accept(); } From 8a35a57efae07ae992269dfc4264809a293610c0 Mon Sep 17 00:00:00 2001 From: Vesa Date: Mon, 14 Jul 2014 18:17:02 +0300 Subject: [PATCH 2/3] InstrumentSoundShaping: ensure that release time is never longer than the volume envelope, if volume envelope is active This saves CPU on certain instruments, like Monstro. There's no point in running the note beyond the end of the volume envelope, ever, so let's not do that. --- src/core/InstrumentSoundShaping.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/core/InstrumentSoundShaping.cpp b/src/core/InstrumentSoundShaping.cpp index 7e2f59799..7fe40f7af 100644 --- a/src/core/InstrumentSoundShaping.cpp +++ b/src/core/InstrumentSoundShaping.cpp @@ -315,23 +315,19 @@ f_cnt_t InstrumentSoundShaping::envFrames( const bool _only_vol ) const f_cnt_t InstrumentSoundShaping::releaseFrames() const { - f_cnt_t ret_val = m_envLfoParameters[Volume]->isUsed() ? - m_envLfoParameters[Volume]->releaseFrames() : 0; - if( m_instrumentTrack->instrument() && - m_instrumentTrack->instrument()->desiredReleaseFrames() > ret_val ) + if( m_envLfoParameters[Volume]->isUsed() ) { - ret_val = m_instrumentTrack->instrument()->desiredReleaseFrames(); + return m_envLfoParameters[Volume]->releaseFrames(); } + f_cnt_t ret_val = m_instrumentTrack->instrument() + ? m_instrumentTrack->instrument()->desiredReleaseFrames() + : 0; - if( m_envLfoParameters[Volume]->isUsed() == false ) + for( int i = Volume+1; i < NumTargets; ++i ) { - for( int i = Volume+1; i < NumTargets; ++i ) + if( m_envLfoParameters[i]->isUsed() ) { - if( m_envLfoParameters[i]->isUsed() && - m_envLfoParameters[i]->releaseFrames() > ret_val ) - { - ret_val = m_envLfoParameters[i]->releaseFrames(); - } + ret_val = qMax( ret_val, m_envLfoParameters[i]->releaseFrames() ); } } return ret_val; From 5ed8f7063353ffc06ac439311ab1ff4656d7d96a Mon Sep 17 00:00:00 2001 From: Vesa Date: Mon, 14 Jul 2014 21:49:34 +0300 Subject: [PATCH 3/3] Mixer: optimize peak value measuring functions --- src/core/Mixer.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index c9fd9b83c..7006c5c5c 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -518,14 +518,7 @@ float Mixer::peakValueLeft( sampleFrame * _ab, const f_cnt_t _frames ) float p = 0.0f; for( f_cnt_t f = 0; f < _frames; ++f ) { - if( _ab[f][0] > p ) - { - p = _ab[f][0]; - } - else if( -_ab[f][0] > p ) - { - p = -_ab[f][0]; - } + p = qMax( p, qAbs( _ab[f][0] ) ); } return p; } @@ -538,14 +531,7 @@ float Mixer::peakValueRight( sampleFrame * _ab, const f_cnt_t _frames ) float p = 0.0f; for( f_cnt_t f = 0; f < _frames; ++f ) { - if( _ab[f][1] > p ) - { - p = _ab[f][1]; - } - else if( -_ab[f][1] > p ) - { - p = -_ab[f][1]; - } + p = qMax( p, qAbs( _ab[f][1] ) ); } return p; }