Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Urs Liska

No idea about Scheme,

but shouldn't a standard barline have the desired length by default?

Best
Urs

Am 23.05.2012 18:57, schrieb Thomas Morley:

Hi,

I'm trying to read out the current height of a StaffGroup, i.e. from
the bottom-line of the bottom-staff up to the top-line of the
top-staff.

As a test I created a new BreathingSign-stencil drawing a line from
top-line to bottom-line. The value for draw-line is figured out
manually for now. Of course I want to automate this.

\version 2.15.38

#(define ((staff-group-height number) grob)
  (let* ((stil (ly:text-interface::print grob))
 (par1 (ly:grob-parent grob Y)) ;; #Grob VerticalAxisGroup
 (par2 (ly:grob-parent par1 Y)) ;; #Grob VerticalAlignment
 (par3 (ly:grob-parent par2 Y)) ;; #Grob System
 )

  ;(newline)(display par1 )(display par1)

  (ly:grob-set-property! grob 'stencil
(grob-interpret-markup grob
(make-line-markup
  (list
  (make-with-dimensions-markup '(0 . 0) '(0 . 0)
(make-with-color-markup blue
  (make-draw-line-markup (cons 0 number))

%- Test

one = {
 \relative c' {
a2 b
\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -13)
c\breathe d \break
a,, b''
\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -22.5)
c\breathe d
 }
}

two = {
 \relative c {
\clef bass
a2 b c d a'' b,, c d
 }
}

\score {
 \new StaffGroup
\new Staff \one
\new Staff \two

}

I don't know which grob/item/stencil I should adress to catch the
needed value and how.

Any hint would be appreciated.

Thanks,
   Harm

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user



___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Thomas Morley
2012/5/23 Urs Liska li...@ursliska.de:
 but shouldn't a standard barline have the desired length by default?

Of course, but the new BreathingSign-stencil is only to visualize that
I've got the correct value.
And a BarLine lives in Staff-context but I want the StaffGroup-size.

Trying:

\override Score.BarLine #'stencil =
  #(lambda (grob)
(let* ((stil (ly:bar-line::print grob))
   (stil-ext-y (interval-length
(ly:stencil-extent stil Y
   (newline)(display stil-ext-y)
   stil))

returns every time the same value, in this case: 3.9975

As expected.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread m...@apollinemike.com
On 23 mai 2012, at 19:19, Thomas Morley wrote:

 2012/5/23 Urs Liska li...@ursliska.de:
 but shouldn't a standard barline have the desired length by default?
 
 Of course, but the new BreathingSign-stencil is only to visualize that
 I've got the correct value.
 And a BarLine lives in Staff-context but I want the StaffGroup-size.
 
 Trying:
 
\override Score.BarLine #'stencil =
  #(lambda (grob)
(let* ((stil (ly:bar-line::print grob))
   (stil-ext-y (interval-length
 (ly:stencil-extent stil Y
   (newline)(display stil-ext-y)
   stil))
 
 returns every time the same value, in this case: 3.9975
 
 As expected.
 

Try the buddy engraver!

buddyEngraver =
#(let ((match-list '())
   (name-list '()))
   (list
 (cons 'acknowledgers
   (list
 (cons 'grob-interface
   (lambda (engraver grob source-engraver)
   (let ((name (ly:grob-property grob 'my-name))
 (searching (ly:grob-property grob 
'searching)))
(set! name-list (cons (cons name grob) 
name-list))
(set! match-list (append (map (lambda (x) 
(cons name x)) searching) match-list)))
 (cons 'finalize
  (lambda (trans)
(for-each
  (lambda (x) ;(format #t MATCHING ~a\n x)
(let ((grob1 (assoc-get (car x) name-list))
  (grob2 (assoc-get (cdr x) name-list)))
(ly:grob-set-property! grob2 'buddies (cons (cons (car x) 
grob1) (ly:grob-property grob2 'buddies)))
(ly:grob-set-property! grob1 'buddies (cons (cons (cdr x) 
grob2) (ly:grob-property grob1 'buddies)
  match-list)

Then, \layout \context { \Staff \consists \buddyEngraver }

If you do something like \override Staff.BarLine #'my-name = #'foo in one staff 
and \override Staff.BarLine #'my-name = #'bar in another and then \override 
BreathingSign #'searching = #'(foo bar) then BreathingSign will have a property 
'buddies set with two buddies (the two barlines). You can then find their 
positions via the normal grob-relative-position-finding functions.

Cheers,
MS


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Thomas Morley
2012/5/23 m...@apollinemike.com m...@apollinemike.com:

 Try the buddy engraver!
(...)
 If you do something like \override Staff.BarLine #'my-name = #'foo in one 
 staff and \override Staff.BarLine #'my-name = #'bar in another and then 
 \override BreathingSign #'searching = #'(foo bar) then BreathingSign will 
 have a property 'buddies set with two buddies (the two barlines). You can 
 then find their positions via the normal grob-relative-position-finding 
 functions.

Hi Mike,

thanks for your suggestion!

As a first step I tried to display 'buddies via
BreathingSign-override. No success.
Am I doing sth wrong?

BTW, to get rid of the loads of warnings I added some more code,
trying to integrate the new properties.


\version 2.15.38

#(define (define-grob-custom-property symbol type? description)
  (if (not (equal? (object-property symbol 'backend-doc) #f))
  (ly:error (_ symbol ~S redefined) symbol))

  (set-object-property! symbol 'backend-type? type?)
  (set-object-property! symbol 'backend-doc description)
  symbol)

#(define all-user-grob-custom-properties
  (map
   (lambda (x)
 (apply define-grob-custom-property x))

   `(
 (buddies ,list? Grobs for function-call)
 (searching ,list? Looks for buddies)
 (my-name ,symbol? general custom-grob-property-name)
 )))

#(define all-custom-grob-descriptions
   (for-each
 (lambda (x)
   (let ((interfaces
   (ly:assoc-get 'interfaces
 (ly:assoc-get 'meta
   (cdr x)
 (set! interfaces (append! interfaces '(grob-marker-interface)
 all-grob-descriptions))

buddyEngraver =
   #(let ((match-list '())
  (name-list '()))
  (list
(cons 'acknowledgers
  (list
(cons 'grob-interface
  (lambda (engraver grob source-engraver)
  (let ((name (ly:grob-property grob 'my-name))
(searching (ly:grob-property grob
'searching)))
   (set! name-list (cons (cons name
grob) name-list))
   (set! match-list (append (map
(lambda (x) (cons name x)) searching) match-list)))
(cons 'finalize
 (lambda (trans)
   (for-each
 (lambda (x) ;(format #t MATCHING ~a\n x)
   (let ((grob1 (assoc-get (car x) name-list))
 (grob2 (assoc-get (cdr x) name-list)))
   (ly:grob-set-property! grob2 'buddies (cons (cons
(car x) grob1) (ly:grob-property grob2 'buddies)))
   (ly:grob-set-property! grob1 'buddies (cons (cons
(cdr x) grob2) (ly:grob-property grob1 'buddies)
 match-list)

#(define ((staff-group-height number) grob)
 (let* ((stil (ly:text-interface::print grob))
(par1 (ly:grob-parent grob Y))  ;; #Grob VerticalAxisGroup 
(par2 (ly:grob-parent par1 Y))  ;; #Grob VerticalAlignment 
(par3 (ly:grob-parent par2 Y))  ;; #Grob System 
(buddies (ly:grob-property grob 'buddies))
)

 (newline)(display buddies )(display buddies)

 (ly:grob-set-property! grob 'stencil
   (grob-interpret-markup grob
   (make-line-markup
 (list
 (make-with-dimensions-markup '(0 . 0) '(0 . 0)
   (make-with-color-markup blue
 (make-draw-line-markup (cons 0 number))

%- Test

one = {
\relative c' {
a2 b
\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -13)
\override Score.BreathingSign #'searching = #'(foo bar)
\override Staff.BarLine #'my-name = #'foo
c\breathe
d \break
a,, b''

\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -22.5)

c\breathe d
}
}

two = {
\relative c {
\clef bass
a2 b \override Staff.BarLine #'my-name = #'bar
c d a'' b,, c d
}
}

\score {
\new StaffGroup 
   \new Staff \one
   \new Staff \two
   
\layout {
\context {
\Staff
\consists \buddyEngraver
}
}
}

Thanks,
  Harm

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Thomas Morley
2012/5/23 David Kastrup d...@gnu.org:
 Thomas Morley thomasmorle...@googlemail.com writes:

 #(define all-custom-grob-descriptions
    (for-each
      (lambda (x)
        (let ((interfaces
                (ly:assoc-get 'interfaces
                  (ly:assoc-get 'meta
                    (cdr x)
          (set! interfaces (append! interfaces '(grob-marker-interface)
      all-grob-descriptions))

 It is probably tiresome of me to point this out, but tampering with the
 global internal data structures of LilyPond is not a good idea since it
 means that in

 lilypond file1.ly file2.ly

 the output for file2 is no longer independent from what happens in
 file1.  So instead of making a fake all-custom-grob-description
 definition that is actually not used, but as a side-effect replaces the
 existing internals, maybe consider actually creating a separate modified
 copy and use \grobdescriptions to embed it in the Global context used in
 this file.

 --
 David Kastrup

Hi David,

sorry for that.
It was a copy/paste-error. Actually, I don't want to define a new
grob, only new properties.

The foolowing seems to be ok, or not?

\version 2.15.38

#(define (define-grob-property symbol type? description)
  (if (not (equal? (object-property symbol 'backend-doc) #f))
  (ly:error (_ symbol ~S redefined) symbol))

  (set-object-property! symbol 'backend-type? type?)
  (set-object-property! symbol 'backend-doc description)
  symbol)

#(map
  (lambda (x)
(apply define-grob-property x))
`(
  (marker ,symbol? Marker in grob for function-call)
))

\relative c' {
c1
\override Staff.BarLine #'after-line-breaking =
 #(lambda (grob)
  (let ((xy (ly:grob-property grob 'marker)))
  (newline)(display xy)))
d
\override Staff.BarLine #'marker = #'foo
e
}

-Harm

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread David Kastrup
Thomas Morley thomasmorle...@googlemail.com writes:

 It was a copy/paste-error. Actually, I don't want to define a new
 grob, only new properties.

 The foolowing seems to be ok, or not?

 \version 2.15.38

 #(define (define-grob-property symbol type? description)
   (if (not (equal? (object-property symbol 'backend-doc) #f))
   (ly:error (_ symbol ~S redefined) symbol))

   (set-object-property! symbol 'backend-type? type?)
   (set-object-property! symbol 'backend-doc description)
   symbol)

Mostly harmless.  It puts object-properties on symbols, and symbols are
global entities IIRC (their bindings/variables are module-local in
contrast).  So depending on whether the symbol gets garbage-collected
between files or not (depends on whether this particular symbol is used
for any purpose anywhere in the global code or variables), behavior
might differ, in that you might or might not get complaints when using
this property without defining it.

But that is a design mistake you can't really avoid with reasonable
effort, and the worst that can happen is that you get unexpected
undefined behavior instead of an error message/warning.

 #(map
   (lambda (x)
 (apply define-grob-property x))
 `(
   (marker ,symbol? Marker in grob for function-call)
 ))

No point in using map when throwing the result away.  Use for-each
instead.

 \relative c' {
 c1
 \override Staff.BarLine #'after-line-breaking =
  #(lambda (grob)
   (let ((xy (ly:grob-property grob 'marker)))
   (newline)(display xy)))
 d
 \override Staff.BarLine #'marker = #'foo
 e
 }

At some point of time, LilyPond may become unhappy when setting
properties that are not in any interface or grob definition.  But then
it will probably also get a proper API for defining such things, and so
one can leave off worrying until then.

This code is depending on internals of LilyPond, but it is at least not
overwriting them.  If the internals or interfaces changes, it will
break, and there will be no convert-ly migration for it.

At the current point of time, you cannot do better.

-- 
David Kastrup

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Thomas Morley
2012/5/23 David Kastrup d...@gnu.org:
 Thomas Morley thomasmorle...@googlemail.com writes:

 It was a copy/paste-error. Actually, I don't want to define a new
 grob, only new properties.

 The foolowing seems to be ok, or not?

 \version 2.15.38

 #(define (define-grob-property symbol type? description)
   (if (not (equal? (object-property symbol 'backend-doc) #f))
       (ly:error (_ symbol ~S redefined) symbol))

   (set-object-property! symbol 'backend-type? type?)
   (set-object-property! symbol 'backend-doc description)
   symbol)

 Mostly harmless.  It puts object-properties on symbols, and symbols are
 global entities IIRC (their bindings/variables are module-local in
 contrast).  So depending on whether the symbol gets garbage-collected
 between files or not (depends on whether this particular symbol is used
 for any purpose anywhere in the global code or variables), behavior
 might differ, in that you might or might not get complaints when using
 this property without defining it.

 But that is a design mistake you can't really avoid with reasonable
 effort, and the worst that can happen is that you get unexpected
 undefined behavior instead of an error message/warning.

 #(map
   (lambda (x)
     (apply define-grob-property x))
     `(
       (marker ,symbol? Marker in grob for function-call)
     ))

 No point in using map when throwing the result away.  Use for-each
 instead.

 \relative c' {
         c1
         \override Staff.BarLine #'after-line-breaking =
          #(lambda (grob)
           (let ((xy (ly:grob-property grob 'marker)))
           (newline)(display xy)))
         d
         \override Staff.BarLine #'marker = #'foo
         e
 }

 At some point of time, LilyPond may become unhappy when setting
 properties that are not in any interface or grob definition.  But then
 it will probably also get a proper API for defining such things, and so
 one can leave off worrying until then.

 This code is depending on internals of LilyPond, but it is at least not
 overwriting them.  If the internals or interfaces changes, it will
 break, and there will be no convert-ly migration for it.

 At the current point of time, you cannot do better.

 --
 David Kastrup

Thanks for your explanations. Hopefully my mind is clearer now. :)

-Harm

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: How to catch the current height of a StaffGroup?

2012-05-23 Thread Thomas Morley
Next try to tackle the main problem, without engraver, but same idea:
Mark some grobs and read out their position.

After defining a 'marker-property and applying it with 'foo and 'bar
to some BarLines, I tried to color them from inside the
BreathingSign-after-line-breaking-override.
Works!

But every time I try to catch their coordinates in Y-axis-direction,
it results in a totally messed up output (but no problem with X-axis)
Regardless if I try:
ly:grob-relative-coordinate
ly:grob-robust-relative-extent
ly:grob-extent

%

\version 2.15.38

#(define (define-grob-property symbol type? description)
  (if (not (equal? (object-property symbol 'backend-doc) #f))
  (ly:error (_ symbol ~S redefined) symbol))

  (set-object-property! symbol 'backend-type? type?)
  (set-object-property! symbol 'backend-doc description)
  symbol)

#(for-each
  (lambda (x)
(apply define-grob-property x))
`(
  (marker ,symbol? Marker(s) in grob for function-call)
))

#(define ((staff-group-height number) grob)
 (let* ((stil (ly:text-interface::print grob))
(par1 (ly:grob-parent grob Y))  ;; #Grob VerticalAxisGroup 
(par2 (ly:grob-parent par1 Y))  ;; #Grob VerticalAlignment 
(sys (ly:grob-parent par2 Y))   ;; #Grob System 
(elements-lst (ly:grob-array-list (ly:grob-object sys
'all-elements)))
(grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
(lst-1 (filter
  (lambda (x) (and (eq? 'BarLine (grob-name x))
(equal? (ly:grob-property x 'marker) 'foo)))
 elements-lst))
(lst-2 (filter
  (lambda (x) (and (eq? 'BarLine (grob-name x))
(equal? (ly:grob-property x 'marker) 'bar)))
 elements-lst))
(top (ly:grob-relative-coordinate (car lst-1) sys Y))
;(top (ly:grob-extent (car lst-1) sys Y))
;(top (ly:grob-robust-relative-extent (car lst-1) sys Y))

;(bottom (ly:grob-relative-coordinate (car lst-2) sys Y))
;(bottom (ly:grob-robust-relative-extent (car lst-2) sys Y))
;(height (interval-length (cons (car bottom) (cdr top
)

 ;(newline)(display top)(display top)
 ;(newline)(display bottom )(display bottom )

 (ly:grob-set-property! (car lst-1) 'color green)
 (ly:grob-set-property! (car lst-2) 'color red)

 (ly:grob-set-property! grob 'stencil
   (grob-interpret-markup grob
   (make-line-markup
 (list
 (make-with-dimensions-markup '(0 . 0) '(0 . 0)
   (make-with-color-markup blue
 (make-draw-line-markup (cons 0 number ))

%- Test

one = {
\relative c' {

a2 b
\override Staff.BarLine #'marker = #'foo
\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -13)

c\breathe
d \break
a,, b''

\override Score.BreathingSign #'after-line-breaking =
#(staff-group-height -22.5)

c\breathe d
}
}

two = {
\relative c {
\clef bass
a2 b \override Staff.BarLine #'marker = #'bar
c d a'' b,, c d
}
}

\score {
\new StaffGroup 
   \new Staff \one
   \new Staff \one
   \new Staff \one
   \new Staff \two
   
}

%%%

What am I missing?

-Harm

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user