lilypond-user
[Top][All Lists]
Advanced

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

Re: Passing pitch to function


From: Pierre-Luc Gauthier
Subject: Re: Passing pitch to function
Date: Thu, 15 Jun 2023 13:15:55 -0400

Thank you so much for the thorough explanation Valentin !

Le jeu. 15 juin 2023, à 13 h 01, Valentin Petzel <valentin@petzel.at> a écrit :
>
> Okay, I understand the problem.
>
> Basically what’s happening is this:
> You are doing
>
> #(define instrumentsInfo
>    '(
>       (piccolo . ((fullName "Piccolo") (transposition #{bf'#})))
>       ))
>
> and intend it to be a shorthand for
>
> #(define instrumentsInfo
>    (list (cons 'piccolo
>                (list (list 'fullName "Piccolo")
>                      (list 'transposition #{ bf' #})))))
>
> But this is not in fact equivalent. ' is a concept of scheme we call "quoting"
> which essentially tells guile to only parse or not evaluate the expression.
> Now you need to understand how #{ ... #} works: This is translated not into a
> scheme object, but a scheme function call that parses the enclosed string.
> This means that #{ ... #} can in fact be quoted, which is why your #(display
> ...) output does not give you a #<Pitch bf' >, but something looking like
> this:
>
> ((@@ (lily) read-lily-expression-internal) bf' /tmp/frescobaldi-avp8mtzi/
> tmpx3_nmcsq/test.ly 6 (list))
>
> This is the actual call Lilypond makes to evaluate #{bf'#} (the bf' you see
> there is not the symbol bf', but a character string).
>
> This means that you are not in fact passing a pitch, but an unevaluated piece
> of scheme code.
>
> If you want to abuse quoting for this you might use quasiquoting instead:
>
> #(define instrumentsInfo
>    `(
>       (piccolo . ((fullName "Piccolo") (transposition ,#{bf'#})))
>       ))
>
> Or instead use actual lists as mentioned before
>
> #(define instrumentsInfo
>    (list (cons 'piccolo
>                (list (list 'fullName "Piccolo")
>                      (list 'transposition #{ bf' #})))))
>
> Cheers,
> Valentin
>
> Am Donnerstag, 15. Juni 2023, 18:45:43 CEST schrieb Pierre-Luc Gauthier:
> > I've attached my notquite-MWE.
> >
> > Le jeu. 15 juin 2023, à 12 h 35, Pierre-Luc Gauthier
> >
> > <p.luc.gauthier@gmail.com> a écrit :
> > > So sorry, you have to remove the c''% at the end… 'should have made that
> > > clear.>
> > > Le jeu. 15 juin 2023, à 12 h 33, Valentin Petzel <valentin@petzel.at> a
> écrit :
> > > > Hello Pierre-Luc,
> > > >
> > > > It works for me if I copy and paste your code. Can you maybe attach a ly
> > > > file that does not work for you?
> > > >
> > > > Cheers,
> > > > Valentin
> > > >
> > > > Am Donnerstag, 15. Juni 2023, 18:25:37 CEST schrieb Pierre-Luc Gauthier:
> > > > > What am-I doing wrong here… ☹
> > > > >
> > > > > \version "2.25.6"
> > > > >
> > > > > \language "english"
> > > > >
> > > > > #(define instrumentsInfo
> > > > >
> > > > >    '(
> > > > >
> > > > >       (piccolo . ((fullName "Piccolo") (transposition #{bf'#})))
> > > > >       ))
> > > > >
> > > > > instrumentInfoLookup =
> > > > > #(define-scheme-function
> > > > >
> > > > >   (instrument info)
> > > > >   (symbol? symbol?)
> > > > >   (car (cdr (assq info (cdr (assq instrument instrumentsInfo))))))
> > > > >
> > > > > #(display (instrumentInfoLookup 'piccolo 'fullName))
> > > > > #(display (instrumentInfoLookup 'piccolo 'transposition))
> > > > >
> > > > > part =
> > > > > #(define-music-function
> > > > >
> > > > >   (music fullName transposition)
> > > > >   (ly:music? markup? ly:pitch?)
> > > > >   #{
> > > > >
> > > > >     \new Staff \with {
> > > > >
> > > > >       shortInstrumentName = fullName
> > > > >
> > > > >     } <<
> > > > >
> > > > >       \transpose $transposition c'
> > > > >       $music
> > > > >   >>
> > > > >   >>#} )
> > > > >
> > > > > %\part c' "test" bf
> > > > > \part c'' #(instrumentInfoLookup 'piccolo 'fullName)
> > > > > c''%#(instrumentInfoLookup 'piccolo 'transposition)
> > > > >
> > > > > The ly:pitch? predicate fails. Is there a way for that pitch to be
> > > > > sent as a correct ly:pitch? ¿
> > > > >
> > > > > Thanks for any pointers.
> > >
> > > --
> > > Pierre-Luc Gauthier
>


-- 
Pierre-Luc Gauthier



reply via email to

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