Hymns and justified lyrics

2015-04-09 Thread David B. Stocker

Hello LilyPonders,

I have a client who is working on a hymnal, and they would like for the 
beginning of the lines of verses to be left justified. The best way I 
can see to do this, from a visual standpoint, is to make the longest 
syllable on the first note of each line centered like it normally is, 
and then left-align all the others to that syllable.


Please see the attached minimal example.

First, I want to know whether it is possible to automate this behavior 
with LilyPond (I think it is).


And next, I'd like it if someone would point me in the direction of how 
to achieve this. My sense is that it is going to require some 
function-writing. I'm not a programmer (at all, really), but I'm not 
opposed to learning how to do this. Actually, I've been meaning to learn 
how to extend and modify some aspects of LilyPond for my own projects 
and doing so for a client-project is the best excuse I might have for 
jumping in.


Also, it's something that may be useful for other users as well, so at 
the very least it should be included in the LSR, and maybe made 
available for everyone in a future release.


I'm also open to collaboration on this, if anyone else is interested.

So, my hunch is that I'm going to write a function that queries the 
value of the left edge of the centered syllable in one verse, and then 
calculates the amount of offset to apply to the syllables at the same 
point in other verses on a case-by-case basis.


1) where can I start with learning this sort of tinkering, and 2) does 
anyone have other functions that behave in a similar way (fetching a 
value, making a calculation, and then applying it somewhere else) that I 
could study to figure out how I might do this?


Again, I have no idea, so let me know if I'm way off base here.

Thanks,

David

\version "2.18.2"


\paper {

%line-width = 10\in

indent = 0\in

ragged-right = ##t

}


%% Default LilyPond beginning-of-line lyric alignment and spacing


\score {

\new Staff <<

\new Voice = "hymn" {

\relative c'' {

\partial 2 a4 a \bar "|"

}

}

\new Lyrics \lyricsto "hymn" {

with my

}

\new Lyrics \lyricsto "hymn" {

through the

}

\new Lyrics \lyricsto "hymn" {

praise the

}

\new Lyrics \lyricsto "hymn" {

bless -- ed

}

>>

}


%% Left justifying the first syllable in each verse results in funky 
note spacing



