Skip to content

Commit

Permalink
[palette] added layout for TremoloBar
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 10, 2023
1 parent c1f1f99 commit 74aea44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
30 changes: 3 additions & 27 deletions src/engraving/layout/pal/tlayout.cpp
Expand Up @@ -2568,34 +2568,10 @@ void TLayout::layout(Tremolo* item, LayoutContext& ctx)
v0::TremoloLayout::layout(item, ctxv0);
}

void TLayout::layout(TremoloBar* item, LayoutContext&)
void TLayout::layout(TremoloBar*, LayoutContext&)
{
double _spatium = item->spatium();
if (item->explicitParent()) {
item->setPos(0.0, -_spatium * 3.0);
} else {
item->setPos(PointF());
}

/* we place the tremolo bars starting slightly before the
* notehead, and end it slightly after, drawing above the
* note. The values specified in Guitar Pro are very large, too
* large for the scale used in Musescore. We used the
* timeFactor and pitchFactor below to reduce these values down
* consistently to values that make sense to draw with the
* Musescore scale. */

double timeFactor = item->userMag() / 1.0;
double pitchFactor = -_spatium * .02;

PolygonF polygon;
for (const PitchValue& v : item->points()) {
polygon << PointF(v.time * timeFactor, v.pitch * pitchFactor);
}
item->setPolygon(polygon);

double w = item->lineWidth().val();
item->setbbox(item->polygon().boundingRect().adjusted(-w, -w, w, w));
//! NOTE Moved to PaletteLayout
UNREACHABLE;
}

void TLayout::layout(Trill*, LayoutContext&)
Expand Down
22 changes: 22 additions & 0 deletions src/palette/internal/palettelayout.cpp
Expand Up @@ -75,6 +75,7 @@
#include "engraving/libmscore/textline.h"
#include "engraving/libmscore/textlinebase.h"
#include "engraving/libmscore/timesig.h"
#include "engraving/libmscore/tremolobar.h"
#include "engraving/libmscore/trill.h"
#include "engraving/libmscore/vibrato.h"
#include "engraving/libmscore/volta.h"
Expand Down Expand Up @@ -173,6 +174,8 @@ void PaletteLayout::layoutItem(EngravingItem* item)
break;
case ElementType::TIMESIG: layout(toTimeSig(item), ctx);
break;
case ElementType::TREMOLOBAR: layout(toTremoloBar(item), ctx);
break;
case ElementType::TRILL: layout(toTrill(item), ctx);
break;
case ElementType::VIBRATO: layout(toVibrato(item), ctx);
Expand Down Expand Up @@ -1313,6 +1316,25 @@ void PaletteLayout::layout(TimeSig* item, const Context& ctx)
item->setDrawArgs(drawArgs);
}

void PaletteLayout::layout(TremoloBar* item, const Context&)
{
double spatium = item->spatium();

item->setPos(PointF());

double timeFactor = item->userMag() / 1.0;
double pitchFactor = -spatium * 0.02;

PolygonF polygon;
for (const PitchValue& v : item->points()) {
polygon << PointF(v.time * timeFactor, v.pitch * pitchFactor);
}
item->setPolygon(polygon);

double w = item->lineWidth().val();
item->setbbox(item->polygon().boundingRect().adjusted(-w, -w, w, w));
}

void PaletteLayout::layout(Trill* item, const Context& ctx)
{
layoutLine(static_cast<SLine*>(item), ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/palette/internal/palettelayout.h
Expand Up @@ -101,6 +101,7 @@ class TextLine;
class TextLineSegment;
class TextLineBaseSegment;
class TimeSig;
class TremoloBar;
class Trill;
class TrillSegment;

Expand Down Expand Up @@ -192,6 +193,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::TremoloBar* item, const Context& ctx);
static void layout(engraving::Trill* item, const Context& ctx);

static void layout(engraving::Vibrato* item, const Context& ctx);
Expand Down

0 comments on commit 74aea44

Please sign in to comment.