Lilypond: Customize bar lines, recursively, automatically? - lilypond

I'm working on Carnatic music scores that involve complex time signatures, that will require modified bar lines
Pattern for barlines for: 8/4
beats: 1 2 3 4 (dashed bar here) 5, 6 (Dotted Bar) 7, 8 (double bar)
Here's one bar of actual score
g16( f) d8 ees( ees) d16( c d8) bes16[( d c bes \bar "dashed"
a g]) a[( bes c] d[ c d]) \bar ":"
g8( f16) ees8( d16 c d) \bar "||"
Is there a way to automate these barlines?

Give this a try. It's not fully automated in that you need to have an "invisible" voice allocated to specify the barlines, and you need to keep track of how many measures this form of barring needs to extend and specify an appropriate unfold value. The "s", if you don't already know, is an invisible spacer, with duration like a rest.
\version "2.13.19"
fooBar = { s1 \bar "dashed" s2 \bar ":" s2 \bar "||" }
\new Staff <<
\new Voice = "theMusic" \relative c'' {
% bar 1
g16( f) d8 ees( ees) d16( c d8) bes16[( d c bes
a g]) a[( bes c] d[ c d])
g8( f16) ees8( d16 c d)
% bar 2
g16( f) d8 ees( ees) d16( c d8) bes16[( d c bes
a g]) a[( bes c] d[ c d])
g8( f16) ees8( d16 c d)
}
\new Voice = "theBarLines" { \repeat unfold 2 \fooBar }
>>

Related

Lilypond: Instrument part transpose with several key signatures

For example, I have a very long clarinets part starts in Fis-dur and ends in G-dur written in concert pitch.
How can I apply transposition to them without causing weird key signatures at the beggining or at the end?
ClarinetI = \relative c' {\key fis \major
fis8 gis ais b cis cis cis4 |
\key g \major
g8 a b c d d d4
}
ClarinetII = \relative c' {\key fis \major
dis8 eis fis gis ais ais ais4|
\key g \major
e8 fis g a b b b4
}
\new Staff \with {instrumentName = "clarinets in concert"}<<
\partCombine \ClarinetI \ClarinetII
>>
\new Staff \with {instrumentName = "clarinets in B"}<<
\transpose bes c' \partCombine \ClarinetI \ClarinetII
>>
I want resulting part look like this:
Generally, as I'm exporting the score from Reaper midi — I can add some Python logic into the export process, but currently I'm inside the production and need to works with the exported parts as they are.
P.S. I've tested MuseScore against my example and...
As a temporary fix, I've wrapped Fis-dur part into enharmonical transpose statement. But I would like to see more reliable and complex solution.
ClarinetI = \transpose c c' { \transpose fis ges {\key fis \major
fis8 gis ais b cis' cis' cis'4 }|
\key g \major
g8 a b c' d' d' d'4
}
ClarinetII = \transpose c c' { \transpose fis ges {\key fis \major
dis8 eis fis gis ais ais ais4|}
\key g \major
e8 fis g a b b b4
}
\new Staff \with {instrumentName = "clarinets in concert"}<<
\partCombine \ClarinetI \ClarinetII
>>
\new Staff \with {instrumentName = "clarinets in B"}<<
\transpose bes c' \partCombine \ClarinetI \ClarinetII
>>

Lilypond: Change color of notes below and above a certain pitch

