autoplace dynamics

This commit is contained in:
werner 2016-06-14 16:00:16 +02:00
parent 1a8cdf1da4
commit ae8644f822
7 changed files with 36 additions and 84 deletions

View file

@ -37,49 +37,6 @@ struct Dyn {
const char* text; // utf8 text of dynamic
};
#if 0
// variant with ligatures, using bravura-text
static Dyn dynList[] = {
// dynamic:
{ -1, true, "other-dynamics", "" },
{ 1, false, "pppppp", "\ue520\ue520\ue520\ue520\ue520\ue520" },
{ 5, false, "ppppp", "\ue520\ue520\ue520\ue520\ue520" },
{ 10, false, "pppp", "\ue520\ue520\ue520\ue520" },
{ 16, false, "ppp", "\ue520\ue520\ue520" },
{ 33, false, "pp", "\ue520\ue520" },
{ 49, false, "p", "\ue520" },
{ 64, false, "mp", "\ue521\ue520" },
{ 80, false, "mf", "\ue521\ue522" },
{ 96, false, "f", "\ue522" },
{ 112, false, "ff", "\ue522\ue522" },
{ 126, false, "fff", "\ue522\ue522\ue522" },
{ 127, false, "ffff", "\ue522\ue522\ue522\ue522" },
{ 127, false, "fffff", "\ue522\ue522\ue522\ue522\ue522" },
{ 127, false, "ffffff", "\ue522\ue522\ue522\ue522\ue522\ue522" },
// accents:
{ 0, true, "fp", "\ue522\ue520" },
{ 0, true, "sf", "\ue524\ue522" },
{ 0, true, "sfz", "\ue524\ue522\ue525" },
{ 0, true, "sff", "\ue524\ue522\ue522" },
{ 0, true, "sffz", "\ue524\ue522\ue522\ue525" },
{ 0, true, "sfp", "\ue524\ue522\ue520" },
{ 0, true, "sfpp", "\ue524\ue522\ue520\ue520" },
{ 0, true, "rfz", "\ue523\ue522\ue525" },
{ 0, true, "rf", "\ue523\ue522" },
{ 0, true, "fz", "\ue522\ue525" },
{ 0, true, "m", "\ue521" },
{ 0, true, "r", "\ue523" },
{ 0, true, "s", "\ue524" },
{ 0, true, "z", "\ue525" },
{ 0, true, "n", "\ue526" },
};
#endif
#if 1
// variant with ligatures, works for both emmentaler and bravura:
static Dyn dynList[] = {
@ -117,7 +74,6 @@ static Dyn dynList[] = {
{ 0, true, "z", "<sym>dynamicZ</sym>"},
{ 0, true, "n", "<sym>dynamicNiente</sym>" }
};
#endif
#if 0
// variant with precomposed symbols, available only in bravura:
@ -241,37 +197,38 @@ void Dynamic::read(XmlReader& e)
void Dynamic::layout()
{
if (!readPos().isNull()) {
if (score()->mscVersion() <= 114) {
setReadPos(QPointF());
// hack: 1.2 boundingBoxes are a bit wider which results
// in symbols moved right
setUserXoffset(userOff().x() - spatium() * .6);
}
}
if (autoplace())
setUserOff(QPointF());
setPos(textStyle().offset(spatium()));
Text::layout1();
Segment* s = segment();
if (!s)
return;
for (int voice = 0; voice < VOICES; ++voice) {
int t = (track() & ~0x3) + voice;
Chord* c = static_cast<Chord*>(s->element(t));
if (!c)
continue;
if (c->type() == Element::Type::CHORD) {
qreal noteHeadWidth = score()->noteHeadWidth() * c->mag();
if (c->stem() && !c->up()) // stem down
rxpos() += noteHeadWidth * .25; // center on stem + optical correction
if (s) {
int t = track() & ~0x3;
for (int voice = 0; voice < VOICES; ++voice) {
Element* e = s->element(t + voice);
if (e && e->isChord()) {
Chord* c = toChord(e);
qreal noteHeadWidth = score()->noteHeadWidth() * c->mag();
if (c->stem() && !c->up()) // stem down
rxpos() += noteHeadWidth * .25; // center on stem + optical correction
else
rxpos() += noteHeadWidth * .5; // center on notehead
}
else
rxpos() += noteHeadWidth * .5; // center on notehead
rxpos() += e->width() * .5;
break;
}
if (autoplace()) {
qreal minDistance = spatium();
Shape s1 = s->staffShape(staffIdx()).translated(s->pos());
Shape s2 = shape().translated(s->pos());
qreal d = s1.minVerticalDistance(s2);
if (d > -minDistance)
setUserOff(QPointF(0.0, d + minDistance));
}
else
rxpos() += c->width() * .5;
break;
}
adjustReadPos();
}
//---------------------------------------------------------

View file

@ -2872,7 +2872,7 @@ void Score::getNextMeasure(LayoutContext& lc)
}
else if (isMaster() && segment.isChordRestType()) {
for (Element* e : segment.annotations()) {
if (!(e->isTempoText() || e->isRehearsalMark() || e->isStaffText()))
if (!(e->isTempoText() || e->isDynamic() || e->isRehearsalMark() || e->isStaffText()))
e->layout();
}
qreal stretch = 0.0;
@ -3300,9 +3300,8 @@ System* Score::collectSystem(LayoutContext& lc)
if (e->visible())
s->staffShape(tt->staffIdx()).add(tt->shape());
}
else if (e->visible() && (e->isRehearsalMark() || e->isStaffText())) {
else if (e->visible() && (e->isRehearsalMark() || e->isDynamic() || e->isStaffText())) {
e->layout();
// s->staffShape(e->staffIdx()).add(e->shape().translated(s->pos()));
s->staffShape(e->staffIdx()).add(e->shape());
}
}

View file

@ -1338,6 +1338,7 @@ void Segment::createShape(int staffIdx)
&& e->visible()
&& !e->isRehearsalMark()
&& !e->isTempoText()
&& !e->isDynamic()
&& !e->isStaffText())
s.add(e->shape());
}

