Nov 12, 2014

Piano RH/LH Brackets

Sometimes when I'm playing the piano or organ (especially the organ, since I'm not that great with the pedals yet), I need to mark that a high note in the lower stave should be played with the right hand. Here's an example of this situation:
For me, the indicated note is easily reachable with the right hand. So, how do I mark it that way? Well, in the Notation Reference, in the Fingering Instructions section, I found an example of a custom fingering markup. Normally, if you want to indicate that a note be played with a particular finger you use the "-N" syntax where N=1, 2, etc., and you'd get something like this:

\relative c'' { 
  c4-1 d-2 f-4 e-3 
}
Pretty simple. If you need a more complex instruction (like a finger-substitution), we can use the built-in "\finger" macro that allows us to put in a "\markup" object:

\relative c'' {
  c4-1 d-2 f\finger \markup \tied-lyric #"4~3" c\finger "2 - 3"
}
Nice! Now, we take this a step further. I decided to create a bracket (or half-bracket, really) using some simple post-script commands within a "\markup" object:
lhMark = \markup { 
  \path #0.1 #'((moveto -1 0)(rlineto 0 1.5)(rlineto 0.5 0))
}
rhMark = \markup { 
  \path #0.1 #'((moveto -1 0)(rlineto 0 -1.5)(rlineto 0.5 0))
}
This is in the shape of an "L" and is designed to go on the LEFT side of the notehead. However, the default position is ABOVE the notehead (or chord, if it's part of one). So, in order to place it NEXT to the note, I need to change the "fingeringOrientations" property, like so:
\set fingeringOrientations = #'(left)
Putting these together, we get something like this:
\relative c {
  \clef bass
  \set fingeringOrientations = #'(left)
  <f, a'\finger \rhMark>4
}

Let's take this a step further. Suppose I now want to indicate "R.H." next to the bracket. This can be done pretty easily by using the "\concat" function within the "\markup" object, which concatenates two expressions, like this:
lhMarkText = \markup { 
  \concat {
    \override #'(font-encoding . latin1) \italic "L.H. " 
    \path #0.1 #'((moveto 0 -0.5)(rlineto 0 1.5)(rlineto 0.5 0))
  }
}
rhMarkText = \markup { 
  \concat {
    \override #'(font-encoding . latin1) \italic "R.H. " 
    \path #0.1 #'((moveto 0 1)(rlineto 0 -1.5)(rlineto 0.5 0))
  }
}

\relative c {
  \clef bass
  \set fingeringOrientations = #'(left)
  <f, a'\finger \rhMarkText>4
}
This can get even more involved if we need to actually bracket a section of a chord, but following the snippets above, we can do crazy things like this:
rhBracket = \markup { 
  \concat {
    \path #0.1 #'((moveto 0 -1.75)(rlineto 0.5 0)(rlineto 0 4.25)(rlineto -0.5 0))
    \override #'(font-encoding . latin1) \italic " RH" 
  }
}

lhBracket = \markup { 
  \concat {
    \path #0.1 #'((moveto 0 0.75)(rlineto 0.5 0)(rlineto 0 -3.25)(rlineto -0.5 0))
    \override #'(font-encoding . latin1) \lower #1.25 \italic " LH" 
  }
}

\new Staff \relative c, {
  \clef bass
  \set fingeringOrientations = #'(right)
  <e f bes\finger \lhBracket e\finger \rhBracket g b! dis>1\arpeggio 
}
There you go, all you piano/organ players! You may have to play around with the numbers (since there isn't a dedicated function to do this yet), but without too much effort, you should be able to get the job done.

If you are trying to do this and can't figure it out for your situation, send me an email.

Nov 6, 2014

Long, Broken (De-)Crescendo Text

Have you ever wondered how to create a dynamic marking like this:



I know I have, and as I was looking through the Chopin score above, I noticed this marking again, and having never tried to do it in LilyPond, I thought I'd figure it out.

In the LilyPond Notation Reference, under the Dynamics Section there's a subsection called "Changing text and spanner styles for text dynamics". In the example, it shows how you can customize the crescendo markings to be text instead of a hairpin and use your own markup text.

\relative c'' {
  \set crescendoText = \markup { \italic { cresc. poco } }
  \set crescendoSpanner = #'text
  \override DynamicTextSpanner.style = #'dotted-line
  a2\< a
  a2 a
  a2 a
  a2 a\mf
}

We can extend this further by using successive "\<" marks, which allows us to have as many bits of text as I want in the chain, except for the last one. To end the chain, it must end on a stand-alone dynamic. This can be created with:
do = \markup { \normal-text \italic do }
do = #(make-dynamic-script do)
or these operations can be combined:
do = #(make-dynamic-script (markup #:normal-text #:italic "do"))

Now, to create the broken-up crescendo (I'll leave the default dashed-line), we can do something like this:
\relative c'' {
  \set crescendoSpanner = #'text
  \set crescendoText = \markup \italic "cre"
  a2\< a 
  \set crescendoText = \markup \italic "scen"
  a2 a\<
  a2 a
  a2 a\do
}
So, all we need to do is put \set crescendoText = \markup \italic "some text" before the note or chord we want to attach it to and \< after it like we would normally do.

Nov 5, 2014

Vertically Centering Lyrics

Recently, I had to create one with a couple of verses with lyrics. Creating the lyrics is easy enough, but I quickly ran into a speed-bump when I wanted to make the chorus show up vertically centered in the same system as the verses. One way around this is to simply start a new system before the chorus lyrics show up, but I didn't want to do that. Doing a quick search through the LSR under the search term "lyrics" showed me that I could set up a series of temporary overrides and offset the vertical position of the lyrics:
dropLyrics = {
  \override LyricText.extra-offset = #'(0 . -4.5)
  \override LyricHyphen.extra-offset = #'(0 . -4.5)
  \override LyricExtender.extra-offset = #'(0 . -4.5)
  \override StanzaNumber.extra-offset = #'(0 . -4.5)
}

raiseLyrics = {
  \revert LyricText.extra-offset
  \revert LyricHyphen.extra-offset
  \revert LyricExtender.extra-offset
  \revert StanzaNumber.extra-offset
}
These two macros would then be used like this (in the first of the four verses):
lyricsA = \lyricmode {
  The first verse has
  \dropLyrics
  \set stanza = #"   All:"
  the com -- mon __ words
  \raiseLyrics
  used in all four.
}

This was exactly what I was looking for, but I felt like it needed to be a little more robust and customizable. So, with my limited knowledge of Scheme, I proceeded to make a function out of it:

dropLyrics =
  #(define-music-function (parser location x music)
     (number? ly:music?)
    #{
      \override LyricText.extra-offset = #(cons 0 x)
      \override LyricHyphen.extra-offset = #(cons 0 x)
      \override LyricExtender.extra-offset = #(cons 0 x)
      \override StanzaNumber.extra-offset = #(cons 0 x)
      $music
      \revert LyricText.extra-offset
      \revert LyricHyphen.extra-offset
      \revert LyricExtender.extra-offset
      \revert StanzaNumber.extra-offset
    #}
  )
Putting it in a function allows me to control the vertical alignment at the same location where I'm typing the text. Now, whenever I need to center a section of lyrics, all I need to do is something like this, adjusting for the proper height:
lyricsA = \lyricmode {
  The first verse has
  \dropLyrics #-4.5 {
    \set stanza = #"   All:"
    the com -- mon __ words
  }
  used in all four.
}
One thing I've learned is that centering lyrics between an odd-number of verses is as easy as including the single line of words in the middle verse while putting "\skip"s in all the others (only necessary if they pick up after the centered text like the example here). So, the above function is really only required for an even-number of verses, and only in the system where they appear together. If I put the centered text in the verse just above where I want to center it (i.e., the second verse if there are four), then I don't need to be explicit about the offset and it can be hard-coded:
dropLyrics =
  #(define-music-function (parser location music)
     (ly:music?)
    #{
      \override LyricText.extra-offset = #'(0 . -1.5)
      \override LyricHyphen.extra-offset = #'(0 . -1.5)
      \override LyricExtender.extra-offset = #'(0 . -1.5)
      \override StanzaNumber.extra-offset = #'(0 . -1.5)
      $music
      \revert LyricText.extra-offset
      \revert LyricHyphen.extra-offset
      \revert LyricExtender.extra-offset
      \revert StanzaNumber.extra-offset
    #}
  )
