Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tie-fret-tab-show-not-show thing #20744

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,72 @@ void Note::updateFrettingForTiesAndBends()
setFret(prevNote->fret());
}

bool Note::shouldHideFret() const
{
if (!tieBack() || shouldForceShowFret()) {
return false;
}

if (isContinuationOfBend()) {
return true;
}

ShowTiedFret showTiedFret = style().value(Sid::tabShowTiedFret).value<ShowTiedFret>();
if (showTiedFret == ShowTiedFret::TIE_AND_FRET) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually to be very honest, I'm not sure if these methods are as clear as they could be. A few things that may be the cause of this are:

  • the fact that Sid::tabShowTiedFret is queried in a lot of places (both in forceShowFret itself, and by the callers of forceShowFret) makes the logic a bit less easy to grasp.
  • Patterns like the following seem to be not my favourite:
    if (it is A) 
        return …
    if (it is C) 
        return …
    
    // then it must be B
    return …
    
    A simple switch might be slightly nicer:
    case A: return …
    case B: return …
    case C: return …
    
  • It's not immediately clear which parameter takes precedence over the others, so to speak. This might become clearer by using switches. Maybe there is simply some interaction between the parameters instead of a strict precedence hierarchy, which is fine; but I think it would be possible to write it down slightly clearer.

Anyway, not sure if this is worth spending time on right now, but in the refinement stage you could keep this in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods look cumbersome because they implement cumbersome logic (which I deeply hate, but I also can't do much about). I honestly couldn't find a clearer way to do this. The logic isn't simple enough that a switch statement would make things better imo, and in these cases with intricate relations I do prefer the "early return" pattern (the alternative is a nesting chain of hell).

return false;
}

ParenthesizeTiedFret parenthTiedFret = style().value(Sid::tabParenthesizeTiedFret).value<ParenthesizeTiedFret>();
if (parenthTiedFret == ParenthesizeTiedFret::NEVER || !rtick().isZero()) {
return true;
}

if (parenthTiedFret == ParenthesizeTiedFret::START_OF_MEASURE) {
return false;
}

const Measure* measure = findMeasure();
bool isStartOfSystem = measure && measure->system() && measure->isFirstInSystem();

return !isStartOfSystem;
}

bool Note::shouldForceShowFret() const
{
if (!style().styleB(Sid::parenthesizeTiedFretIfArticulation)) {
return false;
}

Chord* ch = chord();
if (!ch) {
return false;
}

auto hasTremoloBar = [&] () {
for (EngravingItem* item : ch->segment()->annotations()) {
if (item && item->isTremoloBar() && item->track() == track()) {
return true;
}
}
return false;
};

auto hasVibratoLine = [&] () {
auto spanners = score()->spannerMap().findOverlapping(tick().ticks(), (tick() + ch->actualTicks()).ticks());
for (auto interval : spanners) {
Spanner* sp = interval.value;
if (sp->isVibrato() && sp->startElement() == ch) {
return true;
}
}
return false;
};

bool startsNonBendSpanner = !spannerFor().empty() && !bendFor();

return !ch->articulations().empty() || ch->chordLine() || startsNonBendSpanner || hasTremoloBar() || hasVibratoLine();
}

void Note::setupAfterRead(const Fraction& ctxTick, bool pasteMode)
{
// ensure sane values:
Expand Down Expand Up @@ -3614,6 +3680,25 @@ bool Note::isGraceBendStart() const
return bend && bend->type() == GuitarBendType::GRACE_NOTE_BEND;
}

bool Note::isContinuationOfBend() const
{
if (bendBack()) {
return true;
}

Tie* tie = tieBack();
Note* note = nullptr;
while (tie && tie->startNote()) {
note = tie->startNote();
if (note->bendBack()) {
return true;
}
tie = note->tieBack();
}

return false;
}

