Skip to content

Commit

Permalink
[palette] added layout for Trill
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 10, 2023
1 parent e0481e2 commit b1112ba
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 69 deletions.
75 changes: 8 additions & 67 deletions src/engraving/layout/pal/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3058,80 +3058,21 @@ void TLayout::layout(TremoloBar* item, LayoutContext&)
item->setbbox(item->polygon().boundingRect().adjusted(-w, -w, w, w));
}

void TLayout::layout(TrillSegment* item, LayoutContext& ctx)
void TLayout::layout(Trill*, LayoutContext&)
{
if (item->staff()) {
item->setMag(item->staff()->staffMag(item->tick()));
}
if (item->spanner()->placeBelow()) {
item->setPosY(item->staff() ? item->staff()->height() : 0.0);
}

bool accidentalGoesBelow = item->trill()->trillType() == TrillType::DOWNPRALL_LINE;
Trill* trill = item->trill();
Ornament* ornament = trill->ornament();
if (ornament) {
if (item->isSingleBeginType()) {
TLayout::layout(ornament, ctx);
}
trill->setAccidental(accidentalGoesBelow ? ornament->accidentalBelow() : ornament->accidentalAbove());
trill->setCueNoteChord(ornament->cueNoteChord());
ArticulationAnchor anchor = ornament->anchor();
if (anchor == ArticulationAnchor::AUTO) {
trill->setPlacement(trill->track() % 2 ? PlacementV::BELOW : PlacementV::ABOVE);
} else {
trill->setPlacement(anchor == ArticulationAnchor::TOP ? PlacementV::ABOVE : PlacementV::BELOW);
}
trill->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::STYLED); // Ensures that the property isn't written (it is written by the ornamnent)
}

if (item->isSingleType() || item->isBeginType()) {
switch (item->trill()->trillType()) {
case TrillType::TRILL_LINE:
item->symbolLine(SymId::ornamentTrill, SymId::wiggleTrill);
break;
case TrillType::PRALLPRALL_LINE:
item->symbolLine(SymId::wiggleTrill, SymId::wiggleTrill);
break;
case TrillType::UPPRALL_LINE:
item->symbolLine(SymId::ornamentBottomLeftConcaveStroke,
SymId::ornamentZigZagLineNoRightEnd, SymId::ornamentZigZagLineWithRightEnd);
break;
case TrillType::DOWNPRALL_LINE:
item->symbolLine(SymId::ornamentLeftVerticalStroke,
SymId::ornamentZigZagLineNoRightEnd, SymId::ornamentZigZagLineWithRightEnd);
break;
}
Accidental* a = item->trill()->accidental();
if (a) {
double vertMargin = 0.35 * item->spatium();
RectF box = item->symBbox(item->symbols().front());
double x = 0;
double y = 0;
x = 0.5 * (box.width() - a->width());
double minVertDist = accidentalGoesBelow ? Shape(box).minVerticalDistance(a->shape())
: a->shape().minVerticalDistance(Shape(box));
y = accidentalGoesBelow ? minVertDist + vertMargin : -minVertDist - vertMargin;
a->setPos(x, y);
a->setParent(item);
}
} else {
item->symbolLine(SymId::wiggleTrill, SymId::wiggleTrill);
}

if (item->isStyled(Pid::OFFSET)) {
item->roffset() = item->trill()->propertyDefault(Pid::OFFSET).value<PointF>();
}
//! NOTE Moved to PaletteLayout
UNREACHABLE;
}

void TLayout::layout(TripletFeel* item, LayoutContext& ctx)
void TLayout::layout(TrillSegment*, LayoutContext&)
{
layout(static_cast<SystemText*>(item), ctx);
//! NOTE Moved to PaletteLayout
UNREACHABLE;
}

void TLayout::layout(Trill* item, LayoutContext& ctx)
void TLayout::layout(TripletFeel* item, LayoutContext& ctx)
{
layoutLine(static_cast<SLine*>(item), ctx);
layout(static_cast<SystemText*>(item), ctx);
}

