@@ -1914,31 +1914,30 @@ void MeasureLayout::setCourtesyClef(Measure* m, const Fraction& refClefTick, con
19141914 }
19151915}
19161916
1917- void MeasureLayout::createParenthesis (Segment* segment, const DirectionH direction, LayoutContext& ctx )
1917+ void MeasureLayout::createParenthesis (Segment* segment, const DirectionH direction, const track_idx_t track )
19181918{
1919- for (track_idx_t track = 0 ; track <= ctx.dom ().nstaves () * VOICES; track += VOICES) {
1920- if (!segment->element (track)) {
1921- continue ;
1922- }
1923-
1924- std::vector<EngravingItem*> parens = segment->findAnnotations (ElementType::PARENTHESIS, track, track);
1925- bool foundMatchingParen = false ;
1926- for (EngravingItem* el : parens) {
1927- if (!el->isParenthesis () || toParenthesis (el)->direction () != direction) {
1928- continue ;
1929- }
1930- foundMatchingParen = true ;
1931- }
1919+ if (!segment->element (track)) {
1920+ return ;
1921+ }
19321922
1933- if (foundMatchingParen) {
1923+ std::vector<EngravingItem*> parens = segment->findAnnotations (ElementType::PARENTHESIS, track, track);
1924+ bool foundMatchingParen = false ;
1925+ for (EngravingItem* el : parens) {
1926+ if (!el->isParenthesis () || toParenthesis (el)->direction () != direction) {
19341927 continue ;
19351928 }
1929+ foundMatchingParen = true ;
1930+ break ;
1931+ }
19361932
1937- Parenthesis* paren = Factory::createParenthesis (segment);
1938- paren->setTrack (track);
1939- paren->setDirection (direction);
1940- segment->add (paren);
1933+ if (foundMatchingParen) {
1934+ return ;
19411935 }
1936+
1937+ Parenthesis* paren = Factory::createParenthesis (segment);
1938+ paren->setTrack (track);
1939+ paren->setDirection (direction);
1940+ segment->add (paren);
19421941}
19431942
19441943void MeasureLayout::addRepeatCourtesyParentheses (Measure* m, const bool continuation, LayoutContext& ctx)
@@ -1949,63 +1948,80 @@ void MeasureLayout::addRepeatCourtesyParentheses(Measure* m, const bool continua
19491948
19501949 const Fraction sigTick = continuation ? Fraction (0 , 0 ) : m->ticks ();
19511950
1952- Segment* leftMostSeg = m->findSegmentR (clefSegType, sigTick);
1951+ for (track_idx_t track = 0 ; track <= ctx.dom ().nstaves () * VOICES; track += VOICES) {
1952+ Segment* leftMostSeg = m->findSegmentR (clefSegType, sigTick);
19531953
1954- if (!leftMostSeg || !leftMostSeg->enabled ()) {
1955- leftMostSeg = m->findSegmentR (ksSegType, sigTick);
1956- }
1954+ if (!leftMostSeg || !leftMostSeg->enabled () || !leftMostSeg-> element (track )) {
1955+ leftMostSeg = m->findSegmentR (ksSegType, sigTick);
1956+ }
19571957
1958- if (!leftMostSeg || !leftMostSeg->enabled ()) {
1959- leftMostSeg = m->findSegmentR (tsSegType, sigTick);
1960- }
1958+ if (!leftMostSeg || !leftMostSeg->enabled () || !leftMostSeg-> element (track )) {
1959+ leftMostSeg = m->findSegmentR (tsSegType, sigTick);
1960+ }
19611961
1962- if (!leftMostSeg || !leftMostSeg->enabled ()) {
1963- removeRepeatCourtesyParentheses (m, continuation, ctx );
1964- return ;
1965- }
1962+ if (!leftMostSeg || !leftMostSeg->enabled () || !leftMostSeg-> element (track )) {
1963+ removeRepeatCourtesyParenthesesSegment (leftMostSeg, track, DirectionH::LEFT );
1964+ return ;
1965+ }
19661966
1967- createParenthesis (leftMostSeg, DirectionH::LEFT, ctx );
1967+ createParenthesis (leftMostSeg, DirectionH::LEFT, track );
19681968
1969- Segment* rightMostSeg = m->findSegmentR (tsSegType, sigTick);
1970- if (!rightMostSeg || !rightMostSeg->enabled ()) {
1971- rightMostSeg = m->findSegmentR (ksSegType, sigTick);
1972- }
1969+ Segment* rightMostSeg = m->findSegmentR (tsSegType, sigTick);
1970+ if (!rightMostSeg || !rightMostSeg->enabled () || !rightMostSeg-> element (track )) {
1971+ rightMostSeg = m->findSegmentR (ksSegType, sigTick);
1972+ }
19731973
1974- if (!rightMostSeg || !rightMostSeg->enabled ()) {
1975- rightMostSeg = m->findSegmentR (clefSegType, sigTick);
1976- }
1974+ if (!rightMostSeg || !rightMostSeg->enabled () || !rightMostSeg-> element (track )) {
1975+ rightMostSeg = m->findSegmentR (clefSegType, sigTick);
1976+ }
19771977
1978- if (!rightMostSeg || !rightMostSeg->enabled ()) {
1979- removeRepeatCourtesyParentheses (m, continuation, ctx );
1980- return ;
1981- }
1978+ if (!rightMostSeg || !rightMostSeg->enabled () || !rightMostSeg-> element (track )) {
1979+ removeRepeatCourtesyParenthesesSegment (rightMostSeg, track, DirectionH::RIGHT );
1980+ return ;
1981+ }
19821982
1983- createParenthesis (rightMostSeg, DirectionH::RIGHT, ctx);
1983+ createParenthesis (rightMostSeg, DirectionH::RIGHT, track);
1984+ }
19841985}
19851986
1986- void MeasureLayout::removeRepeatCourtesyParentheses (Measure* m, const bool continuation, LayoutContext& ctx)
1987+ void MeasureLayout::removeRepeatCourtesyParenthesesMeasure (Measure* m, const bool continuation, LayoutContext& ctx)
19871988{
19881989 const SegmentType tsSegType = continuation ? SegmentType::TimeSigStartRepeatAnnounce : SegmentType::TimeSigRepeatAnnounce;
19891990 const SegmentType ksSegType = continuation ? SegmentType::KeySigStartRepeatAnnounce : SegmentType::KeySigRepeatAnnounce;
19901991 const SegmentType clefSegType = continuation ? SegmentType::ClefStartRepeatAnnounce : SegmentType::ClefRepeatAnnounce;
19911992
1992- Segment* clefSeg = m->findSegmentR (clefSegType, m->ticks ());
1993- Segment* ksSeg = m->findSegmentR (ksSegType, m->ticks ());
1994- Segment* tsSeg = m->findSegmentR (tsSegType, m->ticks ());
1993+ const Fraction sigTick = continuation ? Fraction (0 , 0 ) : m->ticks ();
1994+
1995+ Segment* clefSeg = m->findSegmentR (clefSegType, sigTick);
1996+ Segment* ksSeg = m->findSegmentR (ksSegType, sigTick);
1997+ Segment* tsSeg = m->findSegmentR (tsSegType, sigTick);
19951998
19961999 for (Segment* seg : { clefSeg, ksSeg, tsSeg }) {
19972000 if (!seg) {
19982001 continue ;
19992002 }
20002003 for (track_idx_t track = 0 ; track <= ctx.dom ().nstaves () * VOICES; track += VOICES) {
2001- std::vector<EngravingItem*> parens = seg->findAnnotations (ElementType::PARENTHESIS, track, track);
2002- for (EngravingItem* paren : parens) {
2003- if (!paren->isParenthesis ()) {
2004- continue ;
2005- }
2006- seg->remove (paren);
2007- }
2004+ removeRepeatCourtesyParenthesesSegment (seg, track);
2005+ }
2006+ }
2007+ }
2008+
2009+ void MeasureLayout::removeRepeatCourtesyParenthesesSegment (Segment* seg, const track_idx_t track, const DirectionH direction)
2010+ {
2011+ if (!seg) {
2012+ return ;
2013+ }
2014+
2015+ std::vector<EngravingItem*> parens = seg->findAnnotations (ElementType::PARENTHESIS, track, track);
2016+ for (EngravingItem* paren : parens) {
2017+ if (!paren->isParenthesis ()) {
2018+ continue ;
20082019 }
2020+ if (direction != DirectionH::AUTO && toParenthesis (paren)->direction () != direction) {
2021+ continue ;
2022+ }
2023+
2024+ seg->remove (paren);
20092025 }
20102026}
20112027
@@ -2016,54 +2032,50 @@ void MeasureLayout::setRepeatCourtesiesAndParens(Measure* m, LayoutContext& ctx)
20162032
20172033 if (showCourtesyRepeats) {
20182034 MeasureLayout::addRepeatCourtesies (m, ctx);
2035+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, false , ctx);
20192036 if (ctx.conf ().styleB (Sid::useParensRepeatCourtesies)) {
20202037 MeasureLayout::addRepeatCourtesyParentheses (m, false , ctx);
2021- } else {
2022- MeasureLayout::removeRepeatCourtesyParentheses (m, false , ctx);
20232038 }
20242039 }
20252040
20262041 if (showCourtesyOtherJumps) {
20272042 MeasureLayout::addRepeatCourtesies (m, ctx);
2043+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, false , ctx);
20282044 if (ctx.conf ().styleB (Sid::useParensOtherJumpCourtesies)) {
20292045 MeasureLayout::addRepeatCourtesyParentheses (m, false , ctx);
2030- } else {
2031- MeasureLayout::removeRepeatCourtesyParentheses (m, false , ctx);
20322046 }
20332047 }
20342048
20352049 if (!showCourtesyRepeats && !showCourtesyOtherJumps) {
2036- MeasureLayout::removeRepeatCourtesyParentheses (m, false , ctx);
2050+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, false , ctx);
20372051 }
20382052
20392053 const bool courtesiesAfterCancellingRepeats = m->prevMeasure () && m->prevMeasure ()->repeatEnd ()
2040- && !m->prevMeasure ()->endOfMeasureChange () && ctx.conf ().styleB (
2041- Sid::showCourtesiesAfterCancellingRepeats);
2054+ && !m->prevMeasure ()->endOfMeasureChange ()
2055+ && ctx.conf ().styleB (Sid::showCourtesiesAfterCancellingRepeats)
2056+ && ctx.conf ().styleB (Sid::showCourtesiesRepeats);
20422057 const bool courtesiesAfterCancellingOtherJumps = m->prevMeasure () && m->prevMeasure ()->repeatJump ()
2043- && !m->prevMeasure ()->endOfMeasureChange () && ctx.conf ().styleB (
2044- Sid::showCourtesiesAfterCancellingOtherJumps);
2058+ && !m->prevMeasure ()->endOfMeasureChange ()
2059+ && ctx.conf ().styleB (Sid::showCourtesiesAfterCancellingOtherJumps)
2060+ && ctx.conf ().styleB (Sid::showCourtesiesOtherJumps);
20452061 if (courtesiesAfterCancellingRepeats) {
20462062 MeasureLayout::addRepeatContinuationCourtesies (m, ctx);
2047-
2063+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, true , ctx);
20482064 if (ctx.conf ().styleB (Sid::useParensRepeatCourtesiesAfterCancelling)) {
20492065 MeasureLayout::addRepeatCourtesyParentheses (m, true , ctx);
2050- } else {
2051- MeasureLayout::removeRepeatCourtesyParentheses (m, true , ctx);
20522066 }
20532067 }
20542068
20552069 if (courtesiesAfterCancellingOtherJumps) {
20562070 MeasureLayout::addRepeatContinuationCourtesies (m, ctx);
2057-
2071+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, true , ctx);
20582072 if (ctx.conf ().styleB (Sid::useParensOtherJumpCourtesiesAfterCancelling)) {
20592073 MeasureLayout::addRepeatCourtesyParentheses (m, true , ctx);
2060- } else {
2061- MeasureLayout::removeRepeatCourtesyParentheses (m, true , ctx);
20622074 }
20632075 }
20642076
20652077 if (!courtesiesAfterCancellingRepeats && !courtesiesAfterCancellingOtherJumps) {
2066- MeasureLayout::removeRepeatCourtesyParentheses (m, true , ctx);
2078+ MeasureLayout::removeRepeatCourtesyParenthesesMeasure (m, true , ctx);
20672079 }
20682080}
20692081
0 commit comments