lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glissando and how to create concise code


From: Thomas Morley
Subject: Re: glissando and how to create concise code
Date: Sat, 6 Oct 2012 02:23:17 +0200

2012/10/6 Brad Smith <address@hidden>:
> Hi, I'm a little bit new to lilypond, and I'm trying to write a gliss
> into a note and that works fine with something like the following:
>
> : \hideNotes \grace f \glissando \unHideNotes c'
>
> My question is how can I simplify this? I don't want to type this
> whole thing every time I want this. I'd like to do something like:
>
> : \glissin f c'
>
> Am I correct to assume that the best way to do this is with
> define-music-function? I am trying to write a function that takes two
> arguments and works as if I typed the whole example above. The
> following example contains my attempt, which does not compile:
>
>
> \version "2.16.0"
> \include "english.ly"
>
> glissin =
>     #(define-music-function
>         (parser location notea noteb)
>         (ly:music? ly:music?)
>         #{
>             \hideNotes \grace $notea \glissando \unHideNodes $noteb
>         #})
>
> tune = {
>     c4 d e f |
>     g \hideNotes \grace f \glissando \unHideNotes c' b a |
>     c4 d e f |
>     g \glissin f c' b a |
> }
>
> \score {
>     \new Staff {
>         \clef "treble_8"
>         \time 4/4
>         \tune
>     }
> }
>
>
> When I compile, I get the following output:
>
>
> Starting lilypond-windows.exe 2.16.0 [test.ly]...
> Processing `c:/.../test.ly'
> Parsing...
> c:/.../test.ly:9:37: error: syntax error, unexpected EVENT_IDENTIFIER
>             \hideNotes \grace $notea
>                                      \glissando \unHideNodes $noteb
>
> c:/.../test.ly:9:48: error: unknown escaped string: `\unHideNodes'
>             \hideNotes \grace $notea \glissando
>                                                 \unHideNodes $noteb
>
> c:/.../test.ly:16:20: error: error in #{ ... #}
>     g \glissin f c'
>                     b a |
>
> c:/.../test.ly:20:4: error: errors found, ignoring music expression
>
>     \new Staff {
>
> fatal error: failed files: "c:\\...\\test.ly"
> Exited with return code 1.
>
>
> I notice that I can replace $notea with an immediate note like f, and
> it will compile correctly. There seems to be a problem with how $notea
> is being parsed in combination with \glissando that I don't
> understand.
>
> All I really want is something like a preprocessor macro to cut down
> on boilerplate code, but something like this does not seem to be
> available in lilypond. The define-music-function thing seems like it
> would be a reasonable substitute for that if I could get it to work,
> but I'm finding it hard to figure out what's going on. When trying to
> solve this problem, I'm not sure where to start in the documentation.
>
> Can anyone help?
>
>
> -- Brad Smith
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

Hi Brad,

your first variable `notea' is coded with ly:music? it should be ly:pitch?
Furthermore I think it's useful to have the possibility to adjust the
duration of `notea', so I added a new variable `dur' with predicate
ly:duration?
I hope someone with more english-language-skills could give you more
detailed explanations.

\version "2.16.0"
\include "english.ly"

glissin =
    #(define-music-function
        (parser location notea dur noteb)
        (ly:pitch? ly:duration? ly:music?)
        #{
            \hideNotes \grace $notea $dur \glissando \unHideNotes $noteb
        #})

tune = {
    c4 d e f |
    g \hideNotes \grace f \glissando \unHideNotes c' b a |
    c4 d e f |
    g \glissin f 8 c' b a |
}

\score {
    \new Staff {
        \clef "treble_8"
        \time 4/4
        \tune
    }
}


HTH,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]