MuseScore/libmscore/range.cpp

785 lines
30 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012-2016 Werner Schweer
2012-05-26 14:26:10 +02:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "range.h"
#include "measure.h"
#include "segment.h"
#include "rest.h"
#include "chord.h"
#include "score.h"
#include "slur.h"
2013-08-22 12:18:14 +02:00
#include "tie.h"
2012-05-26 14:26:10 +02:00
#include "note.h"
#include "tuplet.h"
#include "barline.h"
2012-05-26 14:26:10 +02:00
#include "utils.h"
2014-05-14 19:19:29 +02:00
#include "staff.h"
#include "excerpt.h"
2016-12-06 09:35:52 +01:00
#include "repeat.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// cleanupTuplet
//---------------------------------------------------------
static void cleanupTuplet(Tuplet* t)
{
foreach (DurationElement* e, t->elements()) {
if (e->isTuplet())
cleanupTuplet(toTuplet(e));
2012-05-26 14:26:10 +02:00
delete e;
}
}
//---------------------------------------------------------
// TrackList
//---------------------------------------------------------
TrackList::~TrackList()
{
int n = size();
for (int i = 0; i < n; ++i) {
Element* e = at(i);
if (e->isTuplet()) {
Tuplet* t = toTuplet(e);
2012-05-26 14:26:10 +02:00
cleanupTuplet(t);
}
else
delete e;
}
}
//---------------------------------------------------------
// appendTuplet
//---------------------------------------------------------
void TrackList::appendTuplet(Tuplet* srcTuplet, Tuplet* dstTuplet)
{
for (DurationElement* de : srcTuplet->elements()) {
2016-11-29 09:26:43 +01:00
DurationElement* e = toDurationElement(de->clone());
dstTuplet->add(e);
if (de->isTuplet()) {
Tuplet* st = toTuplet(de);
Tuplet* dt = toTuplet(e);
appendTuplet(st, dt);
}
}
}
2016-12-06 09:35:52 +01:00
//---------------------------------------------------------
// combineTuplet
//---------------------------------------------------------
void TrackList::combineTuplet(Tuplet* dst, Tuplet* src)
{
dst->setDuration(dst->duration() * 2);
dst->setBaseLen(dst->baseLen().shift(-1));
// try to combine tie'd notes
unsigned idx = 0;
if (dst->elements().back()->isChord() && src->elements().front()->isChord()) {
Chord* chord = toChord(src->elements().front());
bool akkumulateChord = true;
for (Note* n : chord->notes()) {
if (!n->tieBack() || !n->tieBack()->generated()) {
akkumulateChord = false;
break;
}
}
if (akkumulateChord) {
Chord* bc = toChord(dst->elements().back());
bc->setDuration(bc->duration() + chord->duration());
// forward ties
int i = 0;
for (Note* n : bc->notes()) {
n->setTieFor(chord->notes()[i]->tieFor());
++i;
}
idx = 1; // skip first src element
}
}
for (; idx < src->elements().size(); ++idx) {
DurationElement* de = src->elements()[idx];
DurationElement* e = toDurationElement(de->clone());
dst->add(e);
if (de->isTuplet()) {
Tuplet* st = toTuplet(de);
Tuplet* dt = toTuplet(e);
appendTuplet(st, dt);
}
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// append
//---------------------------------------------------------
2013-06-19 16:25:29 +02:00
void TrackList::append(Element* e)
2012-05-26 14:26:10 +02:00
{
if (e->isDurationElement()) {
2016-11-29 09:26:43 +01:00
Fraction d = toDurationElement(e)->duration();
2012-05-26 14:26:10 +02:00
_duration += d;
bool accumulateRest = e->isRest() && !empty() && back()->isRest();
Segment* s = accumulateRest ? toRest(e)->segment() : 0;
2012-05-26 14:26:10 +02:00
if (s && !s->score()->isSpannerStartEnd(s->tick(), e->track()) && !s->annotations().size()) {
2012-05-26 14:26:10 +02:00
// akkumulate rests
Rest* rest = toRest(back());
2012-05-26 14:26:10 +02:00
Fraction d = rest->duration();
d += toRest(e)->duration();
2012-05-26 14:26:10 +02:00
rest->setDuration(d);
}
2016-12-03 20:27:21 +01:00
else {
2016-12-06 09:35:52 +01:00
Element* element = 0;
if (e->isTuplet()) {
2016-12-06 09:35:52 +01:00
Tuplet* src = toTuplet(e);
if (src->generated() && back()->isTuplet()) {
Tuplet* b = toTuplet(back());
combineTuplet(b, src);
}
else {
element = e->clone();
Tuplet* dst = toTuplet(element);
appendTuplet(src, dst);
}
2012-05-26 14:26:10 +02:00
}
else {
2016-12-06 09:35:52 +01:00
element = e->clone();
ChordRest* src = toChordRest(e);
2012-05-26 14:26:10 +02:00
Segment* s = src->segment();
for (Element* ee : s->annotations()) {
2012-05-26 14:26:10 +02:00
if (ee->track() == e->track())
2013-06-19 16:25:29 +02:00
_range->annotations.push_back({ s->tick(), ee->clone() });
2012-05-26 14:26:10 +02:00
}
2016-12-03 20:27:21 +01:00
if (e->isChord()) {
Chord* chord = toChord(e);
bool akkumulateChord = true;
for (Note* n : chord->notes()) {
if (!n->tieBack() || !n->tieBack()->generated()) {
akkumulateChord = false;
break;
}
}
if (akkumulateChord && back()->isChord()) {
Chord* bc = toChord(back());
Fraction d = bc->duration();
d += bc->duration();
bc->setDuration(d);
// forward ties
int idx = 0;
for (Note* n : bc->notes()) {
n->setTieFor(chord->notes()[idx]->tieFor());
++idx;
}
delete element;
element = 0;
}
}
}
if (element) {
element->setSelected(false);
QList<Element*>::append(element);
2012-05-26 14:26:10 +02:00
}
}
}
2017-03-14 17:00:38 +01:00
else {
Element* c = e->clone();
c->setParent(0);
QList<Element*>::append(c);
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// appendGap
//---------------------------------------------------------
void TrackList::appendGap(const Fraction& d)
{
2014-05-14 19:19:29 +02:00
if (d.isZero())
return;
2016-02-06 22:03:43 +01:00
Element* e = empty() ? 0 : back();
if (e && e->isRest()) {
Rest* rest = toRest(back());
2012-05-26 14:26:10 +02:00
Fraction dd = rest->duration();
dd += d;
_duration += d;
2012-05-26 14:26:10 +02:00
rest->setDuration(dd);
}
else {
Rest* rest = new Rest(0);
rest->setDuration(d);
QList<Element*>::append(rest);
2013-01-18 14:42:11 +01:00
_duration += d;
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// truncate
// reduce len of last gap by f
//---------------------------------------------------------
bool TrackList::truncate(const Fraction& f)
{
if (empty())
return true;
Element* e = back();
if (!e->isRest())
return false;
Rest* r = toRest(e);
if (r->duration() < f)
return false;
2016-12-06 15:16:03 +01:00
if (r->duration() == f) {
removeLast();
delete r;
}
else
r->setDuration(r->duration() - f);
_duration -= f;
return true;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// read
//---------------------------------------------------------
2014-11-13 11:53:42 +01:00
void TrackList::read(const Segment* fs, const Segment* es)
2012-05-26 14:26:10 +02:00
{
int tick = fs->tick();
int gap = 0;
2016-03-30 22:33:04 +02:00
while (fs && !fs->enabled())
fs = fs->next1();
const Segment* s;
for (s = fs; s && (s != es); s = s->next1enabled()) {
2014-11-13 11:53:42 +01:00
Element* e = s->element(_track);
if (!e || e->generated()) {
for (Element* ee : s->annotations()) {
2014-11-13 11:53:42 +01:00
if (ee->track() == _track)
_range->annotations.push_back({ s->tick(), ee->clone() });
}
2013-01-18 14:42:11 +01:00
continue;
}
2016-12-06 09:35:52 +01:00
if (e->isRepeatMeasure()) {
// TODO: copy previous measure contents?
RepeatMeasure* rm = toRepeatMeasure(e);
Rest r(*rm);
append(&r);
tick += r.duration().ticks();
}
else if (e->isChordRest()) {
DurationElement* de = toDurationElement(e);
2013-01-18 14:42:11 +01:00
gap = s->tick() - tick;
if (de->tuplet()) {
2016-12-06 09:35:52 +01:00
Tuplet* t = de->topTuplet();
s = skipTuplet(t); // continue with first chord/rest after tuplet
de = t;
2012-05-26 14:26:10 +02:00
}
2013-01-18 14:42:11 +01:00
if (gap) {
appendGap(Fraction::fromTicks(gap));
tick += gap;
}
2013-06-19 16:25:29 +02:00
append(de);
2014-11-10 13:41:25 +01:00
tick += de->duration().ticks();
2012-05-26 14:26:10 +02:00
}
else if (e->isBarLine()) {
BarLine* bl = toBarLine(e);
if (bl->barLineType() != BarLineType::NORMAL)
append(e);
}
2013-01-18 14:42:11 +01:00
else
2013-06-19 16:25:29 +02:00
append(e);
2012-05-26 14:26:10 +02:00
}
gap = es->tick() - tick;
if (gap)
appendGap(Fraction::fromTicks(gap));
//
// connect ties
//
int n = size();
for (int i = 0; i < n; ++i) {
Element* e = at(i);
if (!e->isChord())
2012-05-26 14:26:10 +02:00
continue;
Chord* chord = toChord(e);
for (Note* n1 : chord->notes()) {
2012-05-26 14:26:10 +02:00
Tie* tie = n1->tieFor();
if (!tie)
continue;
for (int k = i+1; k < n; ++k) {
Element* ee = at(k);
if (!ee->isChord())
2012-05-26 14:26:10 +02:00
continue;
Chord* c2 = toChord(ee);
2012-05-26 14:26:10 +02:00
bool found = false;
for (Note* n2 : c2->notes()) {
2012-05-26 14:26:10 +02:00
if (n1->pitch() == n2->pitch()) {
tie->setEndNote(n2);
n2->setTieBack(tie);
found = true;
break;
}
}
if (!found)
2012-12-05 14:01:41 +01:00
qDebug("Tied note not found");
2012-05-26 14:26:10 +02:00
break;
}
}
}
}
//---------------------------------------------------------
// writeTuplet
// measure - current measure
// rest - available time in measure
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
Tuplet* TrackList::writeTuplet(Tuplet* parent, Tuplet* tuplet, Measure*& measure, Fraction& rest) const
2012-05-26 14:26:10 +02:00
{
Score* score = measure->score();
Tuplet* dt = tuplet->clone();
2012-05-26 14:26:10 +02:00
dt->setParent(measure);
Fraction d = tuplet->duration();
if (d > rest) {
// we must split the tuplet
dt->setDuration(d * Fraction(1, 2));
dt->setBaseLen(tuplet->baseLen().shift(1));
}
if (parent)
parent->add(dt);
for (DurationElement* e : tuplet->elements()) {
Fraction duration = e->globalDuration();
Tuplet* tt = dt;
Fraction ratio = Fraction(1, 1);
while (tt) {
ratio *= tt->ratio();
tt = tt->tuplet();
2012-05-26 14:26:10 +02:00
}
bool firstpart = true;
while (duration > 0) {
2016-12-06 09:35:52 +01:00
if (rest.isZero()) {
if (measure->nextMeasure()) {
measure = measure->nextMeasure();
rest = measure->len();
if (e != tuplet->elements().back()) {
// create second part of split tuplet
2016-12-06 09:35:52 +01:00
dt = dt->clone();
dt->setGenerated(true);
dt->setParent(measure);
Tuplet* pt = dt;
while (parent) {
Tuplet* tt = parent->clone();
tt->setGenerated(true);
tt->setParent(measure);
tt->add(pt);
pt = tt;
parent = parent->tuplet();
}
}
}
else {
qFatal("premature end of measure list in track %d, rest %d/%d",
_track, duration.numerator(), duration.denominator());
}
}
Fraction d = qMin(rest, duration);
if (e->isChordRest()) {
Fraction dd = d * ratio;
std::vector<TDuration> dl = toDurationList(dd, false);
for (const TDuration& k : dl) {
2017-03-08 13:12:26 +01:00
Segment* segment = measure->undoGetSegment(SegmentType::ChordRest, measure->len() - rest);
Fraction gd = k.fraction() / ratio;
ChordRest* cr = toChordRest(e->clone());
2016-12-06 09:35:52 +01:00
if (!firstpart)
cr->removeMarkings(true);
cr->setScore(score);
cr->setTrack(_track);
segment->add(cr);
cr->setDuration(k.fraction());
cr->setDurationType(k);
rest -= gd;
duration -= gd;
if (cr->isChord()) {
2016-12-06 09:35:52 +01:00
for (Note* note : toChord(cr)->notes()) {
if (!duration.isZero() && !note->tieFor()) {
Tie* tie = new Tie(score);
2016-12-06 09:35:52 +01:00
tie->setGenerated(true);
note->add(tie);
}
}
}
dt->add(cr);
firstpart = false;
}
}
else if (e->isTuplet()) {
Tuplet* tt = toTuplet(e);
Tuplet* ttt = writeTuplet(dt, tt, measure, rest);
dt = ttt->tuplet();
parent = dt->tuplet();
duration = Fraction();
}
firstpart = false;
2012-05-26 14:26:10 +02:00
}
}
return dt;
}
//---------------------------------------------------------
2016-12-06 09:35:52 +01:00
// checkRest
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2016-12-06 09:35:52 +01:00
static void checkRest(Fraction& rest, Measure*& m, const Fraction& d)
2012-05-26 14:26:10 +02:00
{
2016-12-06 09:35:52 +01:00
if (rest.isZero()) {
if (m->nextMeasure()) {
m = m->nextMeasure();
rest = m->len();
2012-05-26 14:26:10 +02:00
}
2016-12-06 09:35:52 +01:00
else {
qFatal("premature end of measure list, rest %d/%d", d.numerator(), d.denominator());
2013-06-10 11:03:34 +02:00
}
}
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// write
2014-11-13 11:53:42 +01:00
// rewrite notes into measure list measure
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
bool TrackList::write(Score* score, int tick) const
2012-05-26 14:26:10 +02:00
{
2017-03-29 00:53:02 +02:00
if ((_track % VOICES) && size() == 1 && at(0)->isRest()) // dont write rests in voice > 0
return true;
Measure* measure = score->tick2measure(tick);
2012-05-26 14:26:10 +02:00
Measure* m = measure;
2017-03-29 00:53:02 +02:00
Fraction remains = Fraction::fromTicks(m->endTick() - tick);
2012-05-26 14:26:10 +02:00
Segment* segment = 0;
for (Element* e : *this) {
2012-05-26 14:26:10 +02:00
if (e->isDurationElement()) {
Fraction duration = toDurationElement(e)->duration();
2017-03-29 00:53:02 +02:00
checkRest(remains, m, duration); // go to next measure, if necessary
if (duration > remains && e->isTuplet()) {
// experimental: allow tuplet split in the middle
2017-03-29 00:53:02 +02:00
if (duration != remains * 2) {
MScore::setError(CANNOT_SPLIT_TUPLET);
return false;
}
2012-05-26 14:26:10 +02:00
}
bool firstpart = true;
while (duration > 0) {
2017-03-29 00:53:02 +02:00
if ((e->isRest() || e->isRepeatMeasure()) && (duration >= remains || e == back()) && (remains == m->len())) {
2012-05-26 14:26:10 +02:00
//
// handle full measure rest
//
2017-03-29 00:53:02 +02:00
Segment* segment = m->getSegment(SegmentType::ChordRest, m->len() - remains);
2014-11-13 11:53:42 +01:00
if ((_track % VOICES) == 0) {
2012-05-26 14:26:10 +02:00
// write only for voice 1
Rest* r = new Rest(score, TDuration::DurationType::V_MEASURE);
// ideally we should be using stretchedLen
// but this is not valid during rewrite when adding time signatures
// since the time signature has not been added yet
2015-03-20 07:11:30 +01:00
//Fraction stretchedLen = m->stretchedLen(staff);
//r->setDuration(stretchedLen);
r->setDuration(m->len());
2014-11-13 11:53:42 +01:00
r->setTrack(_track);
2012-05-26 14:26:10 +02:00
segment->add(r);
}
duration -= m->len();
2017-03-29 00:53:02 +02:00
remains.set(0, 1);
2012-05-26 14:26:10 +02:00
}
2016-12-06 09:35:52 +01:00
else if (e->isChordRest()) {
2017-03-29 00:53:02 +02:00
Fraction d = qMin(remains, duration);
2016-12-06 09:35:52 +01:00
std::vector<TDuration> dl = toDurationList(d, e->isChord());
if (dl.empty())
qDebug("duration d %d/%d", d.numerator(), d.denominator());
Q_ASSERT(!dl.empty());
for (const TDuration& k : dl) {
2017-03-29 00:53:02 +02:00
segment = m->undoGetSegment(SegmentType::ChordRest, m->len() - remains);
2016-12-06 09:35:52 +01:00
ChordRest* cr = toChordRest(e->clone());
if (!firstpart)
2016-12-06 09:35:52 +01:00
cr->removeMarkings(true);
cr->setTrack(_track);
cr->setScore(score);
Fraction gd = k.fraction();
cr->setDuration(gd);
cr->setDurationType(k);
segment->add(cr);
duration -= gd;
2017-03-29 00:53:02 +02:00
remains -= gd;
2016-12-06 09:35:52 +01:00
if (cr->isChord()) {
for (Note* note : toChord(cr)->notes()) {
if (!duration.isZero() && !note->tieFor()) {
Tie* tie = new Tie(score);
2016-12-03 20:27:21 +01:00
tie->setGenerated(true);
2016-12-06 09:35:52 +01:00
note->add(tie);
}
2012-05-26 14:26:10 +02:00
}
}
}
}
2016-12-06 09:35:52 +01:00
else if (e->isTuplet()) {
2017-03-29 00:53:02 +02:00
writeTuplet(0, toTuplet(e), m, remains);
2016-12-06 09:35:52 +01:00
duration = Fraction();
2012-05-26 14:26:10 +02:00
}
firstpart = false;
2016-12-06 09:35:52 +01:00
if (duration > 0)
2017-03-29 00:53:02 +02:00
checkRest(remains, m, duration); // go to next measure, if necessary
2012-05-26 14:26:10 +02:00
}
}
2016-10-20 11:32:07 +02:00
else if (e->isBarLine()) {
2016-12-06 09:35:52 +01:00
// if (pos.numerator() == 0 && m) {
// BarLineType t = toBarLine(e)->barLineType();
2016-01-04 14:48:58 +01:00
// Measure* pm = m->prevMeasure();
//TODO if (pm)
// pm->setEndBarLineType(t,0);
2016-12-06 09:35:52 +01:00
// }
}
else if (e->isClef()) {
Segment* segment;
2017-03-29 00:53:02 +02:00
if (remains == m->len() && m->tick() > 0) {
Measure* pm = m->prevMeasure();
2017-03-08 13:12:26 +01:00
segment = pm->undoGetSegment(SegmentType::Clef, pm->len());
}
2017-03-29 00:53:02 +02:00
else if (remains != m->len())
segment = m->undoGetSegment(SegmentType::Clef, m->len() - remains);
else
2017-03-08 13:12:26 +01:00
segment = m->undoGetSegmentR(SegmentType::HeaderClef, 0);
Element* ne = e->clone();
ne->setScore(score);
ne->setTrack(_track);
segment->add(ne);
}
2012-05-26 14:26:10 +02:00
else {
2016-10-20 11:32:07 +02:00
if (!m)
2012-05-26 14:26:10 +02:00
break;
// add the element in its own segment;
// but KeySig has to be at start of (current) measure
2017-03-29 00:53:02 +02:00
Segment* segment = m->undoGetSegment(Segment::segmentType(e->type()), e->isKeySig() ? Fraction() : m->len() - remains);
2012-05-26 14:26:10 +02:00
Element* ne = e->clone();
ne->setScore(score);
2014-11-13 11:53:42 +01:00
ne->setTrack(_track);
2012-05-26 14:26:10 +02:00
segment->add(ne);
}
}
//
2016-12-06 09:35:52 +01:00
// connect ties from measure->first() to segment
2012-05-26 14:26:10 +02:00
//
2014-08-11 21:17:55 +02:00
2012-05-26 14:26:10 +02:00
for (Segment* s = measure->first(); s; s = s->next1()) {
Element* e = s->element(_track);
if (!e || !e->isChord())
2012-05-26 14:26:10 +02:00
continue;
Chord* chord = toChord(e);
for (Note* n : chord->notes()) {
2012-05-26 14:26:10 +02:00
Tie* tie = n->tieFor();
if (!tie)
continue;
Note* nn = searchTieNote(n);
if (nn) {
tie->setEndNote(nn);
nn->setTieBack(tie);
}
}
if (s == segment)
break;
}
return true;
}
//---------------------------------------------------------
// ScoreRange
//---------------------------------------------------------
ScoreRange::~ScoreRange()
{
qDeleteAll(tracks);
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2016-12-06 09:35:52 +01:00
void ScoreRange::read(Segment* first, Segment* last, bool readSpanner)
2012-05-26 14:26:10 +02:00
{
_first = first;
_last = last;
Score* score = first->score();
2014-11-13 11:53:42 +01:00
QList<int> sl = score->uniqueStaves();
2014-05-14 19:19:29 +02:00
int startTrack = 0;
2014-11-13 11:53:42 +01:00
int endTrack = score->nstaves() * VOICES;
2013-06-19 16:25:29 +02:00
spanner.clear();
2016-12-06 09:35:52 +01:00
if (readSpanner) {
int stick = first->tick();
int etick = last->tick();
for (auto i : first->score()->spanner()) {
Spanner* s = i.second;
if (s->tick() >= stick && s->tick() < etick && s->track() >= startTrack && s->track() < endTrack) {
2017-12-20 16:49:30 +01:00
Spanner* ns = toSpanner(s->clone());
2017-03-14 17:00:38 +01:00
ns->setParent(0);
ns->setStartElement(0);
ns->setEndElement(0);
2016-12-06 09:35:52 +01:00
ns->setTick(ns->tick() - stick);
spanner.push_back(ns);
}
2013-06-19 16:25:29 +02:00
}
}
2014-11-13 11:53:42 +01:00
for (int staffIdx : sl) {
int sTrack = staffIdx * VOICES;
int eTrack = sTrack + VOICES;
for (int track = sTrack; track < eTrack; ++track) {
TrackList* dl = new TrackList(this);
dl->setTrack(track);
dl->read(first, last);
tracks.append(dl);
}
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
2014-05-14 19:19:29 +02:00
bool ScoreRange::write(Score* score, int tick) const
2012-05-26 14:26:10 +02:00
{
2014-05-14 19:19:29 +02:00
for (TrackList* dl : tracks) {
2014-11-13 11:53:42 +01:00
int track = dl->track();
if (!dl->write(score, tick))
2012-05-26 14:26:10 +02:00
return false;
if ((track % VOICES) == VOICES - 1) {
// clone staff if appropriate after all voices have been copied
2014-05-14 19:19:29 +02:00
int staffIdx = track / VOICES;
Staff* ostaff = score->staff(staffIdx);
2018-04-27 13:29:20 +02:00
const LinkedElements* linkedStaves = ostaff->links();
2014-05-14 19:19:29 +02:00
if (linkedStaves) {
2018-04-27 13:29:20 +02:00
for (auto le : *linkedStaves) {
Staff* nstaff = toStaff(le);
2014-05-14 19:19:29 +02:00
if (nstaff == ostaff)
continue;
Excerpt::cloneStaff2(ostaff, nstaff, tick, tick + dl->duration().ticks());
2014-05-14 19:19:29 +02:00
}
}
}
++track;
}
2013-06-19 16:25:29 +02:00
for (Spanner* s : spanner) {
2016-12-03 20:27:21 +01:00
s->setTick(s->tick() + tick);
if (s->isSlur()) {
Slur* slur = toSlur(s);
2014-07-27 18:55:05 +02:00
if (slur->startCR()->isGrace()) {
Chord* sc = slur->startChord();
int idx = sc->graceIndex();
Chord* dc = toChord(score->findCR(s->tick(), s->track()));
2014-07-27 18:55:05 +02:00
s->setStartElement(dc->graceNotes()[idx]);
}
else
s->setStartElement(0);
if (slur->endCR()->isGrace()) {
Chord* sc = slur->endChord();
int idx = sc->graceIndex();
Chord* dc = toChord(score->findCR(s->tick2(), s->track2()));
2014-07-27 18:55:05 +02:00
s->setEndElement(dc->graceNotes()[idx]);
}
else
s->setEndElement(0);
}
2013-06-19 16:25:29 +02:00
score->undoAddElement(s);
2012-05-26 14:26:10 +02:00
}
2013-06-19 16:25:29 +02:00
for (const Annotation& a : annotations) {
Measure* tm = score->tick2measure(a.tick);
Segment *op = toSegment(a.e->parent());
Segment* s = tm->undoGetSegment(op->segmentType(), a.tick);
2013-06-19 16:25:29 +02:00
if (s) {
a.e->setParent(s);
score->undoAddElement(a.e);
2013-01-18 14:42:11 +01:00
}
}
2014-05-14 19:19:29 +02:00
return true;
2013-01-18 14:42:11 +01:00
}
//---------------------------------------------------------
// fill
//---------------------------------------------------------
void ScoreRange::fill(const Fraction& f)
{
for (auto t : tracks)
t->appendGap(f);
}
//---------------------------------------------------------
// truncate
// reduce len of last gap by f
//---------------------------------------------------------
bool ScoreRange::truncate(const Fraction& f)
{
for (TrackList* dl : tracks) {
if (dl->empty())
continue;
Element* e = dl->back();
if (!e->isRest())
return false;
Rest* r = toRest(e);
if (r->duration() < f)
return false;
}
for (TrackList* dl : tracks)
dl->truncate(f);
return true;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// duration
//---------------------------------------------------------
Fraction ScoreRange::duration() const
{
2016-02-06 22:03:43 +01:00
return tracks.empty() ? Fraction() : tracks[0]->duration();
2012-05-26 14:26:10 +02:00
}
2016-12-06 09:35:52 +01:00
//---------------------------------------------------------
// dump
//---------------------------------------------------------
void TrackList::dump() const
{
qDebug("elements %d, duration %d/%d", size(), _duration.numerator(), _duration.denominator());
for (Element* e : *this) {
if (e->isDurationElement()) {
Fraction d = toDurationElement(e)->duration();
2016-12-06 15:16:03 +01:00
qDebug(" %s %d/%d", e->name(), d.numerator(), d.denominator());
2016-12-06 09:35:52 +01:00
}
2016-12-06 15:16:03 +01:00
else
qDebug(" %s", e->name());
2016-12-06 09:35:52 +01:00
}
}
2013-05-13 18:49:17 +02:00
}