Skip to content

Commit

Permalink
update global insert: combine tuplets
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Dec 6, 2016
1 parent 8d8ceee commit 1f243b5
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 290 deletions.
32 changes: 13 additions & 19 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ Chord::Chord(const Chord& c, bool link)
}

for (Element* e : c.el()) {
if (e->type() == Element::Type::CHORDLINE) {
ChordLine* cl = static_cast<ChordLine*>(e);
if (e->isChordLine()) {
ChordLine* cl = toChordLine(e);
ChordLine* ncl = new ChordLine(*cl);
add(ncl);
if (link)
score()->undo(new Link(const_cast<ChordLine*>(ncl), cl));
score()->undo(new Link(ncl, cl));
}
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ void Chord::add(Element* e)
_hook = toHook(e);
break;
case Element::Type::CHORDLINE:
_el.push_back(e);
el().push_back(e);
break;
case Element::Type::STEM_SLASH:
Q_ASSERT(!_stemSlash);
Expand Down Expand Up @@ -580,7 +580,7 @@ void Chord::remove(Element* e)
_stemSlash = 0;
break;
case Element::Type::CHORDLINE:
_el.remove(e);
el().remove(e);
break;
case Element::Type::CHORD:
{
Expand Down Expand Up @@ -950,7 +950,7 @@ void Chord::write(XmlWriter& xml) const
_arpeggio->write(xml);
if (_tremolo && tremoloChordType() != TremoloChordType::TremoloSecondNote)
_tremolo->write(xml);
for (Element* e : _el)
for (Element* e : el())
e->write(xml);
xml.etag();
}
Expand Down Expand Up @@ -1144,10 +1144,10 @@ void Chord::scanElements(void* data, void (*func)(void*, Element*), bool all)
int n = _notes.size();
for (int i = 0; i < n; ++i)
_notes.at(i)->scanElements(data, func, all);
n = _el.size();
// n = el().size();
for (Chord* chord : _graceNotes)
chord->scanElements(data, func, all);
for (Element* e : _el)
for (Element* e : el())
e->scanElements(data, func, all);
ChordRest::scanElements(data, func, all);
}
Expand All @@ -1172,7 +1172,7 @@ void Chord::processSiblings(std::function<void(Element*)> func) const
func(ll);
for (Note* note : _notes)
func(note);
for (Element* e : _el)
for (Element* e : el())
func(e);
for (Chord* chord : _graceNotes) // process grace notes last, needed for correct shape calculation
func(chord);
Expand Down Expand Up @@ -2051,7 +2051,7 @@ void Chord::layoutPitched()
_spaceRw = xr;
}

