[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: metronome-mark-alignment
From: |
Thomas Morley |
Subject: |
Re: metronome-mark-alignment |
Date: |
Sat, 11 Jan 2020 23:36:53 +0100 |
Am Sa., 11. Jan. 2020 um 18:04 Uhr schrieb David Nalesnik
<address@hidden>:
>
>
>
> On Saturday, January 11, 2020, Daniel Rosen <address@hidden> wrote:
>>
>> On Jan 9, 2020, at 4:21 PM, Daniel Rosen <address@hidden> wrote:
>>
>> >> I have a new problem. If I take away the first instance of \music in each
>> >> staff of my original example,
>>
>>
>> > Whoops, meant to say *your* example with the revised function.
>>
>> >> the file fails to compile, and I get this error message:
>> >>
>> >>> ~/example-updated.ly:13:18: Wrong type argument in position 1 (expecting
>> >>> Grob_array): ()
>> >>
>> >> Can you help me with this one?
>>
>> Seems like this might have fallen through the cracks, so... bump.
>>
>> DR
>
>
> Sorry, no time at the moment. Perhaps someone else can help...
>
Probably:
\version "2.19.83"
%%%% https://archiv.lilypondforum.de/index.php/topic,2507.msg14157.html#msg14157
%%%% Code by xr:
#(define (get-parent-in-hierarchie grob searchword)
;; goes up in hierarchie until it finds
;; a grob named searchword
(define result #f)
(define (get-par grob)
(define compare
(lambda (x) (and (ly:grob? x) (equal? searchword (grob::name x)))))
(let* ((parx (ly:grob-parent grob X))
(pary (ly:grob-parent grob Y)))
(cond ((not (equal? result #f))
result)
((compare parx)
(set! result parx)
result)
((compare pary)
(set! result pary)
result)
(else
(if (ly:grob? parx)
(get-par parx))
(if(ly:grob? pary)
(get-par pary))))))
;; the inner function gets called from here
(let* ((result (get-par grob)))
;; check if we found something
(if (ly:grob? result)
result
#f)))
%%%% David Nalesnik's metronome-mark-alignment function:
#(define align-tempo-with-accidental
(lambda (grob)
(let* (;; returns PaperColumn- or NonMusicalPaperColumn-grob
(col (ly:item-get-column grob))
;; returns System-grob
;; maybe taking a sledgehammer to crack a nut...
(sys (get-parent-in-hierarchie grob 'System))
(all-array (ly:grob-object sys 'all-elements))
;; better be paranoid and check for ly:grob-array?
(all-list
(if (ly:grob-array? all-array)
(ly:grob-array->list all-array)
'()))
;; get all AccidentalPlacement-grobs
(acc-pl-grobs
(filter
(lambda (x)
(and (eq? col (ly:grob-parent x X))
(eq? 'AccidentalPlacement (grob::name x))))
all-list)))
;; print a stencil for PaperColumn or NonMusicalPaperColumn
;; (for debugging)
;(ly:grob-set-property! col 'stencil ly:paper-column::print)
;; if accidentals are present return the most left coodinate of most
;; left accidental to use for X-offset otherwise return the default.
(if (pair? acc-pl-grobs)
(let* (;; get all Accidental-grobs from AccidentalPlacement
(accs
;; TODO is it really safe to go for cadr only?
(map
cadr
(ly:grob-object (car acc-pl-grobs) 'accidental-grobs)))
;; get all X-extents of accs
(accs-x-exts
(map (lambda (x) (ly:grob-extent x sys X)) accs))
;; returns a pair containing most left, most right coordinate
;; of the accidentals
(un (reduce interval-union '() accs-x-exts)))
;; return most left coordinate
(car un))
;; Return the default.
(let* ((basic-props (ly:grob-basic-properties grob))
(default-x-off-proc (assoc-get 'X-offset basic-props)))
default-x-off-proc)))))
%%%% Tiny example:
\layout {
\context {
\Score
\override MetronomeMark.X-offset = #align-tempo-with-accidental
}
}
music = { cis'1 }
<<
\new Staff { \music \music }
\new Staff { \music \tempo "Tempo" \music }
>>
<<
\new Staff { \music \music }
\new Staff { \tempo "Tempo" \music \music }
>>
{
R1 |
\tempo "Tempo"
<aes' bes'>
\tempo "Tempo II"
<as' bes' ges' fes' es' des' ces'>
\tempo "Tempo III"
<ais' bis' gis' fis' eis' dis' cis'>
}
HTH,
Harm
- metronome-mark-alignment, Daniel Rosen, 2020/01/07
- Re: metronome-mark-alignment, David Nalesnik, 2020/01/08
- Re: metronome-mark-alignment, David Nalesnik, 2020/01/08
- RE: metronome-mark-alignment, Daniel Rosen, 2020/01/09
- RE: metronome-mark-alignment, Daniel Rosen, 2020/01/09
- Re: metronome-mark-alignment, Daniel Rosen, 2020/01/11
- Re: metronome-mark-alignment, David Nalesnik, 2020/01/11
- Re: metronome-mark-alignment,
Thomas Morley <=
- RE: metronome-mark-alignment, Daniel Rosen, 2020/01/12
- Re: metronome-mark-alignment, Thomas Morley, 2020/01/12
- RE: metronome-mark-alignment, Daniel Rosen, 2020/01/13
- Re: metronome-mark-alignment, David Kastrup, 2020/01/13
- Re: metronome-mark-alignment, Thomas Morley, 2020/01/14
- Re: metronome-mark-alignment, David Kastrup, 2020/01/14
- Re: metronome-mark-alignment, Thomas Morley, 2020/01/14
- Re: metronome-mark-alignment, David Kastrup, 2020/01/14
- Re: metronome-mark-alignment, Thomas Morley, 2020/01/20
- Re: metronome-mark-alignment, David Kastrup, 2020/01/20