void TLayout::layout(Tuplet*, LayoutContext&)
Expand Down
103 changes: 101 additions & 2 deletions src/palette/internal/palettelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "engraving/libmscore/letring.h"
#include "engraving/libmscore/line.h"
#include "engraving/libmscore/marker.h"
#include "engraving/libmscore/ornament.h"
#include "engraving/libmscore/ottava.h"
#include "engraving/libmscore/palmmute.h"
#include "engraving/libmscore/pedal.h"
Expand All @@ -65,6 +66,7 @@
#include "engraving/libmscore/textline.h"
#include "engraving/libmscore/textlinebase.h"
#include "engraving/libmscore/timesig.h"
#include "engraving/libmscore/trill.h"
#include "engraving/libmscore/vibrato.h"
#include "engraving/libmscore/volta.h"

Expand Down Expand Up @@ -148,13 +150,15 @@ void PaletteLayout::layoutItem(EngravingItem* item)
break;
case ElementType::TIMESIG: layout(toTimeSig(item), ctx);
break;
case ElementType::TRILL: layout(toTrill(item), ctx);
break;
case ElementType::VIBRATO: layout(toVibrato(item), ctx);
break;
case ElementType::VOLTA: layout(toVolta(item), ctx);
break;
default:
//! TODO Still need
// LOGD() << item->typeName();
LOGD() << item->typeName();
layout::pal::TLayout::layoutItem(item, ctxpal);
break;
}
Expand All @@ -177,6 +181,8 @@ void PaletteLayout::layoutLineSegment(LineSegment* item, const Context& ctx)
break;
case ElementType::TEXTLINE_SEGMENT: layout(toTextLineSegment(item), ctx);
break;
case ElementType::TRILL_SEGMENT: layout(toTrillSegment(item), ctx);
break;
case ElementType::VIBRATO_SEGMENT: layout(toVibratoSegment(item), ctx);
break;
case ElementType::VOLTA_SEGMENT: layout(toVoltaSegment(item), ctx);
Expand Down Expand Up @@ -852,6 +858,32 @@ void PaletteLayout::layout(Marker* item, const Context& ctx)
layoutTextBase(item, ctx);
}

void PaletteLayout::layout(Ornament* item, const Context& ctx)
{
double spatium = item->spatium();
double vertMargin = 0.35 * spatium;
constexpr double ornamentAccidentalMag = 0.6; // TODO: style?

if (!item->showCueNote()) {
for (size_t i = 0; i < item->accidentalsAboveAndBelow().size(); ++i) {
bool above = (i == 0);
Accidental* accidental = item->accidentalsAboveAndBelow()[i];
if (!accidental) {
continue;
}
accidental->computeMag();
accidental->setMag(accidental->mag() * ornamentAccidentalMag);
layout(accidental, ctx);
Shape accidentalShape = accidental->shape();
double minVertDist = above
? accidentalShape.minVerticalDistance(item->bbox())
: Shape(item->bbox()).minVerticalDistance(accidentalShape);
accidental->setPos(-0.5 * accidental->width(), above ? (-minVertDist - vertMargin) : (minVertDist + vertMargin));
}
return;
}
}

void PaletteLayout::layout(Ottava* item, const Context& ctx)
{
layoutLine(item, ctx);
Expand Down Expand Up @@ -1035,6 +1067,73 @@ void PaletteLayout::layout(TimeSig* item, const Context& ctx)
item->setDrawArgs(drawArgs);
}

void PaletteLayout::layout(Trill* item, const Context& ctx)
{
layoutLine(static_cast<SLine*>(item), ctx);
}

void PaletteLayout::layout(TrillSegment* item, const Context& ctx)
{
if (item->spanner()->placeBelow()) {
item->setPosY(0.0);
}

bool accidentalGoesBelow = item->trill()->trillType() == TrillType::DOWNPRALL_LINE;
Trill* trill = item->trill();
Ornament* ornament = trill->ornament();
if (ornament) {
if (item->isSingleBeginType()) {
layout(ornament, ctx);
}
trill->setAccidental(accidentalGoesBelow ? ornament->accidentalBelow() : ornament->accidentalAbove());
trill->setCueNoteChord(ornament->cueNoteChord());
ArticulationAnchor anchor = ornament->anchor();
if (anchor == ArticulationAnchor::AUTO) {
trill->setPlacement(trill->track() % 2 ? PlacementV::BELOW : PlacementV::ABOVE);
} else {
trill->setPlacement(anchor == ArticulationAnchor::TOP ? PlacementV::ABOVE : PlacementV::BELOW);
}
trill->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::STYLED); // Ensures that the property isn't written (it is written by the ornamnent)
}

