Skip to content

Commit

Permalink
fix #25646
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed May 8, 2014
1 parent 4721517 commit 02d0fcc
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 114 deletions.
11 changes: 10 additions & 1 deletion libmscore/clef.cpp
Expand Up @@ -210,7 +210,7 @@ void Clef::layout()
}

// if nothing changed since last layout, do nothing
// if (curClefType == clefType() && curLines == lines && curLineDist == lineDist)
//DEBUG if (curClefType == clefType() && curLines == lines && curLineDist == lineDist)
// return;
// if something has changed, cache new values and re-layout
curClefType = clefType();
Expand Down Expand Up @@ -472,6 +472,15 @@ void Clef::setClefType(const QString& s)
setClefType(ct);
}

//---------------------------------------------------------
// clefTypeName
//---------------------------------------------------------

const char* Clef::clefTypeName()
{
return ClefInfo::tag(clefType());
}

//---------------------------------------------------------
// clefType
//---------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions libmscore/clef.h
Expand Up @@ -15,7 +15,7 @@

/**
\file
Definition of classes Clef and ClefList.
Definition of classes Clef
*/

#include "element.h"
Expand Down Expand Up @@ -66,8 +66,8 @@ enum class ClefType : signed char {
//---------------------------------------------------------

struct ClefTypeList {
ClefType _concertClef;
ClefType _transposingClef;
ClefType _concertClef = ClefType::G;
ClefType _transposingClef = ClefType::G;

ClefTypeList() {}
ClefTypeList(ClefType a, ClefType b) : _concertClef(a), _transposingClef(b) {}
Expand Down Expand Up @@ -149,7 +149,7 @@ class Clef : public Element {
virtual void draw(QPainter*) const;
virtual void read(XmlReader&);
virtual void write(Xml&) const;

virtual bool isEditable() const { return false; }

virtual void addElement(Element* e, qreal x, qreal y);
Expand All @@ -165,6 +165,7 @@ class Clef : public Element {
void undoSetShowCourtesy(bool v);

static ClefType clefType(const QString& s);
const char* clefTypeName();

ClefType clefType() const;
void setClefType(ClefType i);
Expand Down
25 changes: 16 additions & 9 deletions libmscore/cleflist.cpp
Expand Up @@ -41,10 +41,12 @@ bool ClefTypeList::operator!=(const ClefTypeList& t) const

ClefTypeList ClefList::clef(int tick) const
{
if (empty())
return ClefTypeList();
auto i = upper_bound(tick);
if (i != begin())
--i;
return i->second;
if (i == begin())
return ClefTypeList();
return (--i)->second;
}

//---------------------------------------------------------
Expand All @@ -53,11 +55,17 @@ ClefTypeList ClefList::clef(int tick) const

void ClefList::setClef(int tick, ClefTypeList ctl)
{
auto i = find(tick);
if (i == end())
insert(std::pair<int, ClefTypeList>(tick, ctl));
else
i->second = ctl;
if (clef(tick) == ctl)
return;
if (clef(tick-1) == ctl)
erase(tick);
else {
auto i = find(tick);
if (i == end())
insert(std::pair<int, ClefTypeList>(tick, ctl));
else
i->second = ctl;
}
}

//---------------------------------------------------------
Expand All @@ -79,6 +87,5 @@ void ClefList::read(XmlReader& e, Score* cs)
e.unknown();
}
}

}

15 changes: 11 additions & 4 deletions libmscore/edit.cpp
Expand Up @@ -1297,16 +1297,23 @@ void Score::deleteItem(Element* el)
case Element::CLEF:
{
Clef* clef = static_cast<Clef*>(el);
int tick = clef->segment()->tick();
Measure* m = clef->measure();
if (m->isMMRest()) {
// propagate to original measure
m = m->mmRestLast();
Segment* s = m->findSegment(Segment::SegClef, clef->segment()->tick());
if (s && s->element(clef->track()))
undoRemoveElement(s->element(clef->track()));
if (s && s->element(clef->track())) {
Clef* c = static_cast<Clef*>(s->element(clef->track()));
undoRemoveElement(c);
undo(new SetClefType(c->staff(), tick, c->staff()->clefTypeList(tick-1)));
}
}
else
undoRemoveElement(el);
else {
undoRemoveElement(clef);
undo(new SetClefType(clef->staff(), tick, clef->staff()->clefTypeList(tick-1)));
}
cmdUpdateNotes();
}
break;

Expand Down
1 change: 1 addition & 0 deletions libmscore/excerpt.cpp
Expand Up @@ -374,6 +374,7 @@ void cloneStaves(Score* oscore, Score* score, const QList<int>& map)
for (int dstStaffIdx = 0; dstStaffIdx < n; ++dstStaffIdx) {
Staff* srcStaff = oscore->staff(map[dstStaffIdx]);
Staff* dstStaff = score->staff(dstStaffIdx);
*dstStaff->clefList() = *srcStaff->clefList();
if (srcStaff->primaryStaff()) {
int span = srcStaff->barLineSpan();
int sIdx = srcStaff->idx();
Expand Down
2 changes: 1 addition & 1 deletion libmscore/keysig.cpp
Expand Up @@ -122,7 +122,7 @@ void KeySig::layout()
// determine current clef for this staff
ClefType clef = ClefType::G;
if (staff())
clef = staff()->clef(segment());
clef = staff()->clef(segment()->tick());

int t1 = _sig.accidentalType();
int t2 = _sig.naturalType();
Expand Down
1 change: 1 addition & 0 deletions libmscore/measure.cpp
Expand Up @@ -2042,6 +2042,7 @@ void Measure::read(XmlReader& e, int staffIdx)
clef->setTrack(e.track());
clef->read(e);
clef->setGenerated(false);
staff->setClef(e.tick(), clef->clefTypeList());

// there may be more than one clef segment for same tick position
if (!segment) {
Expand Down
1 change: 0 additions & 1 deletion libmscore/part.h
Expand Up @@ -23,7 +23,6 @@ class Xml;
class Staff;
class Score;
class InstrumentTemplate;
class ClefList;

//---------------------------------------------------------
// @@ Part
Expand Down
2 changes: 1 addition & 1 deletion libmscore/read114.cpp
Expand Up @@ -455,7 +455,7 @@ Score::FileError Score::read114(XmlReader& e)
s->setBarLineSpan(n - idx);
}
// first clef can be implicit in 1.3 #22607
if(s->clefList()->count(0) == 0) {
if (s->clefList()->count(0) == 0) {
Segment* seg = firstMeasure()->getSegment(Segment::SegClef, 0);
ClefType ct = Clef::clefType("0");
Clef* clef = new Clef(this);
Expand Down
23 changes: 2 additions & 21 deletions libmscore/score.cpp
Expand Up @@ -3498,27 +3498,8 @@ void Score::undoInsertTime(int tick, int len)
void Score::insertTime(int tick, int len)
{
for (Score* score : scoreList()) {
for(Staff* staff : score->staves()) {
KeyList* kl = staff->keymap();
KeyList kl2;
for (auto i = kl->upper_bound(tick); i != kl->end();) {
KeySigEvent kse = i->second;
int key = i->first;
kl->erase(i++);
kl2[key + len] = kse;
}
kl->insert(kl2.begin(), kl2.end());

ClefList* cl = staff->clefList();
ClefList cl2;
for (auto i = cl->upper_bound(tick); i != cl->end();) {
ClefTypeList ctl = i->second;
int key = i->first;
cl->erase(i++);
cl2[key + len] = ctl;
}
cl->insert(cl2.begin(), cl2.end());
}
for (Staff* staff : score->staves())
staff->insertTime(tick, len);
}
}

Expand Down
11 changes: 2 additions & 9 deletions libmscore/segment.cpp
Expand Up @@ -181,9 +181,7 @@ Segment::~Segment()
foreach(Element* e, _elist) {
if (!e)
continue;
if (e->type() == CLEF)
e->staff()->removeClef(static_cast<Clef*>(e));
else if (e->type() == TIMESIG)
if (e->type() == TIMESIG)
e->staff()->removeTimeSig(static_cast<TimeSig*>(e));
delete e;
}
Expand Down Expand Up @@ -462,7 +460,6 @@ void Segment::add(Element* el)
score()->sigmap()->pos(tick()), tick(), track, score());
}
_elist[track] = el;
el->staff()->addClef(static_cast<Clef*>(el));
empty = false;
break;

Expand Down Expand Up @@ -583,16 +580,12 @@ void Segment::remove(Element* el)
removeAnnotation(el);
break;

case CLEF:
_elist[track] = 0;
el->staff()->removeClef(static_cast<Clef*>(el));
break;

case TIMESIG:
_elist[track] = 0;
el->staff()->removeTimeSig(static_cast<TimeSig*>(el));
break;

case CLEF:
case KEYSIG:
case BAR_LINE:
case BREATH:
Expand Down
86 changes: 39 additions & 47 deletions libmscore/staff.cpp
Expand Up @@ -172,7 +172,6 @@ Staff::Staff(Score* s)
_updateKeymap = true;
_linkedStaves = 0;
_color = MScore::defaultColor;
setClef(0, ClefType::G);
}

Staff::Staff(Score* s, Part* p, int rs)
Expand All @@ -190,7 +189,6 @@ Staff::Staff(Score* s, Part* p, int rs)
_updateKeymap = true;
_linkedStaves = 0;
_color = MScore::defaultColor;
setClef(0, ClefType::G);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -221,36 +219,10 @@ ClefTypeList Staff::clefTypeList(int tick) const

ClefType Staff::clef(int tick) const
{
ClefTypeList c = clefs.clef(tick);
ClefTypeList c = clefTypeList(tick);
return score()->styleB(ST_concertPitch) ? c._concertClef : c._transposingClef;
}

ClefType Staff::clef(Segment* segment) const
{
return clef(segment->tick());
}

//---------------------------------------------------------
// timeStretch
//---------------------------------------------------------

Fraction Staff::timeStretch(int tick) const
{
TimeSig* timesig = timeSig(tick);
return timesig == 0 ? Fraction(1,1) : timesig->stretch();
}

//---------------------------------------------------------
// addClef
//---------------------------------------------------------

void Staff::addClef(Clef* clef)
{
int tick = clef->segment()->tick();
if (tick == 0 || !clef->generated())
clefs.setClef(tick, clef->clefTypeList());
}

//---------------------------------------------------------
// setClef
//---------------------------------------------------------
Expand All @@ -260,29 +232,23 @@ void Staff::setClef(int tick, const ClefTypeList& ctl)
clefs.setClef(tick, ctl);
}

void Staff::setClef(int tick, ClefType ct)
//---------------------------------------------------------
// undoSetClef
//---------------------------------------------------------

void Staff::undoSetClef(int tick, const ClefTypeList& ctl)
{
setClef(tick, ClefTypeList(ct, ct));
score()->undo(new SetClefType(this, tick, ctl));
}

//---------------------------------------------------------
// removeClef
// timeStretch
//---------------------------------------------------------

void Staff::removeClef(Clef* clef)
Fraction Staff::timeStretch(int tick) const
{
if (clef->generated())
return;
int tick = clef->segment()->tick();
if (tick == 0) {
setClef(0, ClefType::G);
return;
}
auto i = clefs.find(tick);
if (i != clefs.end())
clefs.erase(i);
else
qDebug("Staff::removeClef: Clef at %d not found", tick);
TimeSig* timesig = timeSig(tick);
return timesig == 0 ? Fraction(1,1) : timesig->stretch();
}

//---------------------------------------------------------
Expand Down Expand Up @@ -431,8 +397,9 @@ void Staff::read(XmlReader& e)
qDebug("Staff::read staffTypeIdx %d", staffTypeIdx);
_staffType = *StaffType::preset(staffTypeIdx);
}
else if (tag == "StaffType")
else if (tag == "StaffType") {
_staffType.read(e);
}
else if (tag == "small")
setSmall(e.readInt());
else if (tag == "invisible")
Expand Down Expand Up @@ -810,7 +777,7 @@ bool Staff::genKeySig()
bool Staff::showLedgerLines()
{
if (_staffType.group() == TAB_STAFF_GROUP)
return false;
return false;
else
return _staffType.showLedgerLines();
}
Expand All @@ -834,5 +801,30 @@ void Staff::undoSetColor(const QColor& /*val*/)
// score()->undoChangeProperty(this, P_COLOR, val);
}

//---------------------------------------------------------
// insertTime
//---------------------------------------------------------

void Staff::insertTime(int tick, int len)
{
KeyList kl2;
for (auto i = _keymap.upper_bound(tick); i != _keymap.end();) {
KeySigEvent kse = i->second;
int key = i->first;
_keymap.erase(i++);
kl2[key + len] = kse;
}
_keymap.insert(kl2.begin(), kl2.end());

ClefList cl2;
for (auto i = clefs.upper_bound(tick); i != clefs.end();) {
ClefTypeList ctl = i->second;
int key = i->first;
clefs.erase(i++);
cl2.setClef(key + len, ctl);
}
clefs.insert(cl2.begin(), cl2.end());
}

}

0 comments on commit 02d0fcc

Please sign in to comment.