For a general solution, one could probably write a callback for the positions
property.
I was hoping to use #'outside-staff-priority to try to allow the tuplet to
float into the staff automatically, but gave up after a few minutes of not
finding the right incantation…
I never really understood the outside-staff behaviour, to be honest.
It's well possible that there's an elegant solution that just tells
LilyPond to go ahead and put the tuplet bracket into the staff.
A poor man's automated solution might be:
\version "2.23.4"
x = { r2 \tuplet 3/2 { g4 a b } r2 \tuplet 3/2 { c'4 a g } }
\addQuote "qx" \x
{
r2 \cueDuring #"qx" #DOWN {
\override CueVoice.TupletBracket.positions =
#(lambda (grob)
(define (get-top direction)
(cdr (ly:grob-property
(ly:spanner-bound grob direction)
'Y-extent)))
(cons (+ (get-top LEFT) 1.5) (+ (get-top RIGHT) 1.5)))
\override CueVoice.TupletBracket.direction = #UP
{ r2 r2 r2 }
}
}
Lukas