bool Note::hasAnotherStraightAboveOrBelow(bool above) const
{
if (!chord()) {
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/dom/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class Note final : public EngravingItem

bool isPreBendStart() const;
bool isGraceBendStart() const;
bool isContinuationOfBend() const;

bool hasAnotherStraightAboveOrBelow(bool above) const;

Expand All @@ -446,6 +447,8 @@ class Note final : public EngravingItem
bool isNoteName() const;

void updateFrettingForTiesAndBends();
bool shouldHideFret() const;
bool shouldForceShowFret() const;

struct LayoutData : public EngravingItem::LayoutData {
ld_field<bool> useTablature = { "[Note] useTablature", false };
Expand Down
12 changes: 12 additions & 0 deletions src/engraving/dom/stafftype.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ enum class StaffTypes : signed char {
TAB_DEFAULT = StaffTypes::TAB_6COMMON,
};

enum class ShowTiedFret {
TIE_AND_FRET,
TIE,
NONE,
};

enum class ParenthesizeTiedFret {
START_OF_SYSTEM,
START_OF_MEASURE,
NEVER,
};

//---------------------------------------------------------
// StaffType
//---------------------------------------------------------
Expand Down
13 changes: 5 additions & 8 deletions src/engraving/rendering/dev/chordlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,7 @@ void ChordLayout::updateLineAttachPoints(Chord* chord, bool isFirstInMeasure, La
for (Note* note : chord->notes()) {
Tie* tieBack = note->tieBack();
if (tieBack && tieBack->startNote()->findMeasure() != note->findMeasure()) {
SlurTieLayout::tieLayoutBack(tieBack, note->findMeasure()->system());
SlurTieLayout::tieLayoutBack(tieBack, note->findMeasure()->system(), ctx);
}
}
}
Expand Down Expand Up @@ -3453,13 +3453,10 @@ void ChordLayout::layoutNote2(Note* item, LayoutContext& ctx)
bool isTabStaff = staffType && staffType->isTabStaff();
// First, for tab staves that have show back-tied fret marks option, we add parentheses to the tied note if
// the tie spans a system boundary. This can't be done in layout as the system of each note is not decided yet
bool useParens = isTabStaff && !staffType->showBackTied() && !item->fixed();
if (useParens
&& item->tieBack()
&& (
item->chord()->measure()->system() != item->tieBack()->startNote()->chord()->measure()->system()
|| !item->el().empty()
)) {
ShowTiedFret showTiedFret = item->style().value(Sid::tabShowTiedFret).value<ShowTiedFret>();
bool useParens = isTabStaff && !item->fixed() && item->tieBack()
&& showTiedFret != ShowTiedFret::TIE_AND_FRET && !item->shouldHideFret();
if (useParens) {
if (!item->fretString().startsWith(u'(')) { // Hack: don't add parentheses if already added
item->setFretString(String(u"(%1)").arg(item->fretString()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/measurelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void MeasureLayout::layout2(Measure* item, LayoutContext& ctx)
SlurTieLayout::tieLayoutFor(tieFor, item->system());
}
if (tieBack && tieBack->tick() < stick && tieBack->isCrossStaff()) {
SlurTieLayout::tieLayoutBack(tieBack, item->system());
SlurTieLayout::tieLayoutBack(tieBack, item->system(), ctx);
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/engraving/rendering/dev/slurtielayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "dom/slur.h"
#include "dom/chord.h"
#include "dom/score.h"
#include "dom/system.h"
#include "dom/staff.h"
#include "dom/stafftype.h"
Expand Down Expand Up @@ -1436,7 +1437,13 @@ static bool tieSegmentShouldBeSkipped(Tie* item)
return false;
}

return !st->showBackTied() || (startNote && startNote->harmonic());
if (startNote->isContinuationOfBend()) {
return true;
}

ShowTiedFret showTiedFret = item->style().value(Sid::tabShowTiedFret).value<ShowTiedFret>();

return showTiedFret == ShowTiedFret::NONE;
}

TieSegment* SlurTieLayout::tieLayoutFor(Tie* item, System* system)
Expand Down Expand Up @@ -1511,8 +1518,12 @@ TieSegment* SlurTieLayout::tieLayoutFor(Tie* item, System* system)
return segment;
}

TieSegment* SlurTieLayout::tieLayoutBack(Tie* item, System* system)
TieSegment* SlurTieLayout::tieLayoutBack(Tie* item, System* system, LayoutContext& ctx)
{
if (item->staffType() && item->staffType()->isTabStaff()) {
// On TAB, the presence of this tie may require to add a parenthesis
ChordLayout::layout(item->endNote()->chord(), ctx);
}
// do not layout ties in tablature if not showing back-tied fret marks
if (tieSegmentShouldBeSkipped(item)) {
if (!item->segmentsEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/slurtielayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SlurTieLayout
static SpannerSegment* layoutSystem(Slur* item, System* system, LayoutContext& ctx);

static TieSegment* tieLayoutFor(Tie* item, System* system);
static TieSegment* tieLayoutBack(Tie* item, System* system);
static TieSegment* tieLayoutBack(Tie* item, System* system, LayoutContext& ctx);
static void resolveVerticalTieCollisions(const std::vector<TieSegment*>& stackedTies);

static void computeUp(Slur* slur, LayoutContext& ctx);
Expand Down
22 changes: 11 additions & 11 deletions src/engraving/rendering/dev/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,9 @@ void SystemLayout::layoutSystemElements(System* system, LayoutContext& ctx)

// ties
if (ctx.conf().isLinearMode()) {
doLayoutTiesLinear(system);
doLayoutTiesLinear(system, ctx);
} else {
doLayoutTies(system, sl, stick, etick);
doLayoutTies(system, sl, stick, etick, ctx);
}
// guitar bends
layoutGuitarBends(sl, ctx);
Expand Down Expand Up @@ -1331,7 +1331,7 @@ void SystemLayout::layoutSystemElements(System* system, LayoutContext& ctx)
}
}

void SystemLayout::doLayoutTies(System* system, std::vector<Segment*> sl, const Fraction& stick, const Fraction& etick)
void SystemLayout::doLayoutTies(System* system, std::vector<Segment*> sl, const Fraction& stick, const Fraction& etick, LayoutContext& ctx)
{
UNUSED(etick);

Expand All @@ -1342,14 +1342,14 @@ void SystemLayout::doLayoutTies(System* system, std::vector<Segment*> sl, const
}
Chord* c = toChord(e);
for (Chord* ch : c->graceNotes()) {
layoutTies(ch, system, stick);
layoutTies(ch, system, stick, ctx);
}
layoutTies(c, system, stick);
layoutTies(c, system, stick, ctx);
}
}
}

void SystemLayout::doLayoutTiesLinear(System* system)
void SystemLayout::doLayoutTiesLinear(System* system, LayoutContext& ctx)
{
constexpr Fraction start = Fraction(0, 1);
for (Measure* measure = system->firstMeasure(); measure; measure = measure->nextMeasure()) {
Expand All @@ -1363,9 +1363,9 @@ void SystemLayout::doLayoutTiesLinear(System* system)
}
Chord* c = toChord(e);
for (Chord* ch : c->graceNotes()) {
layoutTies(ch, system, start);
layoutTies(ch, system, start, ctx);
}
layoutTies(c, system, start);
layoutTies(c, system, start, ctx);
}
}
}
Expand Down Expand Up @@ -1559,7 +1559,7 @@ void SystemLayout::processLines(System* system, LayoutContext& ctx, std::vector<
}
}

void SystemLayout::layoutTies(Chord* ch, System* system, const Fraction& stick)
void SystemLayout::layoutTies(Chord* ch, System* system, const Fraction& stick, LayoutContext& ctx)
{
SysStaff* staff = system->staff(ch->staffIdx());
if (!staff->show()) {
Expand All @@ -1579,7 +1579,7 @@ void SystemLayout::layoutTies(Chord* ch, System* system, const Fraction& stick)
t = note->tieBack();
if (t) {
if (t->startNote()->tick() < stick) {
TieSegment* ts = SlurTieLayout::tieLayoutBack(t, system);
TieSegment* ts = SlurTieLayout::tieLayoutBack(t, system, ctx);
if (ts && ts->addToSkyline()) {
staff->skyline().add(ts->shape().translate(ts->pos()));
stackedBackwardTies.push_back(ts);
Expand Down Expand Up @@ -1674,7 +1674,7 @@ void SystemLayout::restoreTiesAndBends(System* system, LayoutContext& ctx)
}
Fraction stick = system->measures().front()->tick();
Fraction etick = system->measures().back()->endTick();
doLayoutTies(system, segList, stick, etick);
doLayoutTies(system, segList, stick, etick, ctx);
layoutGuitarBends(segList, ctx);
}

Expand Down
6 changes: 3 additions & 3 deletions src/engraving/rendering/dev/systemlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class SystemLayout
private:
static System* getNextSystem(LayoutContext& lc);
static void processLines(System* system, LayoutContext& ctx, std::vector<Spanner*> lines, bool align);
static void layoutTies(Chord* ch, System* system, const Fraction& stick);
static void doLayoutTies(System* system, std::vector<Segment*> sl, const Fraction& stick, const Fraction& etick);
static void doLayoutTiesLinear(System* system);
static void layoutTies(Chord* ch, System* system, const Fraction& stick, LayoutContext& ctx);
static void doLayoutTies(System* system, std::vector<Segment*> sl, const Fraction& stick, const Fraction& etick, LayoutContext& ctx);
static void doLayoutTiesLinear(System* system, LayoutContext& ctx);
static void layoutGuitarBends(const std::vector<Segment*>& sl, LayoutContext& ctx);
static void justifySystem(System* system, double curSysWidth, double targetSystemWidth);
static void updateCrossBeams(System* system, LayoutContext& ctx);
Expand Down
8 changes: 1 addition & 7 deletions src/engraving/rendering/dev/tdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2220,17 +2220,11 @@ void TDraw::draw(const Note* item, Painter* painter)

// tablature
if (tablature) {
if (item->displayFret() == Note::DisplayFretOption::Hide) {
if (item->displayFret() == Note::DisplayFretOption::Hide || item->shouldHideFret()) {
return;
}
const Staff* st = item->staff();
const StaffType* tab = st->staffTypeForElement(item);
if (item->tieBack() && !tab->showBackTied()) {
if (item->chord()->measure()->system() == item->tieBack()->startNote()->chord()->measure()->system() && item->el().empty()) {
// fret should be hidden, so return without drawing it
return;
}
}
// draw background, if required (to hide a segment of string line or to show a fretting conflict)
if (!tab->linesThrough() || item->fretConflict()) {
double d = item->spatium() * .1;
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/style/styledef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "dom/articulation.h"
#include "dom/mscore.h"
#include "dom/realizedharmony.h"
#include "dom/stafftype.h"
#include "dom/textbase.h"
#include "dom/tuplet.h"
#include "dom/types.h"
Expand Down Expand Up @@ -1597,6 +1598,10 @@ const std::array<StyleDef::StyleValue, size_t(Sid::STYLES)> StyleDef::styleValue
{ Sid::golpeShowTabSimple, "golpeShowTabSimple", true },
{ Sid::golpeShowTabCommon, "golpeShowTabCommon", true },

{ Sid::tabShowTiedFret, "tabShowTiedFret", int(ShowTiedFret::TIE_AND_FRET) },
{ Sid::tabParenthesizeTiedFret, "tabParenthesizeTiedFret", int(ParenthesizeTiedFret::START_OF_SYSTEM) },
{ Sid::parenthesizeTiedFretIfArticulation, "parenthesizeTiedFretIfArticulation", true },

{ Sid::chordlineThickness, "chordlineThickness", Spatium(0.16) },

{ Sid::autoplaceEnabled, "autoplaceEnabled", true },
Expand Down
4 changes: 4 additions & 0 deletions src/engraving/style/styledef.h
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,10 @@ enum class Sid {
golpeShowTabSimple,
golpeShowTabCommon,

tabShowTiedFret,
tabParenthesizeTiedFret,
parenthesizeTiedFretIfArticulation,

chordlineThickness,

autoplaceEnabled,
Expand Down
4 changes: 3 additions & 1 deletion src/framework/ui/view/uitheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ void UiTheme::drawRadioButtonIndicator(QPainter* painter, const QRect& rect, con
QColor borderColor = fontPrimaryColor();
QColor backgroundColor = textFieldColor();

if (styleState.pressed) {
if (!styleState.enabled) {
borderColor.setAlphaF(itemOpacityDisabled());
} else if (styleState.pressed) {
borderColor.setAlphaF(buttonOpacityHit());
} else if (styleState.hovered) {
borderColor.setAlphaF(buttonOpacityHover());
Expand Down
4 changes: 0 additions & 4 deletions src/notation/view/widgets/editstafftype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ EditStaffType::EditStaffType(QWidget* parent)
connect(showTabFingering, &QCheckBox::toggled, this, &EditStaffType::updatePreview);
connect(upsideDown, &QCheckBox::toggled, this, &EditStaffType::updatePreview);
connect(numbersRadio, &QCheckBox::toggled, this, &EditStaffType::updatePreview);
connect(showBackTied, &QCheckBox::toggled, this, &EditStaffType::updatePreview);

connect(templateReset, &QPushButton::clicked, this, &EditStaffType::resetToTemplateClicked);
connect(addToTemplates, &QPushButton::clicked, this, &EditStaffType::addToTemplatesClicked);
Expand Down Expand Up @@ -283,7 +282,6 @@ void EditStaffType::setValues()
aboveLinesRadio->setChecked(!staffType.onLines());
linesThroughRadio->setChecked(staffType.linesThrough());
linesBrokenRadio->setChecked(!staffType.linesThrough());
showBackTied->setChecked(staffType.showBackTied());

idx = durFontName->findText(staffType.durationFontName(), Qt::MatchFixedString);
if (idx == -1) {
Expand Down Expand Up @@ -450,7 +448,6 @@ void EditStaffType::setFromDlg()
staffType.setFretFontSize(fretFontSize->value());
staffType.setFretFontUserY(fretY->value());
staffType.setLinesThrough(linesThroughRadio->isChecked());
staffType.setShowBackTied(showBackTied->isChecked());
staffType.setMinimStyle(minimNoneRadio->isChecked() ? mu::engraving::TablatureMinimStyle::NONE
: (minimShortRadio->isChecked() ? mu::engraving::TablatureMinimStyle::SHORTER : mu::engraving::
TablatureMinimStyle::
Expand Down Expand Up @@ -512,7 +509,6 @@ void EditStaffType::blockSignals(bool block)
aboveLinesRadio->blockSignals(block);
linesThroughRadio->blockSignals(block);
linesBrokenRadio->blockSignals(block);
showBackTied->blockSignals(block);

durFontName->blockSignals(block);
durFontSize->blockSignals(block);
Expand Down