fix handling of grace notes in parts

This commit is contained in:
Werner Schweer 2012-09-10 16:10:25 +02:00
parent 3340d3db35
commit 0c2bd69623
6 changed files with 56 additions and 106 deletions

View file

@ -670,14 +670,21 @@ bool Element::readProperties(const QDomElement& e)
else if (tag == "userOff")
_userOff = readPoint(e);
else if (tag == "lid") {
_links = score()->links().value(val.toInt());
int id = val.toInt();
_links = score()->links().value(id);
if (!_links) {
int i = val.toInt();
if (score()->parentScore()) // DEBUG
qDebug("---link %d not found (%d)\n", i, score()->links().size());
_links = new LinkedElements(score(), i);
score()->links().insert(i, _links);
qDebug("---link %d not found (%d)\n", id, score()->links().size());
_links = new LinkedElements(score(), id);
score()->links().insert(id, _links);
}
#ifndef NDEBUG
else {
foreach(Element* e, _links) {
Q_ASSERT(e->type() == type());
}
}
#endif
_links->append(this);
}
else if (tag == "tick") {

View file

@ -421,15 +421,13 @@ void cloneStaves(Score* oscore, Score* score, const QList<int>& map)
//---------------------------------------------------------
// cloneStaff
// srcStaff and dstStaff are in the same score
//---------------------------------------------------------
void cloneStaff(Staff* srcStaff, Staff* dstStaff)
{
printf("clone staff=== %p %p\n", srcStaff, dstStaff);
Score* score = srcStaff->score();
// dstStaff->linkTo(srcStaff);
// int tracks = score->nstaves() * VOICES;
SlurMap slurMap;
TieMap tieMap;
@ -458,10 +456,8 @@ printf("clone staff=== %p %p\n", srcStaff, dstStaff);
ChordRest* ncr = static_cast<ChordRest*>(ne);
Tuplet* ot = ocr->tuplet();
if (ot) {
printf("tuplet\n");
Tuplet* nt = tupletMap.findNew(ot);
if (nt == 0) {
printf(" create tuplet\n");
nt = new Tuplet(*ot);
nt->clear();
nt->setTrack(dstTrack);

View file

@ -744,13 +744,10 @@ Segment* Measure::getSegment(Element* e, int tick)
//---------------------------------------------------------
// getSegment
/// Get a segment of type \a st at tick position \a t.
/// If the segment does not exist, it is created.
//---------------------------------------------------------
/**
Get a segment of type \a st at tick position \a t.
If the segment does not exist, it is created.
*/
Segment* Measure::getSegment(Segment::SegmentType st, int t)
{
Segment* s = findSegment(st, t);
@ -779,6 +776,7 @@ Segment* Measure::getSegment(Segment::SegmentType st, int t)
Segment* Measure::getSegment(Segment::SegmentType st, int t, int gl)
{
// qDebug("Measure::getSegment(st=%d, t=%d, gl=%d)", st, t, gl);
if (st != Segment::SegChordRest && st != Segment::SegGrace) {
qDebug("Measure::getSegment(st=%d, t=%d, gl=%d): incorrect segment type", st, t, gl);
return 0;
@ -788,10 +786,15 @@ Segment* Measure::getSegment(Segment::SegmentType st, int t, int gl)
// find the first segment at tick >= t
for (s = first(); s && s->tick() < t; s = s->next())
;
if (s == 0) {
s = new Segment(this, Segment::SegChordRest, t);
// qDebug(" create cr segment %p", s);
add(s);
}
// find the first SegChordRest segment at tick = t
// while counting the SegGrace segments
int nGraces = 0;
int nGraces = 0;
Segment* sCr = 0;
for (Segment* ss = s; ss && ss->tick() == t; ss = ss->next()) {
if (ss->subtype() == Segment::SegGrace)
@ -801,68 +804,25 @@ Segment* Measure::getSegment(Segment::SegmentType st, int t, int gl)
break;
}
}
// qDebug(" nGraces %d sCr %p s %p %s", nGraces, sCr, s, s->subTypeName());
// qDebug("s=%p sCr=%p nGr=%d", s, sCr, nGraces);
// qDebug("segment list");
// for (Segment* s = first(); s; s = s->next())
// qDebug(" %d: %d", s->tick(), s->subtype());
if (gl == 0) {
if (sCr)
return sCr;
// no SegChordRest at tick = t, must create it
// qDebug("creating SegChordRest at tick=%d", t);
s = new Segment(this, Segment::SegChordRest, t);
add(s);
return s;
for (; nGraces < gl; ++nGraces) {
Segment* ps = new Segment(this, Segment::SegGrace, t);
// qDebug(" create grace segment %p", ps);
_segments.insert(ps, s);
s = ps;
setDirty();
}
if (gl > 0) {
if (gl <= nGraces) {
// qDebug("grace segment %d already exist, returning it", gl);
int graces = 0;
// for (Segment* ss = last(); ss && ss->tick() <= t; ss = ss->prev()) {
for (Segment* ss = last(); ss && ss->tick() >= t; ss = ss->prev()) {
if (ss->tick() > t)
continue;
if ((ss->subtype() == Segment::SegGrace) && (ss->tick() == t))
graces++;
if (gl == graces)
return ss;
}
return 0; // should not be reached
}
else {
// qDebug("creating SegGrace at tick=%d and level=%d", t, gl);
Segment* prevs = 0; // last segment inserted
// insert the first grace segment
if (nGraces == 0) {
++nGraces;
s = new Segment(this, Segment::SegGrace, t);
// qDebug("... creating SegGrace %p at tick=%d and level=%d", s, t, nGraces);
add(s);
prevs = s;
// return s;
}
// find the first grace segment at t
for (Segment* ss = last(); ss && ss->tick() <= t; ss = ss->prev()) {
if (ss->subtype() == Segment::SegGrace && ss->tick() == t)
prevs = ss;
}
// add the missing grace segments before the one already present
while (nGraces < gl) {
++nGraces;
s = new Segment(this, Segment::SegGrace, t);
// qDebug("... creating SegGrace %p at tick=%d and level=%d", s, t, nGraces);
_segments.insert(s, prevs);
prevs = s;
}
setDirty();
return s;
int graces = 0;
for (Segment* ss = sCr; ss && ss->tick() == t; ss = ss->prev()) {
if ((ss->subtype() == Segment::SegGrace) && (ss->tick() == t))
graces++;
if (gl == graces) {
qDebug(" return %p", ss);
return ss;
}
}
return 0; // should not be reached
}
@ -2463,7 +2423,6 @@ bool Measure::setStartRepeatBarLine(bool val)
bl->setSubtype(START_REPEAT);
if (s == 0) {
if (score()->undoRedo()) {
printf("Measure %d) setStartRepeatBarLine %d\n", no()+1, val);
return false;
}
s = undoGetSegment(Segment::SegStartRepeatBarLine, tick());

View file

@ -3227,8 +3227,9 @@ int Score::linkId()
void Score::linkId(int val)
{
if (val > rootScore()->_linkId)
rootScore()->_linkId = val;
Score* s = rootScore();
if (val > s->_linkId)
s->_linkId = val;
}
//---------------------------------------------------------

View file

@ -343,35 +343,23 @@ void Score::undoChangeElement(Element* oldElement, Element* newElement)
void Score::undoChangePitch(Note* note, int pitch, int tpc, int line/*, int fret, int string*/)
{
QList<Staff*> staffList;
Staff* ostaff = note->staff();
LinkedStaves* linkedStaves = ostaff->linkedStaves();
if (linkedStaves)
staffList = linkedStaves->staves();
else
staffList.append(ostaff);
Chord* chord = note->chord();
Chord* chord = note->chord();
int noteIndex = chord->notes().indexOf(note);
Segment* segment = chord->segment();
Measure* measure = segment->measure();
foreach(Staff* staff, staffList) {
Score* score = staff->score();
Measure* m;
Segment* s;
if (score == this) {
m = measure;
s = segment;
Q_ASSERT(noteIndex >= 0);
LinkedElements* l = chord->links();
if (l) {
foreach(Element* e, *l) {
Chord* c = static_cast<Chord*>(e);
Q_ASSERT(c->type() == CHORD);
Q_ASSERT(c->notes().size() > noteIndex);
Note* n = c->notes().at(noteIndex);
undo(new ChangePitch(n, pitch, tpc, line));
}
else {
m = score->tick2measure(measure->tick());
s = m->findSegment(segment->subtype(), segment->tick());
}
int staffIdx = score->staffIdx(staff);
Chord* c = static_cast<Chord*>(s->element(staffIdx * VOICES + chord->voice()));
Note* n = c->notes().at(noteIndex);
undo(new ChangePitch(n, pitch, tpc, line/*, fret, string*/));
}
else
undo(new ChangePitch(note, pitch, tpc, line));
}
//---------------------------------------------------------

View file

@ -509,7 +509,7 @@ void Debugger::updateElement(Element* el)
for (int i = 0;; ++i) {
QTreeWidgetItem* item = list->topLevelItem(i);
if (item == 0) {
qDebug("Debugger::Element not found %s %p\n", el->name(), el);
qDebug("Debugger::Element not found %s %p", el->name(), el);
break;
}
ElementItem* ei = (ElementItem*)item;
@ -1631,7 +1631,6 @@ void ShowElementBase::setElement(Element* e)
eb.address->setText(QString("%1").arg((unsigned long)e, 0, 16));
eb.score->setText(QString("%1").arg((unsigned long)(e->score()), 0, 16));
// eb.subtype->setValue(e->subtype());
eb.selected->setChecked(e->selected());
eb.selectable->setChecked(e->selectable());
eb.droptarget->setChecked(e->dropTarget());
@ -1713,9 +1712,9 @@ void ShowElementBase::parentClicked()
void ShowElementBase::linkClicked()
{
qDebug("linkClicked\n");
qDebug("linkClicked");
foreach(Element* e, *el->links()) {
qDebug(" element <%p> <%p>\n", e->score(), e);
qDebug(" element <%p> <%p>", e->score(), e);
if (e != el) {
emit elementChanged(e);
break;