diff --git a/include/AutomationPattern.h b/include/AutomationPattern.h index 858ec131e..526dc21e7 100644 --- a/include/AutomationPattern.h +++ b/include/AutomationPattern.h @@ -169,6 +169,8 @@ private: bool m_dragging; + static const float DEFAULT_MIN_VALUE = 0; + static const float DEFAULT_MAX_VALUE = 1; friend class AutomationPatternView; diff --git a/include/AutomationPatternView.h b/include/AutomationPatternView.h index 4a58cc30c..7bb2b9f5b 100644 --- a/include/AutomationPatternView.h +++ b/include/AutomationPatternView.h @@ -66,6 +66,8 @@ private: QPixmap m_paintPixmap; bool m_needsUpdate; + void scaleTimemapToFit(); + } ; diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 44bbaaa1f..8f928a8d1 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -98,7 +98,7 @@ void AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) } } - // the automation track is empty + // the automation track is unconnected and there is nothing in the track if( m_objects.isEmpty() && hasAutomation() == false ) { // then initialize first value @@ -155,7 +155,7 @@ const AutomatableModel * AutomationPattern::firstObject() const return m; } - static FloatModel _fm( 0, 0, 1, 0.001 ); + static FloatModel _fm( 0, DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, 0.001 ); return &_fm; } @@ -714,4 +714,6 @@ void AutomationPattern::generateTangents( timeMap::const_iterator it, } + + #include "moc_AutomationPattern.cxx" diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index e66c728b4..f69b5d4d8 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -111,6 +111,12 @@ void AutomationPatternView::disconnectObject( QAction * _a ) m_pat->m_objects.end(), dynamic_cast( j ) ) ); update(); + + //If automation editor is opened, update its display after disconnection + if( engine::automationEditor() ) + { + engine::automationEditor()->updateAfterPatternChange(); + } } } @@ -333,6 +339,13 @@ void AutomationPatternView::dropEvent( QDropEvent * _de ) { engine::automationEditor()->setCurrentPattern( m_pat ); } + + //This is the only model that's just added to AutomationPattern. + if( m_pat->m_objects.size() == 1 ) + { + //scale the points to fit the new min. and max. value + this->scaleTimemapToFit(); + } } else { @@ -343,5 +356,38 @@ void AutomationPatternView::dropEvent( QDropEvent * _de ) +/** + * @brief With nothing connected, the automation points are in a small scale. + * Without this function, if the user set the automation points before + * connecting it to a model, his auto points would be lost because the scale is + * changed. This function preserve the auto points over different scale when a + * first model is connected. + */ +void AutomationPatternView::scaleTimemapToFit() +{ + float oldMin = AutomationPattern::DEFAULT_MIN_VALUE; + float oldMax = AutomationPattern::DEFAULT_MAX_VALUE; + float newMin = m_pat->firstObject()->minValue(); + float newMax = m_pat->firstObject()->maxValue(); + + for( AutomationPattern::timeMap::iterator it = m_pat->m_timeMap.begin(); + it != m_pat->m_timeMap.end(); ++it ) + { + if( *it < oldMin ) + { + *it = oldMin; + } + else if( *it > oldMax ) + { + *it = oldMax; + } + *it = (*it)*(newMax-newMin)/(oldMax-oldMin)+newMin; + } + + m_pat->generateTangents(); +} + + + #include "moc_AutomationPatternView.cxx"