2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
2018-03-21 15:34:32 +01:00
|
|
|
// Copyright (C) 2010-2018 Werner Schweer
|
2012-05-26 14:26:10 +02:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "fingering.h"
|
|
|
|
#include "score.h"
|
2015-02-18 19:06:29 +01:00
|
|
|
#include "staff.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
#include "undo.h"
|
2014-04-09 16:09:21 +02:00
|
|
|
#include "xml.h"
|
2017-01-19 16:06:40 +01:00
|
|
|
#include "chord.h"
|
|
|
|
#include "part.h"
|
|
|
|
#include "measure.h"
|
|
|
|
#include "stem.h"
|
2018-12-29 16:13:18 +01:00
|
|
|
#include "skyline.h"
|
|
|
|
#include "system.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2018-09-25 13:18:45 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// fingeringStyle
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-08-01 11:46:07 +02:00
|
|
|
static const ElementStyle fingeringStyle {
|
2019-02-18 19:52:26 +01:00
|
|
|
{ Sid::fingeringPlacement, Pid::PLACEMENT },
|
2018-08-01 11:46:07 +02:00
|
|
|
};
|
2018-03-21 14:05:33 +01:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Fingering
|
2018-03-21 15:34:32 +01:00
|
|
|
// Element(Score* = 0, ElementFlags = ElementFlag::NOTHING);
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-08-01 11:46:07 +02:00
|
|
|
Fingering::Fingering(Score* s, Tid tid, ElementFlags ef)
|
|
|
|
: TextBase(s, tid, ef)
|
2018-03-21 14:05:33 +01:00
|
|
|
{
|
2018-10-18 11:53:01 +02:00
|
|
|
setPlacement(Placement::ABOVE);
|
2018-08-01 11:46:07 +02:00
|
|
|
initElementStyle(&fingeringStyle);
|
2018-03-21 14:05:33 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 12:41:03 +02:00
|
|
|
Fingering::Fingering(Score* s, ElementFlags ef)
|
2018-08-01 11:46:07 +02:00
|
|
|
: Fingering(s, Tid::FINGERING, ef)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-29 16:13:18 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layoutType
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ElementType Fingering::layoutType()
|
|
|
|
{
|
|
|
|
switch (tid()) {
|
|
|
|
case Tid::FINGERING:
|
|
|
|
case Tid::RH_GUITAR_FINGERING:
|
|
|
|
case Tid::STRING_NUMBER:
|
|
|
|
return ElementType::CHORD;
|
|
|
|
default:
|
|
|
|
return ElementType::NOTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// calculatePlacement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2019-02-18 19:52:26 +01:00
|
|
|
Placement Fingering::calculatePlacement() const
|
2018-12-29 16:13:18 +01:00
|
|
|
{
|
|
|
|
Note* n = note();
|
|
|
|
if (!n)
|
2019-02-18 19:52:26 +01:00
|
|
|
return Placement::ABOVE;
|
2018-12-29 16:13:18 +01:00
|
|
|
Chord* chord = n->chord();
|
|
|
|
Staff* staff = chord->staff();
|
|
|
|
Part* part = staff->part();
|
|
|
|
int nstaves = part->nstaves();
|
|
|
|
bool voices = chord->measure()->hasVoices(staff->idx());
|
|
|
|
bool below = voices ? !chord->up() : (nstaves > 1) && (staff->rstaff() == nstaves - 1);
|
2019-02-18 19:52:26 +01:00
|
|
|
return below ? Placement::BELOW : Placement::ABOVE;
|
2018-12-29 16:13:18 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 19:06:29 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// layout
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Fingering::layout()
|
|
|
|
{
|
2018-12-03 08:45:01 +01:00
|
|
|
if (parent()) {
|
2019-01-30 15:13:54 +01:00
|
|
|
Fraction tick = parent()->tick();
|
2018-12-03 08:45:01 +01:00
|
|
|
const Staff* st = staff();
|
2019-01-30 15:13:54 +01:00
|
|
|
if (st && st->isTabStaff(tick) && !st->staffType(tick)->showTabFingering()) {
|
2018-12-03 08:45:01 +01:00
|
|
|
setbbox(QRectF());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-27 11:51:00 +01:00
|
|
|
TextBase::layout();
|
2018-12-29 16:13:18 +01:00
|
|
|
rypos() = 0.0; // handle placement below
|
2017-01-19 16:06:40 +01:00
|
|
|
|
2017-01-23 10:17:57 +01:00
|
|
|
if (autoplace() && note()) {
|
2018-12-29 16:13:18 +01:00
|
|
|
Note* n = note();
|
|
|
|
Chord* chord = n->chord();
|
|
|
|
bool voices = chord->measure()->hasVoices(chord->staffIdx());
|
|
|
|
bool tight = voices && chord->notes().size() == 1 && !chord->beam() && tid() != Tid::STRING_NUMBER;
|
|
|
|
|
|
|
|
qreal headWidth = n->bboxRightPos();
|
|
|
|
|
|
|
|
// temporarily exclude self from chord shape
|
|
|
|
setAutoplace(false);
|
|
|
|
|
|
|
|
if (layoutType() == ElementType::CHORD) {
|
|
|
|
Stem* stem = chord->stem();
|
|
|
|
Segment* s = chord->segment();
|
|
|
|
Measure* m = s->measure();
|
|
|
|
SysStaff* ss = m->system()->staff(chord->vStaffIdx());
|
|
|
|
Staff* vStaff = chord->staff(); // TODO: use current height at tick
|
|
|
|
if (n->mirror())
|
|
|
|
rxpos() -= n->ipos().x();
|
|
|
|
rxpos() += headWidth * .5;
|
|
|
|
if (placeAbove()) {
|
2017-01-19 16:06:40 +01:00
|
|
|
if (tight) {
|
|
|
|
if (chord->stem())
|
2018-12-29 16:13:18 +01:00
|
|
|
rxpos() -= 0.8 * spatium();
|
|
|
|
rypos() -= spatium() * 1.5;
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
2018-12-29 16:13:18 +01:00
|
|
|
else {
|
|
|
|
QRectF r = bbox().translated(m->pos() + s->pos() + chord->pos() + n->pos() + pos());
|
2019-05-02 07:09:50 +02:00
|
|
|
qreal yOff = offset().y() - propertyDefault(Pid::OFFSET).toPointF().y();
|
|
|
|
r.translate(0.0, -yOff);
|
2018-12-29 16:13:18 +01:00
|
|
|
SkylineLine sk(false);
|
|
|
|
sk.add(r.x(), r.bottom(), r.width());
|
|
|
|
qreal d = sk.minDistance(ss->skyline().north());
|
|
|
|
if (d > 0.0)
|
|
|
|
rypos() -= d + height() * .25;
|
|
|
|
// force extra space above staff & chord (but not other fingerings)
|
|
|
|
qreal top;
|
|
|
|
if (chord->up() && chord->beam() && stem) {
|
|
|
|
top = stem->y() + stem->bbox().top();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Note* un = chord->upNote();
|
|
|
|
top = qMin(0.0, un->y() + un->bbox().top());
|
|
|
|
}
|
2019-02-25 06:12:17 +01:00
|
|
|
qreal minDistance = score()->styleS(Sid::fingeringMinDistance).val() * spatium();
|
|
|
|
top -= minDistance;
|
2018-12-29 16:13:18 +01:00
|
|
|
qreal diff = (bbox().bottom() + ipos().y() + n->y()) - top;
|
|
|
|
if (diff > 0.0)
|
|
|
|
rypos() -= diff;
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tight) {
|
|
|
|
if (chord->stem())
|
2018-12-29 16:13:18 +01:00
|
|
|
rxpos() += 0.8 * spatium();
|
|
|
|
rypos() += spatium() * 1.5;
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
2018-12-29 16:13:18 +01:00
|
|
|
else {
|
|
|
|
QRectF r = bbox().translated(m->pos() + s->pos() + chord->pos() + n->pos() + pos());
|
2019-05-02 07:09:50 +02:00
|
|
|
qreal yOff = offset().y() - propertyDefault(Pid::OFFSET).toPointF().y();
|
|
|
|
r.translate(0.0, -yOff);
|
2018-12-29 16:13:18 +01:00
|
|
|
SkylineLine sk(true);
|
|
|
|
sk.add(r.x(), r.top(), r.width());
|
|
|
|
qreal d = ss->skyline().south().minDistance(sk);
|
|
|
|
if (d > 0.0)
|
|
|
|
rypos() += d + height() * .25;
|
|
|
|
// force extra space below staff & chord (but not other fingerings)
|
|
|
|
qreal bottom;
|
|
|
|
if (!chord->up() && chord->beam() && stem) {
|
|
|
|
bottom = stem->y() + stem->bbox().bottom();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Note* dn = chord->downNote();
|
|
|
|
bottom = qMax(vStaff->height(), dn->y() + dn->bbox().bottom());
|
|
|
|
}
|
2019-02-25 06:12:17 +01:00
|
|
|
qreal minDistance = score()->styleS(Sid::fingeringMinDistance).val() * spatium();
|
|
|
|
bottom += minDistance;
|
2018-12-29 16:13:18 +01:00
|
|
|
qreal diff = bottom - (bbox().top() + ipos().y() + n->y());
|
|
|
|
if (diff > 0.0)
|
|
|
|
rypos() += diff;
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 16:13:18 +01:00
|
|
|
else if (tid() == Tid::LH_GUITAR_FINGERING) {
|
|
|
|
// place to left of note
|
|
|
|
qreal left = n->shape().left();
|
|
|
|
if (left - n->x() > 0.0)
|
|
|
|
rxpos() -= left;
|
|
|
|
else
|
|
|
|
rxpos() -= n->x();
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
2018-12-29 16:13:18 +01:00
|
|
|
// for other fingering styles, do not autoplace
|
|
|
|
|
|
|
|
// restore autoplace
|
|
|
|
setAutoplace(true);
|
2017-01-19 16:06:40 +01:00
|
|
|
}
|
2015-02-18 19:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// draw
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Fingering::draw(QPainter* painter) const
|
|
|
|
{
|
2017-12-27 11:51:00 +01:00
|
|
|
TextBase::draw(painter);
|
2015-02-18 19:06:29 +01:00
|
|
|
}
|
|
|
|
|
2014-07-10 14:13:37 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// accessibleInfo
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-02-04 17:06:32 +01:00
|
|
|
QString Fingering::accessibleInfo() const
|
2014-07-10 14:13:37 +02:00
|
|
|
{
|
|
|
|
QString rez = Element::accessibleInfo();
|
2018-08-01 11:46:07 +02:00
|
|
|
if (tid() == Tid::STRING_NUMBER)
|
2017-02-17 15:09:28 +01:00
|
|
|
rez += " " + QObject::tr("String number");
|
2015-04-27 12:59:30 +02:00
|
|
|
return QString("%1: %2").arg(rez).arg(plainText());
|
2014-07-10 14:13:37 +02:00
|
|
|
}
|
|
|
|
|
2017-01-05 14:53:21 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// propertyDefault
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2018-03-27 15:36:00 +02:00
|
|
|
QVariant Fingering::propertyDefault(Pid id) const
|
2017-01-05 14:53:21 +01:00
|
|
|
{
|
|
|
|
switch (id) {
|
2018-10-18 11:53:01 +02:00
|
|
|
case Pid::PLACEMENT:
|
2019-02-18 19:52:26 +01:00
|
|
|
return int(calculatePlacement());
|
2018-03-27 15:36:00 +02:00
|
|
|
case Pid::SUB_STYLE:
|
2018-08-01 11:46:07 +02:00
|
|
|
return int(Tid::FINGERING);
|
2017-01-05 14:53:21 +01:00
|
|
|
default:
|
2017-12-27 11:51:00 +01:00
|
|
|
return TextBase::propertyDefault(id);
|
2017-01-05 14:53:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|