From aec0dd3b3e34ca7e47067c04d2b2d9737bf5ba4e Mon Sep 17 00:00:00 2001 From: Veratil Date: Sun, 26 Apr 2020 10:14:29 -0500 Subject: [PATCH 1/2] If AutomationPattern has a single tick at 0, set it's length to 1 bar. --- src/core/AutomationPattern.cpp | 26 ++++++++++++++------------ src/core/Track.cpp | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index b38c704ef..9a8bdca15 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -178,9 +178,19 @@ const AutomationPattern::objectVector& AutomationPattern::objects() const MidiTime AutomationPattern::timeMapLength() const { - if( m_timeMap.isEmpty() ) return 0; + MidiTime one_bar = MidiTime(1, 0); + if (m_timeMap.isEmpty()) + { + return one_bar; + } timeMap::const_iterator it = m_timeMap.end(); - return MidiTime( MidiTime( (it-1).key() ).nextFullBar(), 0 ); + tick_t last_tick = static_cast((it-1).key()); + bar_t last_bar = qMax(0, MidiTime(last_tick).nextFullBar() - 1); + if (last_bar == 0 && last_tick == 0) + { + return one_bar; + } + return MidiTime(last_bar, last_tick); } @@ -223,12 +233,7 @@ MidiTime AutomationPattern::putValue( const MidiTime & time, } generateTangents( it, 3 ); - // we need to maximize our length in case we're part of a hidden - // automation track as the user can't resize this pattern - if( getTrack() && getTrack()->type() == Track::HiddenAutomationTrack ) - { - updateLength(); - } + updateLength(); emit dataChanged(); @@ -251,10 +256,7 @@ void AutomationPattern::removeValue( const MidiTime & time ) } generateTangents(it, 3); - if( getTrack() && getTrack()->type() == Track::HiddenAutomationTrack ) - { - updateLength(); - } + updateLength(); emit dataChanged(); } diff --git a/src/core/Track.cpp b/src/core/Track.cpp index cb430da96..0c046a504 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -159,7 +159,7 @@ void TrackContentObject::movePosition( const MidiTime & pos ) /*! \brief Change the length of this TrackContentObject * - * If the track content object's length has chaanged, update it. We + * If the track content object's length has changed, update it. We * also add a journal entry for undo and update the display. * * \param _length The new length of the track content object. From a4f677362d3c37e5436884c70c8869f0cc9174cd Mon Sep 17 00:00:00 2001 From: Veratil Date: Sun, 26 Apr 2020 14:44:05 -0500 Subject: [PATCH 2/2] Add comments and reduce unnecessary code --- src/core/AutomationPattern.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 9a8bdca15..2fd1cea12 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -179,18 +179,15 @@ const AutomationPattern::objectVector& AutomationPattern::objects() const MidiTime AutomationPattern::timeMapLength() const { MidiTime one_bar = MidiTime(1, 0); - if (m_timeMap.isEmpty()) - { - return one_bar; - } + if (m_timeMap.isEmpty()) { return one_bar; } + timeMap::const_iterator it = m_timeMap.end(); tick_t last_tick = static_cast((it-1).key()); - bar_t last_bar = qMax(0, MidiTime(last_tick).nextFullBar() - 1); - if (last_bar == 0 && last_tick == 0) - { - return one_bar; - } - return MidiTime(last_bar, last_tick); + // if last_tick is 0 (single item at tick 0) + // return length as a whole bar to prevent disappearing TCO + if (last_tick == 0) { return one_bar; } + + return MidiTime(last_tick); } @@ -198,7 +195,8 @@ MidiTime AutomationPattern::timeMapLength() const void AutomationPattern::updateLength() { - changeLength( timeMapLength() ); + // Do not resize down in case user manually extended up + changeLength(qMax(length(), timeMapLength())); }