And to use it now, we move the centered text to the second verse and add \skipFour to the first one:
lyricsA = \lyricmode {
  The first verse has
  \skipFour
  used in all four.
}

lyricsB = \lyricmode { 
  In stan -- za two,  
  \dropLyrics {
    \set stanza = #"   All:"
    the com -- mon __ "words  "
  }
  al -- so ap -- pear. 
}
The only catch to this is that the text will only look for collisions between surrounding characters, so it may be necessary to add additional spaces to the first/last words (as I've done with "   All:" and "words  "). Maybe it would be more useful now to call the function "centerLyrics" instead, but whatever.

Nov 3, 2014

No Music Font Industry?

You may know of my involvement with designing alternative music fonts for LilyPond. Ever since I was able to get these fonts to work, I have often wondered why there aren't more music notation fonts out there. The most common seem to be:
  • Maestro (Finale)
  • Petrucci (Finale)
  • Opus (Sibelius)
  • Helsinki (Sibelius)
  • Jazz & Swing (Sigler)
  • Sonata (Adobe)
  • Bravura (Steinberg)
There are definitely others out there, but as I've looked through the various notation software, most have one, maybe two, music fonts. There is an ocean of text fonts, but not for music fonts. Why is this? I can only speculate that it is because of a couple of reasons:
  1. No common character set standard (like Unicode or ASCII). Most music fonts have followed the mnemonic approach of Sonata, like putting the treble clef in the "&" character spot, the sharp accidental in the "#" character spot, etc. Recently, Steinberg's Daniel Spreadbury has been hard at work trying to change this and create a complete music glyph standard that will support nearly any conceivable notation element, ancient and modern. This standard is called the "Standard Music Font Layout" or SMuFL. If this catches on, it could open up the door to a host of designers.
  2. A relatively small user base. Let's face it, there are more people who are going to type up a document with words in it (I'll call them "typesetters") than there are people who are going to type up a document with music in it (I'll call them "engravers"). Since the proportion of engravers to typesetters is extremely small, there doesn't appear to be the same kind of demand for original music typefaces, so high quality designers don't spend much time in it.
  3. Typeface styles/Contextual Purpose. In text, there are so many variants and they all have their own usefulness (light, book, italic, bold, black, serif, sans-serif, monospace, etc.). However, music notation has a specific utility for conveying performance instructions to musicians. The music font (as well as the rest of the score) must be clear so that the musician can play it correctly. Musicians expect this and get quite frustrated when the music is not clear. Since notational elements already vary widely in weight and shape, it is hard to find a correlation to the very many text typeface variants. In that sense, and in my experience, music fonts are MUCH easier to design because there is pretty much just the one glyph set. The only variants to be found are the text-related ones like tuplet numbers. The two main font styles that seem to exist for music fonts are "engraved" and "handwritten". The handwritten fonts tend to be associated with a "jazzy" feel, and basically everything else gets the classic engraved look. 
Well, that's all I can think of for now. Maybe the industry will change, especially as there are more and more self-publishers who may seek a less generic look for their scores. In any case, creating music fonts for LilyPond has given me a chance to contribute to the small pool of high quality music font industry. Who knows where that will lead me?