[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: storing and manipulating multi-chunk texts
From: |
Thomas Morley |
Subject: |
Re: storing and manipulating multi-chunk texts |
Date: |
Fri, 28 Feb 2014 00:51:04 +0100 |
2014-02-27 2:21 GMT+01:00 Kieren MacMillan <address@hidden>:
> Hi David (et al.),
>
> This is both amazingly embarassing and incredibly encouraging...
>
> When I wrote
>
>>> I'd rather do something like
>>> title = #'(Two Ukrainian Courting Tunes:" "A Minuet & Scherzo")
>>> and then be able to say
>>> \markup \one-line \title
>>> \markup \multi-line \title
>
> the first line was intended to be pseudo-code (even ignoring, for the moment,
> the actual unintended non-pseudo-mistake of excluding the opening quotes).
>
> Firstly, I didn't think my list-or-pair-or-whatever was legal code in any
> language, never mind Lily-friendly Scheme. Secondly, I had no idea that
> functions I use every day in Lily code -- e.g., \line and \center-column --
> could be applied to a Scheme list-or-pair-or-whatever. Thirdly, I certainly
> had no idea that they would do *EXACTLY* what I was asking for. =)
>
> 1. Thank you David for your helpful answer. I guess it really *was* a
> "softball", and I didn't know it!
> 2. Lilypond continues to amaze and impress me.
>
> Now the next wrinkle... It doesn't work "out of the box" as I had hoped:
>
> \version "2.19"
> \language "english"
>
> \paper {
> bookTitleMarkup = \markup \fill-line \abs-fontsize #24 \override
> #'(baseline-skip . 2.25) \center-column \fromproperty #'header:title
> oddHeaderMarkup = \markup \abs-fontsize #12 \line \fromproperty
> #'header:title
> }
>
> \header {
> title = #'("Part one" "Part two")
> }
>
> \score { << \new Staff { R1 } >> }
>
> What do I need to fix here?
>
> Thanks!
> Kieren.
Hi,
below some hackery.
Though, I'm not convinced about it! Basically it's an extended
\fromproperty accepting a markuplist, rebuilding \line and the
column-commands (\right-column, \center-column etc)
Following this direction would mean to rewrite every
markuplist-command inside \fromproperty.
Not very attractive. I think it's the wrong way.
At least it works for now:
\version "2.19.1"
%% c/p from define-markup-commands.scm
#(define (general-column align-dir baseline mols)
"Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
(let* ((aligned-mols
(map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
(stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
(stacked-extent (ly:stencil-extent stacked-stencil X)))
(ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
#(define-markup-command (fromproperties layout props symbol)
(symbol?)
#:category other
#:properties ((align-dir #f)
(word-space)
(baseline-skip))
"Read the @var{symbol} from property settings, and produce a stencil
from the markup or markuplist contained within.
If @var{align-dir} is set @code{#f} the stencil is one line. Setting
@var{align-dir} to a number will output a column, vertically aligned according
to @var{align-dir}.
If @var{symbol} is not defined, it returns an empty markup.
"
(let ((m (chain-assoc-get symbol props))
;; prevent infinite loops by clearing the interpreted property:
(new-props
(cons (list (cons symbol `(,property-recursive-markup ,symbol)))
props)))
(cond ((markup? m)
(interpret-markup layout new-props m))
((markup-list? m)
(let* ((stencils (interpret-markup-list layout new-props m)))
(cond (align-dir (general-column align-dir baseline-skip stencils))
(else (stack-stencil-line word-space stencils)))))
(else empty-stencil))))
\paper {
bookTitleMarkup =
\markup \column {
\fill-line {
\abs-fontsize #24
\override #'(baseline-skip . 2.25)
\override #'(align-dir . 0)
\fromproperties #'header:title
}
\fill-line {
\abs-fontsize #12
\override #'(baseline-skip . 2.25)
\override #'(align-dir . -1)
\fromproperties #'header:meter
\null
}
}
oddHeaderMarkup =
\markup
\column {
\fill-line {
\abs-fontsize #12
\fromproperties #'header:title
}
\fill-line {
\abs-fontsize #8
\fromproperties #'header:meter
}
}
}
\header {
title = #'("Two Ukrainian Courting Tunes:" "A Minuet & Scherzo")
meter = \markuplist {
\rotate #3 "Crazy"
\rotate #-3 "Whatever"
}
}
\score { << \new Staff { R1 } >> }
Cheers,
Harm