Skip to content

Commit

Permalink
fix TremoloBar
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Sep 20, 2016
1 parent fe3b30f commit 9c56e22
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 62 deletions.
3 changes: 3 additions & 0 deletions libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Text;
class Hairpin;
class HairpinSegment;
class Bend;
class TremoloBar;
class RepeatMeasure;
class Tuplet;
class NoteDot;
Expand Down Expand Up @@ -719,6 +720,7 @@ class Element : public QObject, public ScoreElement {
CONVERT(Hairpin, HAIRPIN)
CONVERT(HairpinSegment,HAIRPIN_SEGMENT)
CONVERT(Bend, BEND)
CONVERT(TremoloBar, TREMOLOBAR)
CONVERT(RepeatMeasure, REPEAT_MEASURE)
CONVERT(Tuplet, TUPLET)
CONVERT(NoteDot, NOTEDOT)
Expand Down Expand Up @@ -817,6 +819,7 @@ static inline const a* to##a(const Element* e) { Q_ASSERT(e == 0 || e->type() ==
CONVERT(Hairpin, HAIRPIN)
CONVERT(HairpinSegment,HAIRPIN_SEGMENT)
CONVERT(Bend, BEND)
CONVERT(TremoloBar, TREMOLOBAR)
CONVERT(RepeatMeasure, REPEAT_MEASURE)
CONVERT(Tuplet, TUPLET)
CONVERT(NoteDot, NOTEDOT)
Expand Down
70 changes: 20 additions & 50 deletions libmscore/tremolobar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ void TremoloBar::layout()
qreal _spatium = spatium();

setPos(0.0, 0.0);
if (staff() && !staff()->isTabStaff()) {
setbbox(QRectF());
if (!parent()) {
noteWidth = -_spatium*2;
notePos = QPointF(0.0, _spatium*3);
}
}

_lw = _spatium * 0.1;

Note* note = 0;
if (note == 0) {
noteWidth = 0.0;
Expand All @@ -57,21 +50,24 @@ void TremoloBar::layout()
noteWidth = note->width();
notePos = note->pos();
}
// int n = _points.size();
// int pt = 0;
// qreal x = noteWidth * .5;
// qreal y = notePos.y() - _spatium;
// qreal x2, y2;

QRectF bb (0, 0, _spatium, -_spatium * 5);
#if 0
for (int pt = 0; pt < n; ++pt) {
if (pt == (n-1))
break;
x = x2;
y = y2;
}
#endif

polygon.clear();

/* 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. */

qreal timeFactor = 1.0 / _userMag;
qreal pitchFactor = 2.5 / _userMag;

for (auto v : _points)
polygon << QPointF(v.time / timeFactor, -v.pitch / pitchFactor - _spatium * 3);

QRectF bb(polygon.boundingRect());
bb.adjust(-_lw, -_lw, _lw, _lw);
setbbox(bb);
}
Expand All @@ -84,33 +80,7 @@ void TremoloBar::draw(QPainter* painter) const
{
QPen pen(curColor(), _lw, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
painter->setPen(pen);
painter->setBrush(QBrush(Qt::black));

qreal _spatium = spatium();
const TextStyle* st = &score()->textStyle(TextStyleType::BENCH);
QFont f = st->font(_spatium);
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);

painter->setFont(f);
int n = _points.size();

int previousTime = _points[0].time;
int previousPitch = _points[0].pitch;
/* 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. */
qreal timeFactor = 10.0 / _userMag;
qreal pitchFactor = 25.0 / _userMag;
for (int pt = 1; pt < n; ++pt) {
painter->drawLine(QLineF(previousTime/timeFactor, -previousPitch/pitchFactor-_spatium*3,
_points[pt].time/timeFactor, -_points[pt].pitch/pitchFactor-_spatium*3));
previousTime = _points[pt].time;
previousPitch = _points[pt].pitch;
}
painter->drawPolyline(polygon.translated(pos()));
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/tremolobar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TremoloBar : public Element {
QPointF notePos;
qreal noteWidth;
qreal _userMag { 1.0 }; // allowed 0.1 - 10.0
QPolygonF polygon; // computed by layout

public:
TremoloBar(Score* s);
Expand Down
15 changes: 5 additions & 10 deletions mscore/inspector/inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,21 +729,16 @@ void InspectorBend::propertiesClicked()
//---------------------------------------------------------

InspectorTremoloBar::InspectorTremoloBar(QWidget* parent)
: InspectorBase(parent)
: InspectorElementBase(parent)
{
e.setupUi(addWidget());
g.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 },
const std::vector<InspectorItem> iiList = {
// { P_ID::PLAY, 0, 0, g.playBend, g.resetPlayBend }
{ P_ID::MAG, 0, 0, g.mag, g.resetMag }
};

mapSignals();
mapSignals(iiList);
connect(g.properties, SIGNAL(clicked()), SLOT(propertiesClicked()));
}

Expand All @@ -753,10 +748,10 @@ InspectorTremoloBar::InspectorTremoloBar(QWidget* parent)

void InspectorTremoloBar::propertiesClicked()
{
Bend* b = toBend(inspector->element());
TremoloBar* b = toTremoloBar(inspector->element());
Score* score = b->score();
score->startCmd();
mscore->currentScoreView()->editBendProperties(b);
mscore->currentScoreView()->editTremoloBarProperties(b);
score->setLayoutAll();
score->endCmd();
}
Expand Down
3 changes: 1 addition & 2 deletions mscore/inspector/inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ class InspectorBend : public InspectorElementBase {
// InspectorTremoloBar
//---------------------------------------------------------

class InspectorTremoloBar : public InspectorBase {
class InspectorTremoloBar : public InspectorElementBase {
Q_OBJECT

UiInspectorElement e;
Ui::InspectorTremoloBar g;

private slots:
Expand Down

0 comments on commit 9c56e22

Please sign in to comment.