Re: Header fields in custom footer

2016-12-08 Thread Noeck
Thanks Harm,

that works. However, I did not manage to apply string operations to the
text (arg) part of the \my-with-url function.
I tried another proc (called procc) with another test-proc function but
I don't know how to

If it's quickly done, I am happy to see how. But I fear, I will go back
to a handwritten footer as it is mostly the same for all my files.
I just liked the idea of separating style and information. And I did not
know that it was that complicated.

Best,
Joram

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


Re: Header fields in custom footer

2016-12-05 Thread Thomas Morley
2016-12-02 0:43 GMT+01:00 Noeck :
> Hi Harm,
>
> hm, I am still not getting what I want. I fear that's what you meant by
> the limitations concerning the $defaultheader.

Yep.
\headers can be set at very different levels, I simply don't know how
to catch others than the first instance at toplevel.

> Can this be solved?

Falling back to markup-commands may work. See below.
Though, I fear you'll have no difficulties to get it broken. Regard it
as a first sketch.

#(define-markup-command (my-with-url layout props url arg)
  (markup? markup?)
  #:properties ((proc '()))
  (let* ((stil (interpret-markup layout props arg))
 (xextent (ly:stencil-extent stil X))
 (yextent (ly:stencil-extent stil Y))
 (old-expr (ly:stencil-expr stil))
 (possible-url-string (chain-assoc-get (last url) props))
 ;; be aware: not recursing!!!
 (url-string
   (if (string? possible-url-string)
   (if (null? proc)
   possible-url-string
   (proc possible-url-string))
   ""))
 (url-expr
   (list 'url-link url-string `(quote ,xextent) `(quote ,yextent
(ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))

#(define test-proc
  (lambda (strg)
(if (string? strg)
(format #f "https://creativecommons.org/licenses/~a/4.0/";
(substring strg 3))
strg)))

\header {
  composer = "Mozart"
  maintainer = "NameName"
  maintainerWeb = "http://example.com";
  license = "cc-by-sa"
}

\paper {
  oddFooterMarkup =
  \markup \column {
\fill-line {
  \on-the-fly #first-page
\line {
  "By"
  \my-with-url
\fromproperty #'header:maintainerWeb
\fromproperty #'header:maintainer
  "-"
  \override #`(proc . ,test-proc)
  \my-with-url
   \fromproperty #'header:license
   \line { "License:" \smaller #(module-ref $defaultheader 'license) }
}
}

\fill-line {
  %% Tagline header field only on last page in the book.
  \on-the-fly #last-page \fromproperty #'header:tagline
}
  }
}

{ a1 \pageBreak a \pageBreak a }

Cheers,
  Harm

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


Re: Header fields in custom footer

2016-12-01 Thread Noeck
\fromproperty #'header:author
respects the local \header block but I cannot use it in scheme, right?

Joram

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


Re: Header fields in custom footer

2016-12-01 Thread Noeck
Hi Harm,

hm, I am still not getting what I want. I fear that's what you meant by
the limitations concerning the $defaultheader.

This is a minimal example to show the problem:

\version "2.19.50"

%%% from included file
\header {
  author = "default author"  % just in case there is no author later
}
\paper {
  oddFooterMarkup =
  \markup \column {
\fill-line {
  \on-the-fly #first-page
\concat {
#(ly:modules-lookup (list $defaultheader) 'author "")

%%% end of included file

\header {
  author = "real author"
  % this is the author that should appear in the footer
}

{ a }


Can this be solved?

Joram

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


Re: Header fields in custom footer

2016-12-01 Thread Noeck
Hi Harm,

Am 01.12.2016 um 11:00 schrieb Thomas Morley:
> (ly:modules-lookup (list $defaultheader) 'foo "xy")

Thanks a lot. That's it.

Joram

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


Re: Header fields in custom footer

2016-12-01 Thread Thomas Morley
2016-11-30 23:31 GMT+01:00 Noeck :
> Hi,
>
> I have one more question on this topic:
>
> How can I check whether a header field is present at all?
> (Or my main goal: how can I avoid that the code fails?)
>
> This works:
> \version "2.19.50"
> \header {
>   title = "ABC"
> }
> \paper {
>   oddFooterMarkup = #(module-ref $defaultheader 'title)
> }
> { a }
>
>
> This does not for obvious reasons:
> oddFooterMarkup = #(module-ref $defaultheader 'maintainer)
>
>
> Instead of putting all possible headers in a default header like
> maintainer = ##f
> I would like to check the presence, sth like this pseudocode:
>
> oddFooterMarkup = #(if (in? 'maintainer $defaultheader)
>(module-ref $defaultheader 'maintainer)
>"")
>
> Cheers,
> Joram
>
>

Hi Joram,

we have ly:modules-lookup with a possible optional argument. Resulting in:

(ly:modules-lookup (list $defaultheader) 'foo "xy")

If foo is found its value is returned otherwise "xy"

HTH,
  Harm

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


Re: Header fields in custom footer

2016-11-30 Thread Noeck
Hi,

I have one more question on this topic:

How can I check whether a header field is present at all?
(Or my main goal: how can I avoid that the code fails?)

This works:
\version "2.19.50"
\header {
  title = "ABC"
}
\paper {
  oddFooterMarkup = #(module-ref $defaultheader 'title)
}
{ a }


This does not for obvious reasons:
oddFooterMarkup = #(module-ref $defaultheader 'maintainer)


Instead of putting all possible headers in a default header like
maintainer = ##f
I would like to check the presence, sth like this pseudocode:

oddFooterMarkup = #(if (in? 'maintainer $defaultheader)
   (module-ref $defaultheader 'maintainer)
   "")

Cheers,
Joram

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


Re: Header fields in custom footer

2016-11-26 Thread Noeck
Hi Harm,

thanks a lot for this solution and your patience! That's what I wanted.
And the discussion told me more about how to ask.

Cheers,
Joram

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


Re: Header fields in custom footer

2016-11-26 Thread Thomas Morley
2016-11-26 23:17 GMT+01:00 Noeck :
> Hi,
>
> your code works pretty well. Thanks, Harm!
>
> The following questions are left:
>
> (1) How to center the whole markup? \center-column does not work.
> It should be easy, but perhaps it's too late.

Use fill-line

> (2) The footer should appear only on the first page, the last page
> should be different, all other pages should be empty.
> Like \on-the-fly #first-page and #last-page which I could not use
> successfully

You had them in the wrong order

> (3) How can I use header fields for the url in \with-url?
> Your clever functions couldn't help me. Probably such a function
> should return a string instead of a markup?

A markup-comand will _always_ return a stencil, afaik, never a string.


As long as you are using only strings in the header and the header is
at _toplevel_ the following may work

\header {
  composer = "Mozart"
  maintainer = "Name"
  maintainerWeb = "http://example.com";
  license = "cc-by-sa"
}

\paper {
  oddFooterMarkup =
  \markup \column {
\fill-line {
  \on-the-fly #first-page
\line {
  "By"
  \with-url
#(module-ref $defaultheader 'maintainerWeb)
#(module-ref $defaultheader 'maintainer)
  "-"
  \with-url
#(format #f
  "https://creativecommons.org/licenses/~a/4.0/";
  (substring (module-ref $defaultheader 'license) 3))
   \line { "License:" \smaller #(module-ref $defaultheader 'license) }
}
}

\fill-line {
  %% Tagline header field only on last page in the book.
  \on-the-fly #last-page \fromproperty #'header:tagline
}
  }
}

{ a1 \pageBreak a \pageBreak a }


Cheers,
  Harm

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


Re: Header fields in custom footer

2016-11-26 Thread Noeck
Hi,

your code works pretty well. Thanks, Harm!

The following questions are left:

(1) How to center the whole markup? \center-column does not work.
It should be easy, but perhaps it's too late.

(2) The footer should appear only on the first page, the last page
should be different, all other pages should be empty.
Like \on-the-fly #first-page and #last-page which I could not use
successfully

(3) How can I use header fields for the url in \with-url?
Your clever functions couldn't help me. Probably such a function
should return a string instead of a markup?

Thanks again!
Joram


Here is what I have got so far:

%

\version "2.19.22"

#(define-markup-command (fillwith layout props arg)(symbol?)
  #:properties ((proc '()))
  (let* ((target (chain-assoc-get arg props))
 (target-string (markup->string target))
 (output
   (if (or (null? proc) (string-null? target-string))
   target
   (proc target-string

(if (markup? output)
;; prevent infinite loops by clearing the interpreted property:
(interpret-markup
  layout
  (cons
(list (cons symbol `(,property-recursive-markup ,symbol)))
props)
  output)
empty-stencil)))

#(define (transform-web)
  (lambda (strg)
(if (string? strg)
(format #f "- ~a" (substring strg 7))
strg)))

#(define (transform-license)
   (lambda (strg)
 (if (string? strg)
 (format #f "CC ~a"
   (string-upcase (substring strg 3))


\header {
  composer = "Mozart"
  maintainer = "Name"
  maintainerWeb = "http://example.com";
  license = "cc-by-sa"
}


\paper {
  % (1) how to center the whole markup? \center-column does not work:
  % oddFooterMarkup = \markup \center-column \line {
  % (2) it should appear only on the first page
  % the last page should be different
  % all other pages should be empty
  % oddFooterMarkup = \on-the-fly #first-page \markup \line {
  % does not work

  oddFooterMarkup = \markup \line{
"By"
\with-url
  #"http://example.com";   % (3a) how to use maintainerWeb here?
  \line {
\fillwith #'header:maintainer
\override #`(proc . ,(transform-web)) \fillwith
#'header:maintainerWeb
  }
"-"
\with-url
  #(format
"https://creativecommons.org/licenses/~a/4.0/";
(substring "cc-by-sa" 3))  % (3b) how to use license here?
 \line {
   "License:" \smaller
   \override #`(proc . ,(transform-license)) \fillwith #'header:license
 }
  }
}


{ a1 \pageBreak a }

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


Re: Header fields in custom footer

2016-11-26 Thread Noeck
Hi Andrew, Harm, all,

thanks for your help. I tried to post a minimal example, but it looks
like it was too minimal to show my intent. And of course, the LSR
snippet works and does what says. I just could solve my issue with it -
just passing my expression to the function did not solve it.

So here is the full thing I want to achieve:


\version "2.19.50"

\header {
  composer = "Mozart"
  maintainer = "Name"
  maintainerWeb = "http://example.com";
  license = "cc-by-sa"
}

\paper {
  oddFooterMarkup = \markup \line{
\with-url
  #"http://example.com";
  #(format "By ~a - ~a"
"Name"
(substring "http://example.com"; 7))
"-"
\with-url
  #(format "https://creativecommons.org/licenses/~a/4.0/";
(substring "cc-by-sa" 3))
  % putting the \markupWithHeader function here does not work
  #(format "License: CC ~a"
(string-upcase (substring "cc-by-sa" 3)))
  }
}

{ a }
%%
This code shows the footer I want to have, but whenever I wrote "Name",
"http://example.com"; or "cc-by-sa", I would like the corresponding
header fields to be used.

In the end, I would improve it (check whether the license starts with
'cc-', replace substrings rather than cutting out part of them, etc.).
But that would all be possible once I understood how to combine
\fromproperty, \with-url and scheme functions for this purpose.


Your code, Harm, looks promising. I tried to adapt it and put several
return values of \test into a modified test-proc function. But
apparently the lambda function does not accept more than one argument:
Wrong number of arguments to #

Now I try to write several test-proc like functions, one for each call
of a header, and combine them with lilypond later as you did. Might be a
way. I am not sure yet, whether that amount of code is resonable in
contrast to the fact that I saved typing the url etc. twice.

The problem how to put the maintainerWeb field in the first argument of
\with-url remains.

Thanks,
Joram

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


Re: Header fields in custom footer

2016-11-26 Thread Thomas Morley
2016-11-26 1:18 GMT+01:00 Andrew Bernard :
> Hi Joram,
>
> Post an example of what is not working. The code I sent works fine, but I
> can't quite understand what you mean therefore.
>
> Andrew
>
>
> -Original Message-
> From: lilypond-user
> [mailto:lilypond-user-bounces+andrew.bernard=gmail@gnu.org] On Behalf Of
> Noeck
> Sent: Saturday, 26 November 2016 6:59 AM
> To: lilypond-user@gnu.org
> Subject: Re: Header fields in custom footer
>
> Hi,
>
> I still need help. I am not able to get this working. Either it fails (does
> not compile) or it does not print the header fields.
>
> This back and forth between LP and Scheme does not help either. I am not
> sure if my goal is reachable:
> oddFooterMarkup would be a scheme function and the arguments to this
> function would be filled with \fromproperty. But the evaluation is taking
> place in the end on the oddFooterMarkup so the scheme function would have to
> transparently pass the header fields.



Hi Joram,

I second Andrew's call for an example.
Would be nice do know more exactly what you're trying to achieve.
Please post some example you would like to see working, even if it
fails currnetly.

That said, probably the code below may be a starting point.
It's only a proof-of-concept based on fromproperty-markup. Right now
it's likely easy to break.

Anyway:

\version "2.19.51"

#(define-markup-command (test layout props arg)(symbol?)
  #:properties ((proc '()))
  (let* ((target (chain-assoc-get arg props))
 (target-string (markup->string target))
 (output
   (if (or (null? proc) (string-null? target-string))
   target
   (proc target-string

(if (markup? output)
;; prevent infinite loops by clearing the interpreted property:
(interpret-markup
  layout
  (cons
(list (cons symbol `(,property-recursive-markup ,symbol))) props)
  output)
empty-stencil)))

#(define (test-proc xy)
  (lambda (strg)
(if (string? strg)
(format #f "My ~a is: ~a" xy (string-upcase strg))
strg)))

\paper {
  oddFooterMarkup =
  \markup \column \box {
\override #`(proc . ,(test-proc "title")) \test #'header:title
\override #`(proc . ,(test-proc "subtitle")) \test #'header:subtitle
\override #`(proc . ,(test-proc "subsubtitle")) \test
#'header:subsubtitle
\override #`(proc . ,(test-proc "composer")) \test #'header:composer
\override #`(proc . ,(test-proc "meter")) \test #'header:meter
  }
}

\header {
composer = \markup { "xxyyzz" "foo" }
title = "title"
meter = \markup \rounded-box { "meter" \musicglyph #"scripts.segno" }
subtitle = \markup \draw-line #'(10 . 0)
subsubtitle = \markup \with-color #red"subsubtitle"
}

\markup \null



Cheers,
  Harm

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


RE: Header fields in custom footer

2016-11-25 Thread Andrew Bernard
Hi Joram,

Post an example of what is not working. The code I sent works fine, but I
can't quite understand what you mean therefore.

Andrew


-Original Message-
From: lilypond-user
[mailto:lilypond-user-bounces+andrew.bernard=gmail@gnu.org] On Behalf Of
Noeck
Sent: Saturday, 26 November 2016 6:59 AM
To: lilypond-user@gnu.org
Subject: Re: Header fields in custom footer

Hi,

I still need help. I am not able to get this working. Either it fails (does
not compile) or it does not print the header fields.

This back and forth between LP and Scheme does not help either. I am not
sure if my goal is reachable:
oddFooterMarkup would be a scheme function and the arguments to this
function would be filled with \fromproperty. But the evaluation is taking
place in the end on the oddFooterMarkup so the scheme function would have to
transparently pass the header fields.




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


Re: Header fields in custom footer

2016-11-25 Thread Noeck
Hi,

I still need help. I am not able to get this working. Either it fails
(does not compile) or it does not print the header fields.

This back and forth between LP and Scheme does not help either. I am not
sure if my goal is reachable:
oddFooterMarkup would be a scheme function and the arguments to this
function would be filled with \fromproperty. But the evaluation is
taking place in the end on the oddFooterMarkup so the scheme function
would have to transparently pass the header fields.

Any further advice is appreciated.

Cheers,
Joram

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


Re: Header fields in custom footer

2016-11-25 Thread Noeck
Hi Andrew,

I was not convinced because
a) I tried the function around the markup and it did not work
b) this works without the function:
oddFooterMarkup = \markup \fromproperty #'header:composer

But I guess in both cases the fields are filled in the end, but I need
to fill them inside the scheme expression. So I will have another look
this evening.

Cheers,
Joram

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


RE: Header fields in custom footer

2016-11-24 Thread Andrew Bernard
Hi Joram,

As mentioned in my previous post, you have to use the function in LSR 467,
or something similar. This function makes header variables available outside
the header block. If you don't use it, you can't easily see them.

Andrew

== snip

\version "2.19.51"

#(define-markup-command (markupWithHeader layout props markup) (markup?)
   "Interpret the given markup with the header fields added to the props.
This way, one can re-use the same functions (using fromproperty 
#'header:field) in the header block and as top-level markup."
   (let* (
   ;; TODO: If we are inside a score, add the score's local header
block, too!
   ;; Currently, I only use the global header block, stored in
$defaultheader
   (scopes (list $defaultheader))
   (alists (map ly:module->alist scopes))
   (prefixed-alist
(map (lambda (alist)
   (map (lambda (entry)
  (cons
   (string->symbol (string-append "header:"
 (symbol->string
  (car entry
   (cdr entry)))
 alist))
  alists))
   (props (append prefixed-alist
props
(layout-extract-page-properties layout
 (interpret-markup layout props markup)))

\header {
  composer = "Mozart"
}

\paper {
  oddFooterMarkup = \markup \markupWithHeader { "Composer: " \fromproperty
#'header:composer }
}

{
  c'4
}

== snip



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


Re: Header fields in custom footer

2016-11-24 Thread Noeck
Dear Andrew,

thanks for your reply. But I think that's not the point. My example was
too minimal as I assumed that it does not matter if I put it in a
\markup or in the footer properties of the paper block.

So my question remains: How can I use string manipulations and header
properties in my footer markup?

A better minimal example is this:


\version "2.19.50"

\header {
  composer = "Mozart"
}

\paper {
  oddFooterMarkup = \markup #(format "Composer: ~a"
(markup->string (markup (#:fromproperty 'header:composer
}

It compiles but the composer is not shown.


Cheers,
Joram

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


RE: Header fields in custom footer

2016-11-22 Thread Andrew Bernard
Hi Joram,

I think this function is what you require:

http://lsr.di.unimi.it/LSR/Item?id=467

Andrew



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


Re: Header fields in custom footer

2016-11-22 Thread Noeck
> How can I use \fromproperty in scheme? Because I want to do some string
> operations before inserting the field in the footer.

I thought I was close but obviously not:

\header {
  title = "Title"
}

\markup #(format "a ~a z" (markup->string (markup #:fromproperty
'header:title)))

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