Rendering tweak and fixes #234

This commit is contained in:
Wong Cho Ching
2014-02-02 19:40:00 +08:00
parent 287276db6f
commit f7963d5b3b
4 changed files with 54 additions and 2 deletions

View File

@@ -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;

View File

@@ -66,6 +66,8 @@ private:
QPixmap m_paintPixmap;
bool m_needsUpdate;
void scaleTimemapToFit();
} ;

View File

@@ -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"

View File

@@ -111,6 +111,12 @@ void AutomationPatternView::disconnectObject( QAction * _a )
m_pat->m_objects.end(),
dynamic_cast<AutomatableModel *>( 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>();
float newMax = m_pat->firstObject()->maxValue<float>();
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"