Logo Search packages:      
Sourcecode: canorus version File versions  Download package

bool CAVoice::remove ( CAMusElement elt,
bool  updateSigns = true 
)

Removes the given music element elt from this voice, if the element is playable or from all the voices in the staff, if non-playable and part of the staff.

If updateSigns is True, startTimes of elements after the removed one are decreased including the shared signs. Otherwise only timeStarts for playable elements are effected.

Warning:
This function doesn't destroy the object, but only removes its reference in the voice.
Note:
Due to speed issues, voices are NOT synchronized for every inserted element. User should manually call CAStaff::synchronizeVoices().
Returns true, if the element was found and removed; otherwise false.

Definition at line 298 of file voice.cpp.

References CAMusElement::addMark(), CANote::getChord(), CANote::isFirstInChord(), CANote::isPartOfChord(), CAMusElement::isPlayable(), CAMusElement::markList(), musElementList(), CAMusElement::musElementType(), CANote::phrasingSlurEnd(), CANote::phrasingSlurStart(), CAMusElement::removeMark(), CANote::setPhrasingSlurEnd(), CANote::setPhrasingSlurStart(), CANote::setSlurEnd(), CANote::setSlurStart(), CANote::slurEnd(), CANote::slurStart(), CAMusElement::timeLength(), CAPlayable::tuplet(), updateTimes(), CAStaff::voiceAt(), and CAStaff::voiceCount().

Referenced by CATuplet::assignTimes(), CAMainWin::deleteSelection(), insertInTupletAndVoiceAt(), CAMainWin::insertMusElementAt(), CAStaff::remove(), CATuplet::resetTimes(), CAMainWin::scoreViewPortKeyPress(), CAMainWin::sourceViewPortCommit(), and CAPlayable::~CAPlayable().

                                                          {
      if ( _musElementList.contains(elt) ) {    // if the search element is found
            if ( !elt->isPlayable() && staff() ) {          // element is shared - remove it from all the voices
                  for (int i=0; i<staff()->voiceCount(); i++) {
                        staff()->voiceAt(i)->musElementList().removeAll(elt);
                  }
            } else {
                  // element is playable
                  if ( elt->musElementType()==CAMusElement::Note ) {
                        CANote *n = static_cast<CANote*>(elt);
                        if ( n->isPartOfChord() && n->isFirstInChord() ) {
                              // if the note is the first in the chord, the slurs and marks should be relinked to the 2nd in the chord
                              CANote *prevNote = n->getChord().at(1);
                              prevNote->setSlurStart( n->slurStart() );
                              prevNote->setSlurEnd( n->slurEnd() );
                              prevNote->setPhrasingSlurStart( n->phrasingSlurStart() );
                              prevNote->setPhrasingSlurEnd( n->phrasingSlurEnd() );

                              for (int i=0; i<n->markList().size(); i++) {
                                    if ( n->markList()[i]->isCommon() ) {
                                          prevNote->addMark( n->markList()[i] );
                                          n->markList()[i]->setAssociatedElement( prevNote );
                                          n->removeMark( n->markList()[i--] );
                                    }
                              }
                        } else if ( !(n->isPartOfChord()) ) {
                              if ( n->slurStart() ) delete n->slurStart();
                              if ( n->slurEnd() ) delete n->slurEnd();
                              if ( n->phrasingSlurStart() ) delete n->phrasingSlurStart();
                              if ( n->phrasingSlurEnd() ) delete n->phrasingSlurEnd();
                              if ( n->tuplet() ) delete n->tuplet();

                              updateTimes( musElementList().indexOf(elt)+1, elt->timeLength()*(-1), updateSigns ); // shift back timeStarts of playable elements after it
                        }
                  } else {
                        if ( elt->isPlayable() && static_cast<CAPlayable*>(elt)->tuplet() ) delete static_cast<CAPlayable*>(elt)->tuplet();
                        updateTimes( musElementList().indexOf(elt)+1, elt->timeLength()*(-1), updateSigns ); // shift back timeStarts of playable elements after it
                  }

                  musElementList().removeAll(elt);          // removes the element from the voice music element list
            }

            return true;
      } else {
            return false;
      }
}


Generated by  Doxygen 1.6.0   Back to index