@@ -1914,30 +1914,38 @@ void MeasureLayout::setCourtesyClef(Measure* m, const Fraction& refClefTick, con
19141914 }
19151915}
19161916
1917- void MeasureLayout::createParenthesis (Segment* segment, const DirectionH direction, const track_idx_t track)
1917+ Parenthesis* MeasureLayout::findOrCreateParenthesis (Segment* segment, const DirectionH direction, const track_idx_t track)
19181918{
19191919 if (!segment->element (track)) {
1920- return ;
1920+ return nullptr ;
19211921 }
19221922
19231923 std::vector<EngravingItem*> parens = segment->findAnnotations (ElementType::PARENTHESIS, track, track);
1924- bool foundMatchingParen = false ;
1924+
19251925 for (EngravingItem* el : parens) {
19261926 if (!el->isParenthesis () || toParenthesis (el)->direction () != direction) {
19271927 continue ;
19281928 }
1929- foundMatchingParen = true ;
1930- break ;
1931- }
1932-
1933- if (foundMatchingParen) {
1934- return ;
1929+ return toParenthesis (el);
19351930 }
19361931
19371932 Parenthesis* paren = Factory::createParenthesis (segment);
19381933 paren->setTrack (track);
19391934 paren->setDirection (direction);
19401935 segment->add (paren);
1936+
1937+ return paren;
1938+ }
1939+
1940+ static void calcParenTopBottom (Parenthesis* item, double & top, double & bottom)
1941+ {
1942+ Segment* seg = item->segment ();
1943+ EngravingItem* el = seg->element (item->track ());
1944+ const double spatium = item->spatium ();
1945+ if (el) {
1946+ top = std::min (top, el->shape ().top () + el->pos ().y () + spatium / 2 );
1947+ bottom = std::max (bottom, el->shape ().bottom () + el->pos ().y () - spatium / 2 );
1948+ }
19411949}
19421950
19431951void MeasureLayout::addRepeatCourtesyParentheses (Measure* m, const bool continuation, LayoutContext& ctx)
@@ -1949,6 +1957,8 @@ void MeasureLayout::addRepeatCourtesyParentheses(Measure* m, const bool continua
19491957 const Fraction sigTick = continuation ? Fraction (0 , 0 ) : m->ticks ();
19501958
19511959 for (track_idx_t track = 0 ; track <= ctx.dom ().nstaves () * VOICES; track += VOICES) {
1960+ double top = DBL_MAX;
1961+ double bottom = -DBL_MAX;
19521962 Segment* leftMostSeg = m->findSegmentR (clefSegType, sigTick);
19531963
19541964 if (!leftMostSeg || !leftMostSeg->enabled () || !leftMostSeg->element (track)) {
@@ -1964,7 +1974,7 @@ void MeasureLayout::addRepeatCourtesyParentheses(Measure* m, const bool continua
19641974 return ;
19651975 }
19661976
1967- createParenthesis (leftMostSeg, DirectionH::LEFT, track);
1977+ Parenthesis* leftParen = findOrCreateParenthesis (leftMostSeg, DirectionH::LEFT, track);
19681978
19691979 Segment* rightMostSeg = m->findSegmentR (tsSegType, sigTick);
19701980 if (!rightMostSeg || !rightMostSeg->enabled () || !rightMostSeg->element (track)) {
@@ -1980,7 +1990,17 @@ void MeasureLayout::addRepeatCourtesyParentheses(Measure* m, const bool continua
19801990 return ;
19811991 }
19821992
1983- createParenthesis (rightMostSeg, DirectionH::RIGHT, track);
1993+ Parenthesis* rightParen = findOrCreateParenthesis (rightMostSeg, DirectionH::RIGHT, track);
1994+ if (ctx.conf ().styleB (Sid::smallParens)) {
1995+ calcParenTopBottom (leftParen, top, bottom);
1996+ calcParenTopBottom (rightParen, top, bottom);
1997+
1998+ const double height = bottom - top;
1999+ rightParen->mutldata ()->startY .set_value (top);
2000+ rightParen->mutldata ()->height .set_value (height);
2001+ leftParen->mutldata ()->startY .set_value (top);
2002+ leftParen->mutldata ()->height .set_value (height);
2003+ }
19842004 }
19852005}
19862006
0 commit comments