for (Element* e : _el) {
for (Element* e : el()) {
if (e->type() == Element::Type::SLUR) // we cannot at this time as chordpositions are not fixed
continue;
e->layout();
Expand Down Expand Up @@ -2384,7 +2384,7 @@ void Chord::layoutTablature()
if (xr > _spaceRw)
_spaceRw = xr;
}
for (Element* e : _el) {
for (Element* e : el()) {
e->layout();
if (e->type() == Element::Type::CHORDLINE) {
QRectF tbbox = e->bbox().translated(e->pos());
Expand Down Expand Up @@ -3029,18 +3029,12 @@ void Chord::removeMarkings(bool keepTremolo)
remove(tremolo());
if (arpeggio())
remove(arpeggio());
for (Element* e : el())
remove(e);
for (Element* e : articulations())
remove(e);
for (Element* e : lyrics())
remove(e);
for (Element* e : graceNotes())
remove(e);
qDeleteAll(graceNotes());
for (Note* n : notes()) {
for (Element* e : n->el())
n->remove(e);
}
ChordRest::removeMarkings(keepTremolo);
}

//---------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class Chord : public ChordRest {
Arpeggio* _arpeggio;
Tremolo* _tremolo;
bool _endsGlissando;///< true if this chord is the ending point of a glissando (needed for layout)
ElementList _el; ///< chordline, slur
QVector<Chord*> _graceNotes;
int _graceIndex; ///< if this is a grace note, index in parent list

Expand Down Expand Up @@ -162,7 +161,7 @@ class Chord : public ChordRest {
StemSlash* stemSlash() const { return _stemSlash; }
bool slash();
void setSlash(bool flag, bool stemless);
void removeMarkings(bool keepTremolo = false);
virtual void removeMarkings(bool keepTremolo = false) override;

const QVector<Chord*>& graceNotes() const { return _graceNotes; }
QVector<Chord*>& graceNotes() { return _graceNotes; }
Expand Down Expand Up @@ -211,12 +210,7 @@ class Chord : public ChordRest {
void setPlayEventType(PlayEventType v) { _playEventType = v; }

TremoloChordType tremoloChordType() const;

ElementList& el() { return _el; }
const ElementList& el() const { return _el; }

QPointF layoutArticulation(Articulation*);

virtual void crossMeasureSetup(bool on);

virtual QVariant getProperty(P_ID propertyId) const override;
Expand Down
18 changes: 17 additions & 1 deletion libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ ChordRest::~ChordRest()
{
qDeleteAll(_articulations);
qDeleteAll(_lyrics);
qDeleteAll(_el);
delete _tabDur;
}

Expand Down Expand Up @@ -1069,7 +1070,7 @@ void ChordRest::add(Element* e)
{
e->setParent(this);
e->setTrack(track());
switch(e->type()) {
switch (e->type()) {
case Element::Type::ARTICULATION:
{
Articulation* a = toArticulation(e);
Expand Down Expand Up @@ -1452,5 +1453,20 @@ void ChordRest::flipLyrics(Lyrics* l)
l->undoChangeProperty(P_ID::PLACEMENT, int(p));
}

//---------------------------------------------------------
// removeMarkings
// - this is normally called after cloning a chord to tie a note over the barline
// - there is no special undo handling; the assumption is that undo will simply remove the cloned chord
// - two note tremolos are converted into simple notes
// - single note tremolos are optionally retained
//---------------------------------------------------------

void ChordRest::removeMarkings(bool /* keepTremolo */)
{
qDeleteAll(el());
qDeleteAll(articulations());
qDeleteAll(lyrics());
}

}

5 changes: 5 additions & 0 deletions libmscore/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ChordRest : public DurationElement {
Q_PROPERTY(int durationType READ durationTypeTicks WRITE setDurationType)
Q_PROPERTY(bool small READ small WRITE undoSetSmall)

ElementList _el;
TDuration _durationType;
int _staffMove; // -1, 0, +1, used for crossbeaming

Expand Down Expand Up @@ -156,6 +157,9 @@ class ChordRest : public DurationElement {
virtual void remove(Element*);
void removeDeleteBeam(bool beamed);

ElementList& el() { return _el; }
const ElementList& el() const { return _el; }

CrossMeasure crossMeasure() const { return _crossMeasure; }
void setCrossMeasure(CrossMeasure val) { _crossMeasure = val; }
virtual void crossMeasureSetup(bool /*on*/) { }
Expand All @@ -182,6 +186,7 @@ class ChordRest : public DurationElement {
virtual void computeUp() { _up = true; };

bool isFullMeasureRest() const { return _durationType == TDuration::DurationType::V_MEASURE; }
virtual void removeMarkings(bool keepTremolo = false);
};


Expand Down
2 changes: 1 addition & 1 deletion libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ QList<Fraction> Score::splitGapToMeasureBoundaries(ChordRest* cr, Fraction gap)

Tuplet* tuplet = cr->tuplet();
if (tuplet) {
if(tuplet->tuplet())
if (tuplet->tuplet())
return flist; // do no deal with nested tuplets
Fraction rest = Fraction::fromTicks(tuplet->tick() + tuplet->duration().ticks() - cr->segment()->tick()) * tuplet->ratio();
if (rest < gap)
Expand Down
2 changes: 1 addition & 1 deletion libmscore/durationtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void TDuration::shiftType(int v)
setType(DurationType::V_INVALID);
else {
int newValue = int(_val) + v;
if ((newValue < int(DurationType::V_LONG)) || (newValue > int(DurationType::V_128TH)))
if ((newValue < int(DurationType::V_LONG)) || (newValue > int(DurationType::V_1024TH)))
setType(DurationType::V_INVALID);
else
setType(DurationType(newValue));
Expand Down
5 changes: 1 addition & 4 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ Chord* Score::addChord(int tick, TDuration d, Chord* oc, bool genTie, Tuplet* tu

ChordRest* Score::addClone(ChordRest* cr, int tick, const TDuration& d)
{
qDebug(" %s at %d %s", cr->name(), tick, qPrintable(d.fraction().print()));
ChordRest* newcr;
// change a RepeatMeasure() into an Rest()
if (cr->isRepeatMeasure())
Expand Down Expand Up @@ -418,8 +417,6 @@ bool Score::rewriteMeasures(Measure* fm, Measure* lm, const Fraction& ns, int st

ScoreRange range;
range.read(fm->first(), lm->last());
if (!range.canWrite(ns))
return false;

//
// calculate number of required measures = nm
Expand Down Expand Up @@ -475,7 +472,7 @@ bool Score::rewriteMeasures(Measure* fm, Measure* lm, const Fraction& ns, int st
undoInsertTime(lm->endTick(), fill.ticks());

if (!range.write(masterScore(), fm->tick()))
qFatal("Cannot write measures");
return false;
connectTies(true);

if (noteEntryMode()) {
Expand Down
3 changes: 3 additions & 0 deletions libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class FiguredBass;
class StaffState;
class Arpeggio;
class Image;
class ChordLine;

enum class SymId;

Expand Down Expand Up @@ -778,6 +779,7 @@ class Element : public QObject, public ScoreElement {
CONVERT(StaffState, STAFF_STATE)
CONVERT(Arpeggio, ARPEGGIO)
CONVERT(Image, IMAGE)
CONVERT(ChordLine, CHORDLINE)
#undef CONVERT
};

Expand Down Expand Up @@ -889,6 +891,7 @@ static inline const a* to##a(const Element* e) { Q_ASSERT(e == 0 || e->type() ==
CONVERT(StaffState, STAFF_STATE)
CONVERT(Arpeggio, ARPEGGIO)
CONVERT(Image, IMAGE)
CONVERT(ChordLine, CHORDLINE)
#undef CONVERT

//---------------------------------------------------------
Expand Down
28 changes: 17 additions & 11 deletions libmscore/noteentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,30 +560,36 @@ void Score::globalInsertChord(const Position& pos)
Fraction fraction = duration.fraction();
ScoreRange r;

r.read(s1, s2);
r.read(s1, s2, false);

int sTrack = 0;
int eTrack = nstaves() * VOICES;
int stick = s1->tick();
int etick = s2->tick();
foreach (auto i, spanner()) {
Spanner* s = i.second;
if (s->tick() >= stick && s->tick() < etick && s->track() >= sTrack && s->track() < eTrack)
undoRemoveElement(s);
}
int strack = 0; // for now for all tracks
int etrack = nstaves() * VOICES;
int stick = s1->tick();
int etick = s2->tick();
int ticks = fraction.ticks();

Fraction len = r.duration();
if (!r.truncate(fraction))
appendMeasures(1);

putNote(pos, true);
int dtick = s1->tick() + fraction.ticks();
int dtick = s1->tick() + ticks;
int voiceOffsets[VOICES] { 0, 0, 0, 0 };
len = r.duration();
for (int staffIdx = 0; staffIdx < nstaves(); ++staffIdx)
makeGap1(dtick, staffIdx, r.duration(), voiceOffsets);
r.write(this, dtick);

for (auto i : spanner()) {
Spanner* s = i.second;
if (s->track() >= strack && s->track() < etrack) {
if (s->tick() >= stick && s->tick() < etick)
s->undoChangeProperty(P_ID::SPANNER_TICK, s->tick() + ticks);
else if (s->tick2() >= stick && s->tick2() < etick)
s->undoChangeProperty(P_ID::SPANNER_TICKS, s->ticks() + ticks);
}
}

if (track != -1) {
Measure* m = tick2measure(dtick);
Segment* s = m->findSegment(Segment::Type::ChordRest, dtick);
Expand Down
Loading

0 comments on commit 1f243b5

Please sign in to comment.