Tracking usage of variables

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

Tracking usage of variables

Mark Knoop-4
Often in the music I'm engraving a single variable might be used and transformed in multiple contexts and repetitions throughout the piece. This can become difficult to keep track of, particularly if subsequent changes are made which might want to affect only one or some of the instances.

It would be great to be able to display the use of variables throughout a score, I imagine by writing a custom engraver for this. Such an engraver would create two helpful components:

1. Add markup to every use of a variable in the music. The point-and-click link of this markup would be to the use of the variable (rather than its definition).

2. Output a text report listing the musical locations (bar/beat) and contexts of each variable.

The example below demonstrates what such an engraver would create. I don't really know how to start with this, or if it is even possible - any thoughts or pointers from scheme gurus would be extremely helpful.

Thanks,

Mark

%%%%%%%%%%%%%%%%
\version "2.19.82"

motif = { c'4 e' g' c'' }

#(define-markup-command
  (variable layout props varname)
  (string?)
  "Format variable name."
  (interpret-markup layout props
   #{
   \markup
   \with-dimensions #'(0 . 0) #'(0 . 0)
   \with-color #red
   \raise #1
   \column {
     \box \fontsize #-3 \typewriter #varname
     \combine
     \draw-line  #'(0 . 3)
     \arrow-head #Y #DOWN ##f
   }
   #}))

varname =
#(define-event-function (text) (markup?)
  #{
  -\tweak parent-alignment-X #CENTER
  -\tweak layer #-10
  ^\markup \variable #text
  #})

\score {
  <<
    \new Staff = "flute" \with {
      instrumentName = "flute"
    } {
      <>\varname "motif"
      \motif
      R1
      \repeat unfold 3 \transpose c' e' { <>\varname "motif" \motif }
      \bar "|."
    }
    \new Staff = "viola" \with {
      instrumentName = "viola"
    } {
      \clef "alto"
      R1
      \repeat unfold 4 \shiftDurations 2 0 { <>\varname "motif" \motif }
      R1*2
      <>\varname "motif"
      \motif
    }
  >>
}

%{ output to text file:
Variable report
===============

motif:

  1 0/4: flute
  2 0/4: viola
  2 1/4: viola
  2 2/4: viola
  2 3/4: viola
  3 0/4: flute
  4 0/4: flute
  5 0/4: flute
  5 0/4: viola

%}
%%%%%%%%%%%%%%%%

--
Mark Knoop

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

Re: Tracking usage of variables

David Kastrup
Mark Knoop <[hidden email]> writes:

> Often in the music I'm engraving a single variable might be used and transformed in multiple contexts and repetitions throughout the piece. This can become difficult to keep track of, particularly if subsequent changes are made which might want to affect only one or some of the instances.
>
> It would be great to be able to display the use of variables throughout a score, I imagine by writing a custom engraver for this. Such an engraver would create two helpful components:
>
> 1. Add markup to every use of a variable in the music. The point-and-click link of this markup would be to the use of the variable (rather than its definition).
>
> 2. Output a text report listing the musical locations (bar/beat) and contexts of each variable.
>
> The example below demonstrates what such an engraver would create. I don't really know how to start with this, or if it is even possible - any thoughts or pointers from scheme gurus would be extremely helpful.

Variable use does not sound like a use case for engravers since
engravers work at a different stage than variable use.

How about something like

motif = { c'4 e' g' c'' }

make-obvious =
#(define-void-function (x) (symbol?)
   (let ((old (ly:music-deep-copy (ly:parser-lookup x))))
     (ly:parser-define! x
       (define-music-function () ()
         #{ \context Bottom << <>-#(format "Variable: ~s" x) $old >> #}))))

\make-obvious motif

\score {
  <<
    \new Staff = "flute" \with {
      instrumentName = "flute"
    } {
      \motif
      R1
      \repeat unfold 3 \transpose c' e' \motif
      \bar "|."
    }
    \new Staff = "viola" \with {
      instrumentName = "viola"
    } {
      \clef "alto"
      R1
      \repeat unfold 4 \shiftDurations 2 0 \motif
      R1*2
      \motif
    }
  >>
}

I apologize for vandalizing your code and throwing out the bulk of
functionality and markup you put in but that was just a quick and easy
job.

--
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: Tracking usage of variables

Mark Knoop-4
At 13:17 on 03 Mar 2019, David Kastrup wrote:

> Mark Knoop <[hidden email]> writes:
>> Often in the music I'm engraving a single variable might be used and
>> transformed in multiple contexts and repetitions throughout the
>> piece. This can become difficult to keep track of, particularly if
>> subsequent changes are made which might want to affect only one or
>> some of the instances.
>>
>> It would be great to be able to display the use of variables
>> throughout a score, I imagine by writing a custom engraver for this.
>
> Variable use does not sound like a use case for engravers since
> engravers work at a different stage than variable use.

Yes, I thought this might be the case.

> How about something like
>
> motif = { c'4 e' g' c'' }
>
> make-obvious =
> #(define-void-function (x) (symbol?)
>    (let ((old (ly:music-deep-copy (ly:parser-lookup x))))
>      (ly:parser-define! x
>        (define-music-function () ()
>          #{ \context Bottom << <>-#(format "Variable: ~s" x) $old >> #}))))
>
> \make-obvious motif
>
> I apologize for vandalizing your code and throwing out the bulk of
> functionality and markup you put in but that was just a quick and easy
> job.

That's brilliant, thanks. I'll work more with that and see where it takes me.

--
Mark Knoop

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

Re: Tracking usage of variables

David Kastrup
Mark Knoop <[hidden email]> writes:

> At 13:17 on 03 Mar 2019, David Kastrup wrote:
>> Mark Knoop <[hidden email]> writes:
>>> Often in the music I'm engraving a single variable might be used and
>>> transformed in multiple contexts and repetitions throughout the
>>> piece. This can become difficult to keep track of, particularly if
>>> subsequent changes are made which might want to affect only one or
>>> some of the instances.
>>>
>>> It would be great to be able to display the use of variables
>>> throughout a score, I imagine by writing a custom engraver for this.
>>
>> Variable use does not sound like a use case for engravers since
>> engravers work at a different stage than variable use.
>
> Yes, I thought this might be the case.
>
>> How about something like
>>
>> motif = { c'4 e' g' c'' }
>>
>> make-obvious =
>> #(define-void-function (x) (symbol?)
>>    (let ((old (ly:music-deep-copy (ly:parser-lookup x))))
>>      (ly:parser-define! x
>>        (define-music-function () ()
>>          #{ \context Bottom << <>-#(format "Variable: ~s" x) $old >> #}))))
>>
>> \make-obvious motif
>>
>> I apologize for vandalizing your code and throwing out the bulk of
>> functionality and markup you put in but that was just a quick and easy
>> job.
>
> That's brilliant, thanks. I'll work more with that and see where it takes me.

Note that a music function would not actually be required to do what I
show here.  However, when you use a music function, you have the ability
to refer to (*location*) inside of it in which case this will refer to
the current input location where the music function is getting called.
I am not sure that this is what you want.  Of course you also have the
ability to call all sorts of indexing functions (and that does appear
like something you wanted to do).  If those indexing functions should
not refer to input line and number but instead to measure numbers or
stuff, you'd likely need to engage the help of \applyContext or
engravers or whatever after all.

--
David Kastrup

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