Reading global variables from Scheme [documentation request?]

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading global variables from Scheme [documentation request?]

Jérôme Plût-2
I would like to *read*, from within a Scheme function
(define-music-function), the values of variables such as
Score.currentBarNumber or Score.alternativeNumberingStyle.

I can have a guess that this is possible with such functions as
ly:context-property or ly:output-def-lookup, but the documentation of
these functions is quite terse.

How is it possible to access these values?

Thanks,

--
        Jérôme

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Reading global variables from Scheme [documentation request?]

David Kastrup
Jérôme Plût <[hidden email]> writes:

> I would like to *read*, from within a Scheme function
> (define-music-function), the values of variables such as
> Score.currentBarNumber or Score.alternativeNumberingStyle.
>
> I can have a guess that this is possible with such functions as
> ly:context-property or ly:output-def-lookup, but the documentation of
> these functions is quite terse.
>
> How is it possible to access these values?

Not at all since they don't exist at the time a music function is
interpreted.  Depending on what you actually want to do, you might
install callbacks that kick in at a time where those values exist.

How this is done depends on just what you want to see done when.

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Reading global variables from Scheme [documentation request?]

Thomas Morley-2
Am Do., 8. Nov. 2018 um 10:10 Uhr schrieb David Kastrup <[hidden email]>:

>
> Jérôme Plût <[hidden email]> writes:
>
> > I would like to *read*, from within a Scheme function
> > (define-music-function), the values of variables such as
> > Score.currentBarNumber or Score.alternativeNumberingStyle.
> >
> > I can have a guess that this is possible with such functions as
> > ly:context-property or ly:output-def-lookup, but the documentation of
> > these functions is quite terse.
> >
> > How is it possible to access these values?
>
> Not at all since they don't exist at the time a music function is
> interpreted.  Depending on what you actually want to do, you might
> install callbacks that kick in at a time where those values exist.
>
> How this is done depends on just what you want to see done when.
>
> --
> David Kastrup

Hi Jérôme,

could you post some example- or pseudo-code what you want to achieve?
Would be helpful...

Have to run for my regular job now, though.


Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

\goto for Lilypond

Jérôme Plût-2
I quite often find myself transcribing a part of a big orchestral
score from IMSLP (e.g., putting the horns in F
transposition and the trombones in bass clef -- our brass section is
not too good at exotic sightreading).

For this I put the global structure of a movement in a \global
variable, such as:


global = {
  \time 4/4 \tempo "Al dente ma non troppo"
  s1*47 \mark "A" % bar 48
  s1*38 \mark "B" % bar 86
  ...
}

and cues in another variable:

