lilypond-user
[Top][All Lists]
Advanced

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

Re: [bounty] context generating function - how to get context def from i


From: Janek Warchoł
Subject: Re: [bounty] context generating function - how to get context def from its name?
Date: Fri, 25 Jul 2014 23:37:58 +0200

2014-07-25 21:34 GMT+02:00 David Kastrup <address@hidden>:
> Janek Warchoł <address@hidden> writes:
>
>> newInstrument =
>> #(define-scheme-function
>>   (parser location instrName parentName settings)(string? ly:context-mod?)
>>   ;; ...
>>     #{
>>       \layout {
>>         \context {
>             $(module-ref (current-module) (string->symbol parentName))

Ha!
Exactly as i thought: as a higher-level mage than me, you know more
(and more powerful) magic incantations than i do.  Kudos!

>>           ;; create "instrNameStaff" context, derived from "parentNameStaff",
>>           ;; with default child "instrNameVoice", and modifications specified
>>           ;; in "settings" argument
>             \name #instrName
>             \defaultchild #instrNameVoice
>             #settings
>>         }
>>         \context {
>>           ;; create "instrNameVoice" context, derived from "parentNameVoice",
>>         }
>>       }
>>     #})
>>
>> I managed to write a function that does something like this, but I
>> have two problems:
>> 1) inside the function, i don't know how to get a context definition
>> from its name (i.e. from a string).  Right now i have to pass parent
>> contexts' definitions as separate arguments, but this means that i
>> have three arguments instead of one.
>> 2) i didn't manage to get midi stuff done inside the same function as
>> the layout stuff - but i think that i'll be able to solve that if i
>> have a solution to 1).
>
> You basically need to collect just the context definitions and apply
> those (a context definition is applied by looking up its \name and
> overwriting the variable with that name).
>
> Frankly, I am tempted to create something like
> #{
>    \output {
>      \context ...
>      xxx = 3\cm
>    }
> #}
>
> that will either execute a number of assignments or alternatively return
> an anonymous lambda or define-void-function doing the same so that you
> can easily splice it into different output definitions.
>
> Something like that would apparently serve a need.

I don't fully understand this yet, but for now i'm very happy that I
have a better version of the function (see attached) :)
I haven't gotten rid of all the duplication yet, but the user
interface at least seems nice!

Any further improvements are welcome! It would be great if you managed
to fix \addlyrics so that it would work nice with these custom
contexts (see comments in the attachment) - i'd gladly give another
€15 for that (or maybe more...).

thanks & good night for now! :)
Janek

Attachment: new-instrument.ly
Description: Text Data


reply via email to

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