if (item->isSingleType() || item->isBeginType()) {
switch (item->trill()->trillType()) {
case TrillType::TRILL_LINE:
item->symbolLine(SymId::ornamentTrill, SymId::wiggleTrill);
break;
case TrillType::PRALLPRALL_LINE:
item->symbolLine(SymId::wiggleTrill, SymId::wiggleTrill);
break;
case TrillType::UPPRALL_LINE:
item->symbolLine(SymId::ornamentBottomLeftConcaveStroke,
SymId::ornamentZigZagLineNoRightEnd, SymId::ornamentZigZagLineWithRightEnd);
break;
case TrillType::DOWNPRALL_LINE:
item->symbolLine(SymId::ornamentLeftVerticalStroke,
SymId::ornamentZigZagLineNoRightEnd, SymId::ornamentZigZagLineWithRightEnd);
break;
}
Accidental* a = item->trill()->accidental();
if (a) {
double vertMargin = 0.35 * item->spatium();
RectF box = item->symBbox(item->symbols().front());
double x = 0;
double y = 0;
x = 0.5 * (box.width() - a->width());
double minVertDist = accidentalGoesBelow
? Shape(box).minVerticalDistance(a->shape())
: a->shape().minVerticalDistance(Shape(box));
y = accidentalGoesBelow ? minVertDist + vertMargin : -minVertDist - vertMargin;
a->setPos(x, y);
a->setParent(item);
}
} else {
item->symbolLine(SymId::wiggleTrill, SymId::wiggleTrill);
}

item->setOffset(PointF());
}

void PaletteLayout::layout(Vibrato* item, const Context& ctx)
{
layoutLine(static_cast<SLine*>(item), ctx);
Expand All @@ -1043,7 +1142,7 @@ void PaletteLayout::layout(Vibrato* item, const Context& ctx)
void PaletteLayout::layout(VibratoSegment* item, const Context&)
{
if (item->spanner()->placeBelow()) {
item->setPosY(item->staff() ? item->staff()->height() : 0.0);
item->setPosY(0.0);
}

switch (item->vibrato()->vibratoType()) {
Expand Down
6 changes: 6 additions & 0 deletions src/palette/internal/palettelayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class LineSegment;

class Marker;

class Ornament;
class Ottava;
class OttavaSegment;

Expand All @@ -91,6 +92,8 @@ class TextLine;
class TextLineSegment;
class TextLineBaseSegment;
class TimeSig;
class Trill;
class TrillSegment;

class Vibrato;
class VibratoSegment;
Expand Down Expand Up @@ -151,6 +154,7 @@ class PaletteLayout

static void layout(engraving::Marker* item, const Context& ctx);

static void layout(engraving::Ornament* item, const Context& ctx);
static void layout(engraving::Ottava* item, const Context& ctx);

static void layout(engraving::PalmMute* item, const Context& ctx);
Expand All @@ -166,6 +170,7 @@ class PaletteLayout
static void layout(engraving::TempoText* item, const Context& ctx);
static void layout(engraving::TextLine* item, const Context& ctx);
static void layout(engraving::TimeSig* item, const Context& ctx);
static void layout(engraving::Trill* item, const Context& ctx);

static void layout(engraving::Vibrato* item, const Context& ctx);
static void layout(engraving::Volta* item, const Context& ctx);
Expand All @@ -178,6 +183,7 @@ class PaletteLayout
static void layout(engraving::PalmMuteSegment* item, const Context& ctx);
static void layout(engraving::PedalSegment* item, const Context& ctx);
static void layout(engraving::TextLineSegment* item, const Context& ctx);
static void layout(engraving::TrillSegment* item, const Context& ctx);
static void layout(engraving::VibratoSegment* item, const Context& ctx);
static void layout(engraving::VoltaSegment* item, const Context& ctx);

Expand Down

0 comments on commit b1112ba

Please sign in to comment.