While writing a Lilypond score for recorders (flutes), I wish I could automatically mark notes with pitches beyond the range of an instrument by changing its color.
The idea is that, for example, all absolute pitches below f and all pitches above g'' are colored red for the bass instrument. The same for tenor, alt and soprano instruments.
I found a helpful question on coloring notes, but there remains a piece of code I cannot write:
#(define (ambitus-notehead-alt grob)
( **code_i_cannot_write** )
#(define (ambitus-notehead-tenor grob)
( **code_i_cannot_write** )
#(define (ambitus-notehead-bass grob)
( **code_i_cannot_write** )
\score {
\new Staff \relative c' {
\override NoteHead #'color = #ambitus-notehead-alt
\music_altrecorder
}
\new Staff \relative c' {
\override NoteHead #'color = #ambitus-notehead-tenor
\music_tenorrecorder
}
\new Staff \relative c' {
\override NoteHead #'color = #ambitus-notehead-bass
\music_bassrecorder
}
}
Here is a function that does what you want:
\version "2.19.82"
#(define (colour-out-of-range grob)
(let* ((pch (ly:event-property (event-cause grob) 'pitch))
(semitones (ly:pitch-semitones pch)))
(cond ((< semitones 0) red)
((> semitones 24) red)
(else black))))
\score {
\new Staff \relative c' {
\override NoteHead.color = #colour-out-of-range
g8 a b c d e f g a b c d e f g a b c d e f g
}
}
Producing:
To customize it for your instrument's range, change the values of (< semitones 0) and (> semitones 24). The value 0 is the middle C (C4), and increments of 1 are equal to one semitone. So in the case above, the range is between C4-C6. You need to use negative values for pitches below middle C (e.g. -5 is G3).

LilyPond multiline lyrics

Having this example LilyPond snippet, I'm getting two strange things.
\score{
<<
\new Voice = "voicea" \relative { g'4 a b c g a b c }
\new Lyrics \lyricmode {
{ a b c d }
<<
\new Lyrics \lyricsto "voicea" \lyricmode { e f g h }
\new Lyrics \lyricsto "voicea" \lyricmode { i j k l }
>>
}
\new Voice = "voiceb" \relative { g'4 a b c g a b c }
>>
}
The last two lyrics lines are placed under the both music lines. I want all lyrics to go in-between them.
By some reason, the lyrics don't line up correctly with the notes. The first quarter note in the second bar has no lyric.
Can you help me understand what is going on, and preferably come up with a solution.
Here is the document: http://lilybin.com/o6atu2/1
One Lyrics context makes one line of lyrics. If you want sequential lyrics, you need to put them into the same context. To target some notes in a voice, you can always create a named voice into another. This is what it looks like:
\score{
<<
\new Voice = "voicea" \relative {
g'4 a b c
\new Voice = "voiceb" { g a b c }
}
\new Lyrics
<<
\lyricsto "voicea" { \lyricmode { a b c d } }
\lyricsto "voiceb" { \lyricmode { e f g h } }
>>
\new Lyrics \lyricsto "voiceb" { \lyricmode { i j k l } }
\new Voice = "voicec" \relative { g'4 a b c g a b c }
>>
}
The lilybin document is here: http://lilybin.com/4vsiem/1
I don't use Lyrics and I can't tell you what's wrong exactly in your example.
But this is a simple working example:
\version "2.18.2"
<<
\new Voice \relative {
g'4 a b c g a b c
}
\addlyrics { a b c d e f g h } % 1st stanza
\addlyrics { _ _ _ _ i j k l } % 2nd stanza
\new Voice \relative {
g'4 a b c g a b c
}
>>

Align secondary lyrics to hidden Voice

I think I'm close, but can't quite seem to get two stanzas going with one aligned to a hidden voice - so that rhythmic variations can be approximated by the lyrics.
melody = \relative c' {
\clef treble
\key c \major
\time 4/4
c4 d e f | g f e d |
<<
\new Voice = "shown" {
\relative c' {
c4 d c d | e f g2
}
}
\new Voice = "hidden" {
\hide {
c'8 c d d c c d d | e f g2
}
}
>>
}
text = \lyricmode {
Here we have a | li -- tle si -- lly
<<
{
\set stanza = #"1. "
Si -- lly li -- tle | al -- pha -- bet
\new Lyrics {
\set associatedVoice = "hidden"
\set stanza = #"2. "
Si -- ly li -- tle fu -- nny soun -- ding |
Al -- pha -- bet song.
}
}
>>
}
\score {
<<
\new Voice = "one" { \melody }
\new Lyrics \lyricsto "one" \text
>>
\layout { }
\midi { }
}
The above shows both voices and neither of their "associated" (or not) lyrics.
You can use the NullVoice context as so:
\version "2.19.15"
\language "english"
\score {
\new Staff
<<
\new Voice = "displayedMusic" \relative c'' {
b8 c d \times 2/3 {c16 d c}
b8 a g a
bf c bf \times 2/3 {a16 bf a}
g8 f g a
bf f' e a,
d cs4.~
cs1
}
\new NullVoice = "hiddenMusic"
{
c4 d e f %\break
g a b8~ b c4 \break
d e f g a
}
\new Lyrics \lyricsto "hiddenMusic" {
Those words seem to be aligned to the hidden melody or are they?
}
>>
}
Which will result in :
Okay. From the lilypond mailinglist I learned:
First, you need to use \hideNotes, not \hide. Also the above structure doesn't quite work. It's usually easier to have all the lyrics contexts running from the start rather than starting them part way along - they'll get their position from the notes. Here's one way of doing it, although in this particular case the stanza number doesn't quite fit.
melody = \relative c' {
\clef treble
\key c \major
\time 4/4
c4 d e f | g f e d |
<<
\new Voice = "shown" {
\relative c' {
c4 d c d | e f g2
}
}
\new Voice = "hidden" {
\hideNotes { % !!
c'8 c d d c c d d | e f g2
}
}
>>
}
text = \lyricmode {
Here we have a | li -- tle si -- lly
}
wordsOne = \lyricmode {
\set stanza = #"1. "
Si -- lly li -- tle | al -- pha -- bet
}
wordsTwo = \lyricmode {
\set stanza = #"2. "
Si -- ly li -- tle fu -- nny soun -- ding |
Al -- pha -- bet song.
}
\score {
<<
\new Voice = "one" { \melody }
\new Lyrics \lyricsto "one" \text
\new Lyrics \lyricsto "shown" \wordsOne
\new Lyrics \lyricsto "hidden" \wordsTwo
>>
\layout { }
\midi { }
}

