Thanks to Jan-Peter's lalily, I now have a working solution, attached.

At 09:05 on 09 Jul 2015, Mark Knoop wrote:
>Thanks Jan-Peter,
>
>I'll take a look at this and post back if I make any progress.
>
>Cheers,
>
>Mark
>
>At 09:21 on 09 Jul 2015, Jan-Peter Voigt wrote:
>>Hi Mark,
>>
>>I know this issue and wrote and use some code which tracks the
>>current toc entry.
>>The bad thing - of course this is a good thing ;) - I am employed in
>>a full time job with absolutely no relation to lilypond, so I can't
>>say, when I am able to discover the magic ...
>>
>>Just for completenes - I don't think this uncommented chaos is
>>readable ;) In line 217 in the default paper-definition, I call the
>>property #'toc:current :
>>https://github.com/jpvoigt/lalily/blob/master/lalily/paper.lalily-default.ly#L196
>>
>>this property is set in markup-init.scm line 153:
>>https://github.com/jpvoigt/lalily/blob/master/lalily/lalily/markup-init.scm#L131
>>
>>So, I don't expect anybody to extract this from lalily, as this might
>>be quite frustrating. But if you like, you can see, if the use of
>>lalily conceptually does, what you want. And perhaps there will be
>>times, when I am able extract this to openlilylib.
>>
>>Cheers,
>>Jan-Peter
>>
>>Am 08.07.2015 um 13:41 schrieb Mark Knoop:
>>> I'm trying to include the title of the current movement in the page
>>> header. This works if I use bookparts to seperate the movements, but
>>> not by setting header:piece in a score block. I don't want to use
>>> bookparts as I don't want pagebreaks between movements.
>>>
>>> Any ideas on how to achieve this?
>>>
>>> \version "2.19.22"
>>>
>>> \header {
>>>    title = "My Piece"
>>>    composer = "Me"
>>>    tagline = ##f
>>>    % piece only prints in header if set here or in bookpart header
>>>    piece = "Global Piece"
>>> }
>>>
>>> \paper {
>>>    oddHeaderMarkup = \markup
>>>    \fill-line {
>>>      \on-the-fly #not-part-first-page \fromproperty #'header:piece
>>>      \on-the-fly #not-part-first-page \fromproperty #'header:title
>>>      \on-the-fly #print-page-number-check-first
>>>        \fromproperty #'page:page-number-string
>>>    }
>>>    evenHeaderMarkup = \oddHeaderMarkup
>>> }
>>>
>>> \book {
>>>    \bookpart {
>>>      % piece only prints in header if set here or in top-level
>>> header \header { piece = "Part 1" }
>>>      \score {
>>>        % setting piece here has no effect
>>>        \header { piece = "Movement 1" }
>>>        \repeat unfold 400 c'1
>>>      }
>>>      \score {
>>>        % setting piece here has no effect
>>>        \header { piece = "Movement 2" }
>>>        \repeat unfold 400 d'1
>>>      }
>>>    }
>>>    \bookpart {
>>>      \score {
>>>        % setting piece here has no effect,
>>>        % even without a bookpart level header
>>>        \header { piece = "Movement 3" }
>>>        \repeat unfold 400 e'1
>>>      }
>>>    }
>>> }
>>>
>>
>>
>>_______________________________________________
>>lilypond-user mailing list
>>lilypond-user@gnu.org
>>https://lists.gnu.org/mailman/listinfo/lilypond-user
>
>
>
>




-- 
Mark Knoop
\version "2.19.22"

% Scheme functions ripped from https://github.com/jpvoigt/lalily
% Thanks to Jan-Peter Voigt

#(define-public (register-markup-producer name proc) #f)
#(define-public (get-markup-producer name) #f)

#(let ((table (list)))
  (set! register-markup-producer (lambda (name proc)
                                   (set! table (assoc-set! table name proc))))
  (set! get-markup-producer (lambda (name)
                              (assoc-get name table))))

