lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spacing grobs with an invisible object between them (hack)


From: Aaron Hill
Subject: Re: Spacing grobs with an invisible object between them (hack)
Date: Thu, 06 Feb 2020 19:27:52 -0800
User-agent: Roundcube Webmail/1.4.2

On 2020-02-06 3:02 pm, Paolo Prete wrote:
On Thu, Feb 6, 2020 at 6:04 PM Aaron Hill <address@hidden> wrote:

On 2020-02-06 8:35 am, Paolo Prete wrote:
> I ask you if is it possible to remove the noisy default  #OSSPW param
> as
> well, in the function call.


Also: I'm seeing that it compiles well on 2.19.45 (lilybin) but doesn't
compile on 2.19.83

\setOSPosition "Staff.SustainPedalLineSpanner" 2 {}
test.ly:18:18: error: bad grob property path
\once \override
                $obj .outside-staff-priority = #(* 105 pos)

This is where symbol-list? comes in. LilyPond appears to have handled strings and symbols in similar ways in the past such that you can interchange them. Something must have changed between the version, but the solution should be to avoid strings and stick only to symbols.

Consider the following examples:

%%%%
\version "2.19"

foo = #(define-music-function (grobpath) (symbol-list?)
  #{ \once \override #grobpath . color = #red #})

{ \foo Staff.Clef \foo Slur aes'4( b' \foo Accidental cis''2) }

#(define (symbol-list-or-music? x) (or (symbol-list? x) (ly:music? x)))

baz = #(define-music-function (arg) (symbol-list-or-music?)
  (if (ly:music? arg)
      #{ -\tweak color #green #arg #}
      #{ \once \override #arg . color = #red #}))

{ \baz Staff.Clef aes'4 -\baz ( b' \baz Accidental cis''2) }
%%%%

This second pattern is of more importance. It mimics the behavior and usage of \offset which can be used in both \override-style and \tweak-style.

I have applied this logic to your code and made some changes [1].

[1]: http://lilybin.com/bt0t2d/11

* OSSpacer did not need to specify TextScript when \tweaking.
* setOSPosition uses the pattern above to accept either a grob path or music.
* Argument order changes so that "pos" is first,
  but the spurious empty music {} expressions are gone.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\version "2.19.45"

#(define OSSPW 3)
#(define OSSPacerColor white)

#(define (number-or-number-pair? x) (or (number? x) (number-pair? x)))

OSSpacer = #(define-music-function (pos arg) (number? number-or-number-pair?)
(let ((width (if (pair? arg) (cdr arg) OSSPW))
      (height (if (pair? arg) (car arg) arg)))
#{ -\tweak color #OSSPacerColor -\tweak outside-staff-priority #(* 100 pos)
    -\markup{ \filled-box #(cons 0 width) #(cons 0 height) #0 } #}))

#(define (symbol-list-or-music? x) (or (symbol-list? x) (ly:music? x)))

setOSPosition = #(define-music-function (pos arg) (number? symbol-list-or-music?)
  (if (ly:music? arg)
    #{ -\tweak outside-staff-priority #(* 105 pos) #arg #}
    #{ \once \override #arg .outside-staff-priority = #(* 105 pos) #}))

{

\time 2/4
\set Staff.pedalSustainStyle = #'mixed
\once \override TupletBracket.direction = #UP
#(set! OSSPacerColor grey)

% Assign a position to each object.
% A lower position is nearer to the staff.
% Different markups can have different positions
% and their positions is set "inline" (see below)

% Objects above staff
\setOSPosition 1 Script
\setOSPosition 2 TupletBracket
\setOSPosition 3 Slur
\setOSPosition 4 Staff.OttavaBracket
% Objects below staff
\setOSPosition 1 DynamicLineSpanner
\setOSPosition 2 Staff.SustainPedalLineSpanner
\setOSPosition 3 Staff.SostenutoPedalLineSpanner

\tuplet 3/2 { \ottava #1 c''''

% Place objects above/below the staff according to
% the previous positions list and create barriers between them.
% Each barrier has a default width = $OSSPW (3)

^\OSSpacer 5 4 -\setOSPosition 5 ^\markup { "Espressivo" }
^\OSSpacer 4 2
^\OSSpacer 3 3 ^(
^\OSSpacer 2 2
^\OSSpacer 1 0.7 ^>
%------------------------------------------
%------------------------------------------
%------------------STAFF-------------------
%------------------------------------------
%------------------------------------------
_\OSSpacer 1 #'(5 . 8) \mf
_\OSSpacer 2 3 \sustainOn
_\OSSpacer 3 4 \sostenutoOn
_\OSSpacer 4 3 -\setOSPosition 4 _\markup { "Use pedal with care!"}

c'''' c'''')\sustainOff\sostenutoOff \ottava #0 }

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


-- Aaron Hill



reply via email to

[Prev in Thread] Current Thread [Next in Thread]