diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 382f906fc..44bbaaa1f 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -84,8 +84,6 @@ AutomationPattern::~AutomationPattern() void AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) { - bool addIt = true; - if( _search_dup ) { for( objectVector::iterator it = m_objects.begin(); @@ -95,27 +93,26 @@ void AutomationPattern::addObject( AutomatableModel * _obj, bool _search_dup ) { // Already exists // TODO: Maybe let the user know in some non-annoying way - addIt = false; - break; + return; } } } - if( addIt ) + // the automation track is empty + if( m_objects.isEmpty() && hasAutomation() == false ) { - // been empty before and model's current value is not its init value? - if( m_objects.isEmpty() && hasAutomation() == false && _obj->isAtInitValue() == false ) - { - // then initialize first value - putValue( 0, _obj->value(), false ); - } - - m_objects += _obj; - - connect( _obj, SIGNAL( destroyed( jo_id_t ) ), - this, SLOT( objectDestroyed( jo_id_t ) ), - Qt::DirectConnection ); + // then initialize first value + putValue( MidiTime(0), _obj->value(), false ); } + + m_objects += _obj; + + connect( _obj, SIGNAL( destroyed( jo_id_t ) ), + this, SLOT( objectDestroyed( jo_id_t ) ), + Qt::DirectConnection ); + + emit dataChanged(); + } @@ -584,18 +581,18 @@ void AutomationPattern::resolveAllIDs() AutomationPattern * a = dynamic_cast( *j ); if( a ) { - for( QVector::Iterator k = a->m_idsToResolve.begin(); - k != a->m_idsToResolve.end(); ++k ) - { - JournallingObject * o = engine::projectJournal()-> - journallingObject( *k ); - if( o && dynamic_cast( o ) ) - { - a->addObject( dynamic_cast( o ), false ); - } - } - a->m_idsToResolve.clear(); - a->dataChanged(); + for( QVector::Iterator k = a->m_idsToResolve.begin(); + k != a->m_idsToResolve.end(); ++k ) + { + JournallingObject * o = engine::projectJournal()-> + journallingObject( *k ); + if( o && dynamic_cast( o ) ) + { + a->addObject( dynamic_cast( o ), false ); + } + } + a->m_idsToResolve.clear(); + a->dataChanged(); } } } @@ -639,6 +636,20 @@ void AutomationPattern::objectDestroyed( jo_id_t _id ) // case we had to remove ourselves if we're the global automation // pattern of the destroyed object m_idsToResolve += _id; + + for( objectVector::Iterator objIt = m_objects.begin(); + objIt != m_objects.end(); objIt++ ) + { + Q_ASSERT( !(*objIt).isNull() ); + if( (*objIt)->id() == _id ) + { + //Assign to objIt so that this loop work even break; is removed. + objIt = m_objects.erase( objIt ); + break; + } + } + + emit dataChanged(); } diff --git a/src/gui/AutomationEditor.cpp b/src/gui/AutomationEditor.cpp index ffc230637..31e582a7c 100644 --- a/src/gui/AutomationEditor.cpp +++ b/src/gui/AutomationEditor.cpp @@ -1546,72 +1546,76 @@ void AutomationEditor::paintEvent( QPaintEvent * _pe ) { int len_ticks = 4; timeMap & time_map = m_pattern->getTimeMap(); - timeMap::iterator it = time_map.begin(); - p.setPen( QColor( 0xCF, 0xD9, 0xFF ) ); - while( it+1 != time_map.end() ) + //Don't bother doing/rendering anything if there is no automation points + if( time_map.size() > 0 ) { - // skip this section if it occurs completely before the - // visible area - int next_x = xCoordOfTick( (it+1).key() ); - if( next_x < 0 ) + timeMap::iterator it = time_map.begin(); + p.setPen( QColor( 0xCF, 0xD9, 0xFF ) ); + while( it+1 != time_map.end() ) { - ++it; - continue; - } + // skip this section if it occurs completely before the + // visible area + int next_x = xCoordOfTick( (it+1).key() ); + if( next_x < 0 ) + { + ++it; + continue; + } - int x = xCoordOfTick( it.key() ); - if( x > width() ) - { - break; - } + int x = xCoordOfTick( it.key() ); + if( x > width() ) + { + break; + } - bool is_selected = FALSE; - // if we're in move-mode, we may only draw - // values in selected area, that have originally - // been selected and not values that are now in - // selection because the user moved it... - if( m_editMode == MOVE ) - { - if( m_selValuesForMove.contains( it.key() ) ) + bool is_selected = FALSE; + // if we're in move-mode, we may only draw + // values in selected area, that have originally + // been selected and not values that are now in + // selection because the user moved it... + if( m_editMode == MOVE ) + { + if( m_selValuesForMove.contains( it.key() ) ) + { + is_selected = TRUE; + } + } + else if( it.value() >= selLevel_start && + it.value() <= selLevel_end && + it.key() >= sel_pos_start && + it.key() + len_ticks <= sel_pos_end ) { is_selected = TRUE; } - } - else if( it.value() >= selLevel_start && - it.value() <= selLevel_end && - it.key() >= sel_pos_start && - it.key() + len_ticks <= sel_pos_end ) - { - is_selected = TRUE; + + float *values = m_pattern->valuesAfter( it.key() ); + for( int i = 0; i < (it+1).key() - it.key(); i++ ) + { + drawLevelTick( p, it.key() + i, values[i], + is_selected ); + } + delete [] values; + + // Draw circle + drawAutomationPoint(p, it); + + ++it; } - float *values = m_pattern->valuesAfter( it.key() ); - for( int i = 0; i < (it+1).key() - it.key(); i++ ) - { - drawLevelTick( p, it.key() + i, values[i], - is_selected ); - } - delete [] values; + Q_ASSERT( it == time_map.end()-1 ); - // Draw circle + for( int i = it.key(), x = xCoordOfTick( i ); x <= width(); + i++, x = xCoordOfTick( i ) ) + { + // TODO: Find out if the section after the last control + // point is able to be selected and if so set this + // boolean correctly + drawLevelTick( p, i, it.value(), false ); + } + // Draw circle(the last one) drawAutomationPoint(p, it); - - ++it; } - - Q_ASSERT( it == time_map.end()-1 ); - - for( int i = it.key(), x = xCoordOfTick( i ); x <= width(); - i++, x = xCoordOfTick( i ) ) - { - // TODO: Find out if the section after the last control - // point is able to be selected and if so set this - // boolean correctly - drawLevelTick( p, i, it.value(), false ); - } - // Draw circle(the last one) - drawAutomationPoint(p, it); } else {