cues = {
  % I don't know about you, but I like having *a lot* of cues to
  % follow. I suspect that being a former pianist, I find it easier
  % than most brass colleagues to read several lines at once?
  R1*15 % bar 16
  \relative { fis'1^"Fl." } % bar 17
  R1*24
  \relative { c''1^"Ob." } % bar 41
}

Keeping tracks of the bar numbers is a bit tedious, and I find myself
doing a *lot* of additions/subtractions (« sooo this oboe cue is 7
bars before A, and my last cue ended at bar 17, which makes it, let's
see.. 17 measures of rest »). And then spend twice as long fixing the
bugs (and introducing new ones, etc.)



So I wrote a few macros to automate this (and I expect them to pay
for themselves in only 1-2 more symphonies).

Now I can write the previous score in this way:

global = {
  \at-bar 1 { \time 4/4 \tempo "..." }
  \at-bar 48 { \mark "A" }
  \at-bar 86 { \mark "B" }
}

cues = <<
  \relative { \goto 16 fis'1^"Fl." }
  \relative { \goto "A-7" c''1^"Ob." } % we can even make them relative
>>

(In particular, this makes *inserting* a new cue much, much easier).

The functions should work even in the presence of varying time
signatures. A proof of concept (in 608 parentheses) is in the attached file.

Drawbacks (those identified for now):
 - \partial is not recognized yet
   (but this is quite easy to compensate for, by putting the
   appropriate skip at the beginning of \global);
 - this assumes that alternateBarNumbering is 'numbers-with-letters,
   (the other way around is quite easier; I could put some code to
   identify \set Score.alternateBarNumbering commands);
 - it *does not work* (for syntax reasons) in the presence of true
   repeats (they must be simulated using Score.repeatCommands);
 - when a voice uses \at-bar, it must *only* use \at-bar (this is the
   only way to keep track of time; see my previous question).


Oh, and by the way, I have a half-serious bug-report:
negative-length skips don't work.

--
        Jérôme

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

at-bar.ly (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: \goto for Lilypond

Jérôme Plût-2
> cues = {
>   % I don't know about you, but I like having *a lot* of cues to
>   % follow. I suspect that being a former pianist, I find it easier
>   % than most brass colleagues to read several lines at once?
>   R1*15 % bar 16
>   \relative { fis'1^"Fl." } % bar 17
>   R1*24
>   \relative { c''1^"Ob." } % bar 41
> }

By the way, a secondary question:

the \cues voice has some cues from a large number of instruments and
therefore a large range. So the clef used for the cues will depend on
the instrument I am currently cueing from.

Currently I use several different macros for cueing in F, G or current
clef. Does there exist a way to put the clef info in the cue voice
itself? (e.g. a oboe cue will always be in G clef, whereas a viola cue
will not provoke a clef change). Or else, to have access to the cued
music (and possibly the current clef) to compute an appropriate
cue-clef?

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: \goto for Lilypond

Kieren MacMillan
In reply to this post by Jérôme Plût-2
Hi Jérôme,

> and cues in another variable:

May I ask why you don’t use the built-in cue system? I’ve found it very useful and flexible.

> Now I can write the previous score in this way:
>
> global = {
>  \at-bar 1 { \time 4/4 \tempo "..." }
>  \at-bar 48 { \mark "A" }
>  \at-bar 86 { \mark "B" }
> }

David K wrote a similar function for me a couple of years ago.
Clearly, something like this should be in the regular distro…

Cheers,
Kieren.
________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: [hidden email]


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: \goto for Lilypond

Jérôme Plût-2
Sexto Idus Octobres MMXVIII scripsit Kieren MacMillan :
> Hi Jérôme,
>
> > and cues in another variable:
>
> May I ask why you don’t use the built-in cue system? I’ve found it very useful and flexible.

I do use it! I have another set of macros (not shown here) that
basically wrap \cueDuringWithClef. (I actually wrote a generator for
such trivial wrappers, which I use like this:

cc = #(cue-gen "cues" "")
ccF = #(cue-gen "cues" "" "F")
ctA = #(cue-gen "tromboneA" "Tbn. I" "F")
ctB = #(cue-gen "tromboneB" "Tbn. II" "F")

{ ... \cc R1*2 ... }

I could send it here in case anyone were interested (but it would need
a bit of code cleansing before)).

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: \goto for Lilypond

Jérôme Plût-2
Sexto Idus Octobres MMXVIII scripsit Jérôme Plût :

> Sexto Idus Octobres MMXVIII scripsit Kieren MacMillan :
> > Hi Jérôme,
> >
> > > and cues in another variable:
> >
> > May I ask why you don’t use the built-in cue system? I’ve found it very useful and flexible.
>
> I do use it! I have another set of macros (not shown here) that
> basically wrap \cueDuringWithClef. (I actually wrote a generator for
> such trivial wrappers, which I use like this:

Oh! I guess you meant, "Why don't I cue directly from the
oboe/bassoon/etc. voice"? In that case, the reason is that I generally
only need to redo the trombone/horn parts (instead of the full 20-25
voices in the orchestra...), so I don't have full oboe/etc. voices to
quote from. Hence the fact that I put all cues in the same voice.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: \goto for Lilypond

Kieren MacMillan
Hi Jérôme,

> Oh! I guess you meant, "Why don't I cue directly from the
> oboe/bassoon/etc. voice"?

Yes.  =)

> In that case, the reason is that I generally
> only need to redo the trombone/horn parts (instead of the full 20-25
> voices in the orchestra...), so I don't have full oboe/etc. voices to
> quote from. Hence the fact that I put all cues in the same voice.

Ah! That makes a lot of sense. Sorry for the noisy question.

Kieren.

________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: [hidden email]


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user