syllableLeft = { \once \override LyricText.self-alignment-X = #LEFT }


\score {

\new Staff <<

\new Voice = "hymn" {

\relative c'' {

\partial 2 a4 a \bar "|"

}

}

\new Lyrics \lyricsto "hymn" {

\syllableLeft with my

}

\new Lyrics \lyricsto "hymn" {

\syllableLeft through the

}

\new Lyrics \lyricsto "hymn" {

\syllableLeft praise the

}

\new Lyrics \lyricsto "hymn" {

\syllableLeft bless -- ed

}

>>

}


%% Left justifying syllables to the longest syllable by hand is 
time-consuming, inaccurate, and not persistent


%% if a different lyric font is chosen later


\score {

\new Staff <<

\new Voice = "hymn" {

\relative c'' {

\partial 2 a4 a \bar "|"

}

}

\new Lyrics \lyricsto "hymn" {

\once \override LyricText.self-alignment-X = #1 with my

}

\new Lyrics \lyricsto "hymn" {

through the

}

\new Lyrics \lyricsto "hymn" {

\once \override LyricText.self-alignment-X = #0.35 praise the

}

\new Lyrics \lyricsto "hymn" {

\once \override LyricText.self-alignment-X = #0.8 bless -- ed

}

>>

}




\version "2.18.2"

\paper {
  %line-width = 10\in
  indent = 0\in
  ragged-right = ##t
}

%% Default LilyPond beginning-of-line lyric alignment and spacing

\score {
  \new Staff <<
\new Voice = "hymn" {
  \relative c'' {
\partial 2 a4 a \bar "|"
  }
}
\new Lyrics \lyricsto "hymn" {
  with my
}
\new Lyrics \lyricsto "hymn" {
  through the
}
\new Lyrics \lyricsto "hymn" {
  praise the
}
\new Lyrics \lyricsto "hymn" {
  bless -- ed
}
  >>
}

%% Left justifying the first syllable in each verse results in funky note spacing

syllableLeft = { \once \override LyricText.self-alignment-X = #LEFT }

\score {
  \new Staff <<
\new Voice = "hymn" {
  \relative c'' {
\partial 2 a4 a \bar "|"
  }
}
\new Lyrics \lyricsto "hymn" {
  \syllableLeft with my
}
\new Lyrics \lyricsto "hymn" {
  \syllableLeft through the
}
\new Lyrics \lyricsto "hymn" {
  \syllableLeft praise the
}
\new Lyrics \lyricsto "hymn" {
  \syllableLeft bless -- ed
}
  >>
}

%% Left justifying syllables to the longest syllable by hand is time-consuming, inaccurate, and not persistent
%% if a different lyric font is chosen later

\score {
  \new Staff <<
\new Voice = "hymn" {
  \relative c'' {
\partial 2 a4 a \bar "|"
  }
}
\new Lyrics \lyricsto "hymn" {
  \once \override LyricText.self-alignment-X = #1 with my
}
\new Lyrics \lyricsto "hymn" {
  through the
}
\new Lyrics \lyricsto "hymn" {
  \once \override LyricText.self-alignment-X = #0.35 praise the
}
 

Re: Hymns and justified lyrics

2015-04-09 Thread David Nalesnik
Hi David,

On Thu, Apr 9, 2015 at 9:32 AM, David B. Stocker 
wrote:

> Hello LilyPonders,
>
> I have a client who is working on a hymnal, and they would like for the
> beginning of the lines of verses to be left justified. The best way I can
> see to do this, from a visual standpoint, is to make the longest syllable
> on the first note of each line centered like it normally is, and then
> left-align all the others to that syllable.
>
> Please see the attached minimal example.
>
> First, I want to know whether it is possible to automate this behavior
> with LilyPond (I think it is).
>
> And next, I'd like it if someone would point me in the direction of how to
> achieve this. My sense is that it is going to require some
> function-writing. I'm not a programmer (at all, really), but I'm not
> opposed to learning how to do this. Actually, I've been meaning to learn
> how to extend and modify some aspects of LilyPond for my own projects and
> doing so for a client-project is the best excuse I might have for jumping
> in.
>
> Also, it's something that may be useful for other users as well, so at the
> very least it should be included in the LSR, and maybe made available for
> everyone in a future release.
>
> I'm also open to collaboration on this, if anyone else is interested.
>
> So, my hunch is that I'm going to write a function that queries the value
> of the left edge of the centered syllable in one verse, and then calculates
> the amount of offset to apply to the syllables at the same point in other
> verses on a case-by-case basis.
>
> 1) where can I start with learning this sort of tinkering, and 2) does
> anyone have other functions that behave in a similar way (fetching a value,
> making a calculation, and then applying it somewhere else) that I could
> study to figure out how I might do this?


You can find a function here which I believe does what you want:

http://www.mail-archive.com/lilypond-user%40gnu.org/msg81870.html

It's been a while, but it looks like you add \tagIt at the line beginning,
to any of the verses,  This will center the lines based on the longest word
and left-justify, regardless of the verse to which you attach the \tagIt.

Attached is the relevant code with your example.

Of course it would be great to automate this so you wouldn't have to worry
about line breaks, and possibly that could be done here.

Hope this helps,
David

P.S.  I see the following message in the above thread:
http://www.mail-archive.com/lilypond-user%40gnu.org/msg81941.html
Possibly you could request the code from the poster.
\version "2.17.17"

%%

#(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))

  `(
(tagged ,boolean? "is this grob marked?")
(syllables ,array? "the lyric syllables at a timestep")
  ))



#(define (Lyric_text_align_engraver ctx)
"If the property 'tagged is set, collect all lyric syllables at that
timestep in the grob-array `syllables'"
  (let ((syl '()))
(make-engraver
 (acknowledgers
  ((lyric-syllable-interface trans grob source)
   (set! syl (cons grob syl
 ((stop-translation-timestep trans)
  (if (any (lambda (x) (eq? #t (ly:grob-property x 'tagged)))
   syl)
  (for-each
(lambda (x)
   (for-each
 (lambda (y)
   (ly:pointer-group-interface::add-grob x 'syllables y))
 syl))
syl))
  (set! syl '())

#(define (X-offset-callback grob)
  (let* ((target (ly:grob-object grob 'syllables))
 (target
   (if (ly:grob-array? target)
   (ly:grob-array->list target)
   '(
(if (pair? target)
(let ((longest
(car
  (sort target
(lambda (x y)
  (> (interval-length
   (ly:stencil-extent
 (grob-interpret-markup
   grob (ly:grob-property x 'text))
 X))
 (interval-length
   (ly:stencil-extent
 (grob-interpret-markup
   grob (ly:grob-property y 'text))
 X
  (if (eq? grob longest)
  ; if our grob has the longest syllable, return its default
  ; value for 'X-offset
  (ly:self-alignment-interface::aligned-on-x-parent grob)
  (ly:grob-property longest 'X-offset)))
(ly:self-alignment-interface::aligned-on-x-parent grob
 
tagIt = \once \override L

Re: Hymns and justified lyrics

2015-04-13 Thread Simon Albrecht

Am 13.04.2015 um 01:55 schrieb David B. Stocker:

David,

Thank you for this. This is exactly what I'm after.

It seems like you're a Scheme guy. Is there a learning resource you 
would recommend to a very green beginner?
I don’t know any basic tutorials for Scheme itself, but concerning Lily 
the extending manual 
 
is a point to start.
Documentation for Scheme may be found at 
 and 
 
(R5RS referring to scheme in general and the guile reference manual to 
the implementation used in LilyPond), but these offer what is probably 
the steepest learning path available.


HTH, Simon

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


Re: Hymns and justified lyrics

2015-04-13 Thread J Martin Rushton
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 13/04/15 22:44, Simon Albrecht wrote:
> Am 13.04.2015 um 01:55 schrieb David B. Stocker:
>> David,
>> 
>> Thank you for this. This is exactly what I'm after.
>> 
>> It seems like you're a Scheme guy. Is there a learning resource
>> you would recommend to a very green beginner?
> I don’t know any basic tutorials for Scheme itself, but concerning
> Lily the extending manual 
> 
>
> 
is a point to start.
> Documentation for Scheme may be found at 
>  and 
> 
>
> 
(R5RS referring to scheme in general and the guile reference manual to
> the implementation used in LilyPond), but these offer what is
> probably the steepest learning path available.
> 
> HTH, Simon
> 
There's also an introduction in Wikipedia:
https://en.wikipedia.org/wiki/Scheme_%28programming_language%29
which also lists some resources under "Further reading".  Still a
steep learning curve though!

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJVLD4RAAoJEAF3yXsqtyBlkUoQANhClvtJ+ARODglnCKnNJmMA
jGtcrRp6fKCinboc50joK7Q/lGbL0bLCoMeiIAB8hR2Ojb+Uz0FPNB7N/jAqZpZj
2O0jDJKE7itQTuT0j7w5QtsswTZrdg63GZvkjBFksfYxIGP3WRXcYi7AaIDtxKoq
+OFj7emGrw3pzUf9ivt4Tan5OfIrp3FfU0UFf7wFEFlfdCM+RMNDjkMeq+xj8wQf
U6aRp349E+/k6MhGt1P4kk3w/f2CIvwF+jsCSrPVJLEkdJqcIy971W4uprvX+9E4
n+ZeR7iss9pRlB8xDdYyjFD1yccg1q/EDoo5kF98Ecq3L2xSR1GJVWhENK0J12kN
5gzTrJjLh3wFAe+yEbm30o5tcPjgwp0/GwsbMgGaQLqYdMHt6UXIxTpODez70Ox7
3XLbGjuuuIQHLRuIey3xOBOBzaKDoI78Fll6kFIlKNnyKqwvjYCInExMjWIyEq8O
rSbxFIntj+xqsZMc6srgspObmwiDiy/xYvcs7sarYjnTOgXSTzBCxk+MIn3x2Vl8
EuXR3wGyuOWVM9K62YPJVuZ5jCrepx6yjIPJZYgX0Sibj+hvQNKqS4BL6KyCrqna
ZG+dmVKt9E4AQpDuQx4U16UZBXRLGDLdoze+5sxT79JxoZ6qGDOnkJhlTAjPpBAy
CyDVfk6FKxg5paugCQIs
=fIgE
-END PGP SIGNATURE-

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


Re: Hymns and justified lyrics

2015-04-13 Thread David Nalesnik
On Mon, Apr 13, 2015 at 4:44 PM, Simon Albrecht 
wrote:

> Am 13.04.2015 um 01:55 schrieb David B. Stocker:
>
>> David,
>>
>> Thank you for this. This is exactly what I'm after.
>>
>> It seems like you're a Scheme guy. Is there a learning resource you would
>> recommend to a very green beginner?
>>
> I don’t know any basic tutorials for Scheme itself, but concerning Lily
> the extending manual  19/Documentation/extending/scheme-tutorial> is a point to start.
> Documentation for Scheme may be found at  Documents/Standards/R5RS/> and  guile/docs/docs-1.8/guile-ref/index.html> (R5RS referring to scheme in
> general and the guile reference manual to the implementation used in
> LilyPond), but these offer what is probably the steepest learning path
> available.
>  
>

I've gotten a lot from the Extending Manual and the Guile 1.8 manual.
There's plenty to be had by searching, resources like
http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html.   There isn't
much that is specifically geared to our flavor of Scheme, but I haven't
found this to be much of an issue.

The harder part is learning the LilyPond-specific-stuff -- or at least
taking it to the level of functions such as I referred you to above.  There
is Extending and the list of Scheme functions in the Internals Reference <
http://lilypond.org/doc/v2.19/Documentation/internals/scheme-functions>.
Otherwise, what I know comes from the lists, reading code, and
experimenting A tutorial for this is ever on the TODO list.

And, or course, you can ask Scheme questions on the user list.  You'll
pretty much always get a ready answer.

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


Re: Hymns and justified lyrics

2015-04-13 Thread David Nalesnik
On Mon, Apr 13, 2015 at 5:26 PM, David Nalesnik 
wrote:

>
>
> On Mon, Apr 13, 2015 at 4:44 PM, Simon Albrecht 
> wrote:
>
>> Am 13.04.2015 um 01:55 schrieb David B. Stocker:
>>
>>> David,
>>>
>>> Thank you for this. This is exactly what I'm after.
>>>
>>> It seems like you're a Scheme guy. Is there a learning resource you
>>> would recommend to a very green beginner?
>>>
>> I don’t know any basic tutorials for Scheme itself, but concerning Lily
>> the extending manual > 19/Documentation/extending/scheme-tutorial> is a point to start.
>> Documentation for Scheme may be found at > Documents/Standards/R5RS/> and > guile/docs/docs-1.8/guile-ref/index.html> (R5RS referring to scheme in
>> general and the guile reference manual to the implementation used in
>> LilyPond), but these offer what is probably the steepest learning path
>> available.
>>  
>>
>
> I've gotten a lot from the Extending Manual and the Guile 1.8 manual.
> There's plenty to be had by searching, resources like
> http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html.   There
> isn't much that is specifically geared to our flavor of Scheme, but I
> haven't found this to be much of an issue.
>
>
Though I must underscore that you need to be ever on the lookout for
functions that aren't in Guile (as I see there are in the "Teach yourself
Scheme in fixnum days..." link above.  That's why I've always had the Guile
1.8 manual (not 2x) at the ready and have gotten most info from there after
becoming reasonably proficient.

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