fix stems for drum staves
This commit is contained in:
parent
0326f57b19
commit
0cefb023a3
4 changed files with 252 additions and 176 deletions
|
@ -1372,7 +1372,169 @@ void Chord::layout()
|
|||
{
|
||||
if (_notes.empty())
|
||||
return;
|
||||
if (staff() && staff()->isTabStaff())
|
||||
layoutTablature();
|
||||
else
|
||||
layoutPitch();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// layoutPitch
|
||||
//---------------------------------------------------------
|
||||
|
||||
void Chord::layoutPitch()
|
||||
{
|
||||
qreal _spatium = spatium();
|
||||
|
||||
while (_ledgerLines) {
|
||||
LedgerLine* l = _ledgerLines->next();
|
||||
delete _ledgerLines;
|
||||
_ledgerLines = l;
|
||||
}
|
||||
|
||||
qreal lll = 0.0; // space to leave at left of chord
|
||||
qreal rrr = 0.0; // space to leave at right of chord
|
||||
Note* upnote = upNote();
|
||||
qreal headWidth = symbols[score()->symIdx()][quartheadSym].width(magS());
|
||||
|
||||
delete _tabDur; // no TAB? no duration symbol! (may happen when converting a TAB into PITCHED)
|
||||
_tabDur = 0;
|
||||
|
||||
if (!segment()) {
|
||||
//
|
||||
// hack for use in palette
|
||||
//
|
||||
int n = _notes.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Note* note = _notes.at(i);
|
||||
note->layout();
|
||||
qreal x = 0.0;
|
||||
qreal y = note->line() * _spatium * .5;
|
||||
note->setPos(x, y);
|
||||
}
|
||||
computeUp();
|
||||
layoutStem();
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// process notes
|
||||
// - position
|
||||
//-----------------------------------------
|
||||
|
||||
int lx = 0.0;
|
||||
adjustReadPos();
|
||||
qreal noteWidth = _notes.size() ? downNote()->headWidth() :
|
||||
symbols[score()->symIdx()][quartheadSym].width(magS());
|
||||
qreal stemX = _up ? noteWidth : 0.0;
|
||||
|
||||
for (int i = 0; i < _notes.size(); ++i) {
|
||||
Note* note = _notes.at(i);
|
||||
note->layout();
|
||||
qreal x = note->rxpos();
|
||||
|
||||
Accidental* accidental = note->accidental();
|
||||
if (accidental) {
|
||||
qreal minNoteDistance = score()->styleS(ST_minNoteDistance).val() * _spatium;
|
||||
x = accidental->x() + note->x() - minNoteDistance;
|
||||
}
|
||||
if (x < lx)
|
||||
lx = x;
|
||||
}
|
||||
lll = -lx;
|
||||
if (stem())
|
||||
stem()->rypos() = (_up ? downNote() : upNote())->rypos();
|
||||
|
||||
addLedgerLines(stemX, staffMove());
|
||||
|
||||
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next())
|
||||
ll->layout();
|
||||
|
||||
if (_arpeggio) {
|
||||
qreal headHeight = upnote->headHeight();
|
||||
_arpeggio->layout();
|
||||
lll += _arpeggio->width() + _spatium * .5;
|
||||
qreal y = upNote()->pos().y() - headHeight * .5;
|
||||
qreal h = downNote()->pos().y() + downNote()->headHeight() - y;
|
||||
_arpeggio->setHeight(h);
|
||||
_arpeggio->setPos(-lll, y);
|
||||
|
||||
// handle the special case of _arpeggio->span() > 1
|
||||
// in layoutArpeggio2() after page layout has done so we
|
||||
// know the y position of the next staves
|
||||
}
|
||||
|
||||
if (_glissando)
|
||||
lll += _spatium * .5;
|
||||
|
||||
int n = _notes.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
Note* note = _notes.at(i);
|
||||
qreal lhw = note->headWidth();
|
||||
qreal rr = 0.0; // assume note is at left of stem (0 space at right)
|
||||
if (note->mirror()) {
|
||||
if (up())
|
||||
rr = lhw * 2.0;
|
||||
else {
|
||||
if (lhw > lll)
|
||||
lll = lhw;
|
||||
}
|
||||
}
|
||||
else
|
||||
rr = lhw;
|
||||
if (rr > rrr)
|
||||
rrr = rr;
|
||||
qreal xx = note->pos().x() + headWidth + pos().x();
|
||||
if (xx > dotPosX())
|
||||
setDotPosX(xx);
|
||||
}
|
||||
|
||||
if (dots()) {
|
||||
qreal x = dotPosX() + point(score()->styleS(ST_dotNoteDistance)
|
||||
+ (dots()-1) * score()->styleS(ST_dotDotDistance));
|
||||
x += symbols[score()->symIdx()][dotSym].width(1.0);
|
||||
if (x > rrr)
|
||||
rrr = x;
|
||||
}
|
||||
|
||||
if (_hook) {
|
||||
if (beam())
|
||||
score()->undoRemoveElement(_hook);
|
||||
else {
|
||||
_hook->layout();
|
||||
if (up()) {
|
||||
// hook position is not set yet
|
||||
qreal x = _hook->bbox().right() + stem()->hookPos().x();
|
||||
rrr = qMax(rrr, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_space.setLw(lll);
|
||||
_space.setRw(rrr + ipos().x());
|
||||
|
||||
for (Element* e : _el) {
|
||||
e->layout();
|
||||
if (e->type() == CHORDLINE) {
|
||||
int x = bbox().translated(e->pos()).right();
|
||||
if (x > _space.rw())
|
||||
_space.setRw(x);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _notes.size(); ++i)
|
||||
_notes.at(i)->layout2();
|
||||
QRectF bb;
|
||||
processSiblings([&bb] (Element* e) { bb |= e->bbox().translated(e->pos()); } );
|
||||
setbbox(bb);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// layoutTablature
|
||||
//---------------------------------------------------------
|
||||
|
||||
void Chord::layoutTablature()
|
||||
{
|
||||
qreal _spatium = spatium();
|
||||
|
||||
while (_ledgerLines) {
|
||||
|
@ -1387,7 +1549,6 @@ void Chord::layout()
|
|||
qreal headWidth = symbols[score()->symIdx()][quartheadSym].width(magS());
|
||||
StaffTypeTablature* tab = 0;
|
||||
|
||||
if (staff() && staff()->isTabStaff()) {
|
||||
//
|
||||
// TABLATURE STAVES
|
||||
//
|
||||
|
@ -1405,7 +1566,7 @@ void Chord::layout()
|
|||
// centre fret string on stem
|
||||
qreal x = stemX - fretWidth*0.5;
|
||||
note->setPos(x, _spatium * tab->physStringToVisual(note->string()) * lineDist);
|
||||
// note->layout2(); // needed? it is repeated later right before computing bbox
|
||||
// note->layout2(); // needed? it is repeated later right before computing bbox
|
||||
}
|
||||
// horiz. spacing: leave half width at each side of the (potential) stem
|
||||
qreal halfHeadWidth = headWidth * 0.5;
|
||||
|
@ -1482,71 +1643,6 @@ void Chord::layout()
|
|||
}
|
||||
} // end of if(duration_symbols)
|
||||
adjustReadPos();
|
||||
} // end of if(isTabStaff)
|
||||
else {
|
||||
//
|
||||
// NON-TABLATURE STAVES
|
||||
//
|
||||
delete _tabDur; // no TAB? no duration symbol! (may happen when converting a TAB into PITCHED)
|
||||
_tabDur = 0;
|
||||
|
||||
if (!segment()) {
|
||||
//
|
||||
// hack for use in palette
|
||||
//
|
||||
int n = _notes.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
Note* note = _notes.at(i);
|
||||
note->layout();
|
||||
qreal x = 0.0;
|
||||
qreal y = note->line() * _spatium * .5;
|
||||
note->setPos(x, y);
|
||||
}
|
||||
computeUp();
|
||||
layoutStem();
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// process notes
|
||||
// - position
|
||||
//-----------------------------------------
|
||||
|
||||
int lx = 0.0;
|
||||
|
||||
adjustReadPos();
|
||||
|
||||
qreal noteWidth = _notes.size() ? downNote()->headWidth() :
|
||||
symbols[score()->symIdx()][quartheadSym].width(magS());
|
||||
qreal stemX = _up ? noteWidth : 0.0;
|
||||
|
||||
int n = _notes.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
Note* note = _notes.at(i);
|
||||
note->layout();
|
||||
qreal x = note->rxpos();
|
||||
|
||||
Accidental* accidental = note->accidental();
|
||||
if (accidental) {
|
||||
qreal minNoteDistance = score()->styleS(ST_minNoteDistance).val() * _spatium;
|
||||
x = accidental->x() + note->x() - minNoteDistance;
|
||||
}
|
||||
if (x < lx)
|
||||
lx = x;
|
||||
}
|
||||
lll = -lx;
|
||||
if (stem())
|
||||
stem()->rypos() = (_up ? downNote() : upNote())->rypos();
|
||||
|
||||
addLedgerLines(stemX, staffMove());
|
||||
|
||||
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next())
|
||||
ll->layout();
|
||||
}
|
||||
|
||||
//
|
||||
// COMMON TO ALL STAVES
|
||||
//
|
||||
|
||||
if (_arpeggio) {
|
||||
qreal headHeight = upnote->headHeight();
|
||||
|
@ -1565,29 +1661,6 @@ void Chord::layout()
|
|||
if (_glissando)
|
||||
lll += _spatium * .5;
|
||||
|
||||
if (!tab) {
|
||||
int n = _notes.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
Note* note = _notes.at(i);
|
||||
qreal lhw = note->headWidth();
|
||||
qreal rr = 0.0; // assume note is at left of stem (0 space at right)
|
||||
if (note->mirror()) {
|
||||
if (up())
|
||||
rr = lhw * 2.0;
|
||||
else {
|
||||
if (lhw > lll)
|
||||
lll = lhw;
|
||||
}
|
||||
}
|
||||
else
|
||||
rr = lhw;
|
||||
if (rr > rrr)
|
||||
rrr = rr;
|
||||
qreal xx = note->pos().x() + headWidth + pos().x();
|
||||
if (xx > dotPosX())
|
||||
setDotPosX(xx);
|
||||
}
|
||||
}
|
||||
if (dots()) {
|
||||
qreal x = dotPosX() + point(score()->styleS(ST_dotNoteDistance)
|
||||
+ (dots()-1) * score()->styleS(ST_dotDotDistance));
|
||||
|
@ -1624,10 +1697,9 @@ void Chord::layout()
|
|||
|
||||
for (int i = 0; i < _notes.size(); ++i)
|
||||
_notes.at(i)->layout2();
|
||||
|
||||
QRectF bb;
|
||||
processSiblings([&bb] (Element* e) { bb |= e->bbox().translated(e->pos()); } );
|
||||
if (staff() && staff()->isTabStaff() && _tabDur)
|
||||
if (_tabDur)
|
||||
bb |= _tabDur->bbox().translated(_tabDur->pos());
|
||||
setbbox(bb);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,8 @@ class Chord : public ChordRest {
|
|||
void addLedgerLine(qreal x, int staffIdx, int line, int extend, bool visible, qreal hw);
|
||||
void addLedgerLines(qreal x, int move);
|
||||
void processSiblings(std::function<void(Element*)> func);
|
||||
void layoutPitch();
|
||||
void layoutTablature();
|
||||
|
||||
public:
|
||||
Chord(Score* s = 0);
|
||||
|
|
|
@ -100,7 +100,8 @@ void Score::layoutChords1(Segment* segment, int staffIdx)
|
|||
{
|
||||
Staff* staff = Score::staff(staffIdx);
|
||||
|
||||
if (staff->isDrumStaff() || staff->isTabStaff())
|
||||
// if (staff->isDrumStaff() || staff->isTabStaff())
|
||||
if (staff->isTabStaff())
|
||||
return;
|
||||
|
||||
int startTrack = staffIdx * VOICES;
|
||||
|
|
|
@ -113,6 +113,7 @@ void DrumTools::updateDrumset()
|
|||
Chord* chord = new Chord(gscore);
|
||||
chord->setDurationType(TDuration::V_QUARTER);
|
||||
chord->setStemDirection(dir);
|
||||
chord->setUp(up);
|
||||
chord->setTrack(voice);
|
||||
Note* note = new Note(gscore);
|
||||
note->setParent(chord);
|
||||
|
|
Loading…
Reference in a new issue