What are those functional functions called?

I'm looking for a functional way to implement this:
list = [a b c d e f]
foo(list, 3) = [[a d] [b e] [c f]]
A potential solution is:
foo(list,spacing) = zip(goo(list,spacing))
Where, for example,
goo([a b c d e f],3) = [[a b c] [d e f]]
What is foo and goo usually called, so I can look for existing solutions rather than reinventing the wheel?
Notes: Rather than trying to explain with words, I've just shown examples that'll be hopefully much easier to get. Arbitrary syntax for broader understanding.
You can use partition:
(partition 3 '[a b c d e f])
=> ((a b c) (d e f))
(partition 2 '[a b c d e f])
=> ((a b) (c d) (e f))
Edit:
(apply map list (partition 3 '[a b c d e f]))
=> ((a d) (b e) (c f))
I do not think there is a built-in function for that. It's easy and nice to implement.
I know you do not want the implementation, but one of the tags was Haskell so maybe you want to see this
p :: Int -> [a] -> [[a]]
p n xs = [ [x | (x ,y) <- ys , y `mod` n == i] | i <- [0 .. n - 1] , let ys = zip xs [0 .. ]]
That is pretty functional.
Your goo function is drop with flipped arguments. Given that, you can implement foo almost like you say in your question:
let foo list spacing = zip list (drop spacing list)
This still doesn't exactly give the result you need though, but close:
Prelude> foo "abcdef" 3
[('a','d'),('b','e'),('c','f')]
EDIT:
Reading more carefully, your goo function is splitAt with flipped arguments. Given that, foo can be defined like this:
let foo list spacing = (uncurry zip) $ splitAt spacing list
Which is the same as:
let foo list spacing = let (left, right) = splitAt spacing list
in zip left right