void Segment::removeElement(int track) { Element* el = element(track); if (el->isChordRest()) { ChordRest* cr = (ChordRest*)el; Beam* beam = cr->beam(); if (beam) beam->remove(cr); Tuplet* tuplet = cr->tuplet(); if (tuplet) tuplet->remove(cr); } }
void SwingDetector::applySwing() { if (elements.size() != 2 && elements.size() != 3) return; Tuplet *tuplet = nullptr; for (ChordRest *el: elements) { el->setDurationType(TDuration::DurationType::V_EIGHTH); el->setTicks(Fraction(1, 8)); el->setDots(0); if (el->tuplet()) { if (!tuplet) tuplet = el->tuplet(); tuplet->remove(el); el->setTuplet(nullptr); } } const ChordRest *first = elements.front(); const int startTick = first->segment()->tick().ticks(); ChordRest *last = elements.back(); last->segment()->remove(last); Segment *s = last->measure()->getSegment(SegmentType::ChordRest, Fraction::fromTicks(startTick + MScore::division / 2)); s->add(last); if (elements.size() == 3) { // remove central rest ChordRest *cr = elements[1]; cr->score()->removeElement(cr); delete cr; } if (tuplet) { // delete tuplet delete tuplet; tuplet = nullptr; } if (!swingApplied) swingApplied = true; }