View file

@ -59,7 +59,7 @@ void Shape::draw(QPainter* p) const
qreal Shape::minHorizontalDistance(const Shape& a) const
{
qreal dist = 0.0;
qreal dist = -1000000.0; // min real
for (const QRectF& r2 : a) {
qreal by1 = r2.top();
qreal by2 = r2.bottom();
@ -82,7 +82,7 @@ qreal Shape::minHorizontalDistance(const Shape& a) const
qreal Shape::minVerticalDistance(const Shape& a) const
{
qreal dist = 0.0;
qreal dist = -1000000.0; // min real
for (const QRectF& r2 : a) {
qreal bx1 = r2.left();
qreal bx2 = r2.right();

View file

@ -889,22 +889,17 @@ void InspectorTempoText::postInit()
//---------------------------------------------------------
InspectorDynamic::InspectorDynamic(QWidget* parent)
: InspectorBase(parent)
: InspectorElementBase(parent)
{
e.setupUi(addWidget());
t.setupUi(addWidget());
d.setupUi(addWidget());
iList = {
{ P_ID::COLOR, 0, 0, e.color, e.resetColor },
{ P_ID::VISIBLE, 0, 0, e.visible, e.resetVisible },
{ P_ID::USER_OFF, 0, 0, e.offsetX, e.resetX },
{ P_ID::USER_OFF, 1, 0, e.offsetY, e.resetY },
std::vector<InspectorItem> il = {
{ P_ID::TEXT_STYLE_TYPE, 0, 0, t.style, t.resetStyle },
{ P_ID::DYNAMIC_RANGE, 0, 0, d.dynRange, d.resetDynRange },
{ P_ID::VELOCITY, 0, 0, d.velocity, d.resetVelocity }
};
mapSignals();
mapSignals(il);
connect(t.resetToStyle, SIGNAL(clicked()), SLOT(resetToStyle()));
}
@ -926,7 +921,7 @@ void InspectorDynamic::setElement()
t.style->addItem(qApp->translate("TextStyle",ts.at(i).name().toUtf8().data()), i);
}
t.style->blockSignals(false);
InspectorBase::setElement();
InspectorElementBase::setElement();
}
//---------------------------------------------------------

View file

@ -321,7 +321,7 @@ class InspectorTempoText : public InspectorBase {
// InspectorDynamic
//---------------------------------------------------------
class InspectorDynamic : public InspectorBase {
class InspectorDynamic : public InspectorElementBase {
Q_OBJECT
UiInspectorElement e;

View file

@ -169,7 +169,7 @@ void InspectorNote::setElement()
hook->setEnabled(note->chord()->hook());
beam->setEnabled(note->chord()->beam());
tuplet->setEnabled(note->chord()->tuplet());
InspectorBase::setElement();
InspectorElementBase::setElement();
bool nograce = !note->chord()->isGrace();
s.leadingSpace->setEnabled(nograce);
s.resetLeadingSpace->setEnabled(nograce && s.leadingSpace->value());