11

I am trying to write a simple, minimalist script in LilyPond to create the koron symbol (used in Persian music).

I came up with the following solution, with satisfactory results, but my code is not well-organized:

koron = {
    \once\override Accidental.stencil = #ly:text-interface::print 
    \once\override Accidental.text = \markup {
        \overlay {
            \override #'(thickness . 1.5) {
                \draw-line #'(-.7 . .4)
                \draw-line #'(-.7 . -.4) 
                \translate #'(-.7 . -1.4)
                \draw-line #'(0 . 1.8)
            }
        }
    }
}

\markup {Mode of Dastgah} 

\score {
     {
        \omit Staff.TimeSignature
        \cadenzaOn
        \key c \major % not interested in automation of accidentals!
        \override Staff.KeySignature.stencil = #ly:text-interface::print
        \override Staff.KeySignature.text = \markup {
            \musicglyph #"accidentals.flat" % standard symbol added to key signature like this
            \overlay {
                \raise #1.5 {
                    \override #'(thickness . 1.5) {
                        \draw-line #'(-.7 . .4)
                        \draw-line #'(-.7 . -.4)
                        \translate #'(-.7 . -1.4)
                        \draw-line #'(0 . 1.8)
                    }
                }
            } % koron symbol added to key signature like this
        }
        \relative c' { 
            b!1 c \koron % replaces accidental of next note by koron
            deh e f g 
            a^\markup {
                \overlay {
                    \override #'(thickness . 1.5) {
                        \translate #'(1.5 . .7) {
                            \draw-line #'(-.7 . .4)
                            \draw-line #'(-.7 . -.4)
                            \translate #'(-.7 . -1.4)
                            \draw-line #'(0 . 1.8)
                        }
                    }
                } (var)
            } % koron in a text
            b 
            \bar "|."
        }
    }
}

lilypond code output

My naive difficulty is with defining new commands. I wish LilyPond would accept a LaTeX tool like \newcommand, but apparently it does not. The variable "koron" in my code seems to be working fine, but when I try to define, for example,

koronsymboldraw = {
    \draw-line #'(-.7 . .4)
    \draw-line #'(-.7 . -.4)
    \translate #'(-.7 . -1.4)
    \draw-line #'(0 . 1.8)
}

to make things more modular, LilyPond gives me errors:

error: unknown escaped string: `\draw-line'
...

With the manual of LilyPond not being sufficiently helpful really, I hope I can get some thoughts here on how we can define efficient commands and functions in LilyPond, particularly for this code.

1
  • 1
    You should submit this as a feature request to lilypond. Commented May 8, 2022 at 12:49

2 Answers 2

5

When you are defining a non-musical piece of script you often have to wrap it in a markup. Nesting markups is fine.


I don't know what version you are running, but this seems to work in version 2.19:


\version "2.19.48"

koronsymboldraw = \markup {
    \override #'(thickness . 1.5) {
        \overlay {
            \draw-line #'(-.7 . .4)
            \draw-line #'(-.7 . -.4)
            \translate #'(-.7 . -1.4)
            \draw-line #'(0 . 1.8)
        }
    }
}

koron = {
    \once\override Accidental.stencil = #ly:text-interface::print
    \once\override Accidental.text = \koronsymboldraw
}

\markup { Mode of Dastgah }

\score {
    {
        \omit Staff.TimeSignature
        \cadenzaOn
        \key c \major
        \override Staff.KeySignature.stencil = #ly:text-interface::print
        \override Staff.KeySignature.text = \markup {
            \musicglyph #"accidentals.flat"
                \raise #1.5 
                \koronsymboldraw 
        }
        \relative c' {
            b!1 c \koron
            deh e f g
            a^\markup { 
                \koronsymboldraw 
                \lower #0.5
                (var) 
            }
            b
            \bar "|."
        }
    }
}
2
  • 1
    It seems like a solution to wrap the definition of the commands in a \markup, but since these commands are mainly to be used inside other markups in the code, I'm not sure whether the approach of nested markups is not going to cause other problems. I sort of hoped to have a way of "simply" bundling a bunch of things into a placeholder, similar to what \newcommand provides in LaTeX. Also, why didn't you use \overlay instead of those \hspace's that you have added to \koronsymboldraw? The resulting koron symbol with your combination of commands has misaligned lines and corners.
    – Hadi S
    Commented May 1, 2021 at 4:08
  • I didn't know what version you were running, so I first guessed that it was 2.18 (which is now quite clearly incorrect). 2.18 doesn't have the overlay command - so there were misalignments. So I replaced some of the overlays with the extra spacing. Then I changed to version 2.19, but didn't but the overlay command back in. Sorry about that – see edited response. Commented May 8, 2021 at 4:26
6

In recent versions, persian.ly provides Persian accidentals as well as key signatures. I believe it is available since version 2.23.6.

Minimal example for dastgah-e shoor (in G):

\version "2.24.1"

\include "persian.ly"

\score {
  \header {
    piece = "Dastgah-e Shoor."
  }
  {
    \key g \shur
    \relative c' {
        bf1 c 
        d ef f g
        ak
        bf
        \bar "|."
    }
  }
}

Dastgah-e Shoor

The documentation about persian.ly provides some information (link), but I had to dig some specifics from the source code on GitHub: permalink.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.