#(define-markup-command (fromproperties layout props arg)(list?)
  (let ((mup (get-markup-producer fromproperties-markup)))
       (interpret-markup layout props (mup layout props (list arg)))))

#(register-markup-producer fromproperties-markup (lambda (layout props args)
  (let ((ret (markup)))
       (for-each (lambda (sym)(let ((val (chain-assoc-get sym props)))
                              (if (and (or (string? val)(markup? val))
                                  (> (string-length (markup->string val)) 0))
                                (set! ret val))))
                 (reverse (car args)))
       ret)))

#(define-markup-command (execMarkup layout props proc)
                        (procedure?)
  (let ((m (proc layout props)))
    (cond ((ly:stencil? m) m)
          ((markup? m) (interpret-markup layout props m))
          (else (interpret-markup layout props (markup (format "~A" m)))))))

#(define-markup-command (delayed layout props mup)
                        (markup?)
  (let* ((line-part (chain-assoc-get 'line-part props 1))
         (line-width (* (ly:output-def-lookup layout 'line-width) line-part))
         (gauge-stencil (interpret-markup layout props mup)) ; (markup #:super "*" "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜß" )))
         (x-ext (ly:stencil-extent gauge-stencil X))
         (y-ext (ly:stencil-extent gauge-stencil Y)))
        (ly:make-stencil
          `(delay-stencil-evaluation
            ,(delay (ly:stencil-expr

                     (let* ((table (ly:output-def-lookup layout 'label-page-table))
                            (cur-page 0)
                            (current-toc (markup)))
                           (set! cur-page (chain-assoc-get 'page:page-number props -1))
                           (for-each (lambda (toc)
                                             (let ((label (car toc))
                                                   (text (cdr toc)))
                                                  (let ((label-page (and (list? table) (assoc label table))))
                                                       ; I want the current toc item at the *start* of the page, not the end
                                                       ; so change >= to >
                                                       ;(if (and label-page (>= cur-page (cdr label-page)))
                                                       (if (and label-page (> cur-page (cdr label-page)))
                                                           (set! current-toc (markup->string text #f layout props))))
                                             )
                                     ) (toc-items))
                           (interpret-markup layout (cons (list (cons 'toc:current current-toc)) props) mup)
                     )
          )))
          x-ext y-ext)))

\header {
  title = "My Piece"
  composer = "Me"
  tagline = ##f
}

\paper {
  titleHeaderMarkup = \markup \execMarkup #(lambda (layout props)
                                             (let* ((mtitle (chain-assoc-get 'header:title props))
                                                    (stitle (if (markup? mtitle) (string-trim-both (markup->string mtitle)) ""))
                                                    (mtoc (chain-assoc-get 'toc:current props))
                                                    (stoc (if (markup? mtoc) (string-trim-both (markup->string mtoc)) ""))
                                                    (mlist (list)))
                                               (if (and (> (string-length stoc) 0) (not (string=? stitle stoc)))
                                                   (set! mlist `(,@mlist ,@(if (> (length mlist) 0) (list ", ")(list)) ,mtoc)))
                                               (make-line-markup mlist)))
  oddHeaderMarkup = \markup \delayed \fill-line {
    \on-the-fly #not-part-first-page \fromproperty #'header:title
    \on-the-fly #not-part-first-page \execMarkup #(lambda (layout props)
                  (ly:output-def-lookup layout 'titleHeaderMarkup
                                               (markup #:fromproperties '(toc:current))))
    \on-the-fly #print-page-number-check-first \fromproperty #'page:page-number-string
  }
  evenHeaderMarkup = \oddHeaderMarkup
}

\book {
  \tocItem \markup "Movement 1"
  \score {
    \header { piece = "Movement 1" }
    \repeat unfold 400 c'1
  }
  \tocItem \markup "Movement 2"
  \score {
    \header { piece = "Movement 2" }
    \repeat unfold 400 d'1
  }
  \tocItem \markup "Movement 3"
  \score {
    \header { piece = "Movement 3" }
    \repeat unfold 400 e'1
  }
}

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

Reply via email to