How to extract the current time signature

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

How to extract the current time signature

tisimst
I'd like to extract the current numerator and denominator of the time signature at any point in time. How can I do this in scheme? A robust solution (i.e., one that can handle compound time signatures) is always preferred, but I can settle for "normal" time signatures with a single numerator and denominator.

Thanks,
Abraham
Reply | Threaded
Open this post in threaded view
|

Re: How to extract the current time signature

Thomas Morley-2
2015-01-22 2:09 GMT+01:00 tisimst <[hidden email]>:
> I'd like to extract the current numerator and denominator of the time
> signature at any point in time. How can I do this in scheme? A robust
> solution (i.e., one that can handle compound time signatures) is always
> preferred, but I can settle for "normal" time signatures with a single
> numerator and denominator.
>
> Thanks,
> Abraham



Maybe:

\version "2.19.15"

printTimeSignatureFraction =
\applyContext #(lambda (ctx)
  (let* ((context
           (ly:context-property-where-defined ctx 'timeSignatureFraction))
         (time-sig-frac
           (ly:context-property context 'timeSignatureFraction)))
  (display time-sig-frac)))

\relative c' {
    \time 3/2
    \printTimeSignatureFraction % => (3 . 2)
    c''1
        \compoundMeter #'((1 4) (3 8))
    \printTimeSignatureFraction % => (5 . 8) !!
        \repeat unfold 5 c8 \repeat unfold 10 c16
}

Though the compound TimeSig will return "summarized"

Cheers,
  Harm

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

Re: How to extract the current time signature

tisimst
Harm,

Thomas Morley-2 wrote
Maybe:

\version "2.19.15"

printTimeSignatureFraction =
\applyContext #(lambda (ctx)
  (let* ((context
           (ly:context-property-where-defined ctx 'timeSignatureFraction))
         (time-sig-frac
           (ly:context-property context 'timeSignatureFraction)))
  (display time-sig-frac)))

\relative c' {
    \time 3/2
    \printTimeSignatureFraction % => (3 . 2)
    c''1
        \compoundMeter #'((1 4) (3 8))
    \printTimeSignatureFraction % => (5 . 8) !!
        \repeat unfold 5 c8 \repeat unfold 10 c16
}

Though the compound TimeSig will return "summarized"

Cheers,
  Harm
That works great! Thanks so much for your help. Perhaps I should have mentioned it in the original post, but I'd like to be able to use the values in time-sig-frac to automatically make a MultiMeasureRest with the duration of the full measure, but when I attempt to do so, nothing gets added to my score. Here's my latest and greatest:

%<------------------------------

\version "2.18.2"

autoMMR =
\applyContext #(lambda (ctx)
  (let* ((context
           (ly:context-property-where-defined ctx 'timeSignatureFraction))
         (time-sig-frac
           (ly:context-property context 'timeSignatureFraction))
         (num (car time-sig-frac))
         (den (cdr time-sig-frac)))
    (make-music 'MultiMeasureRestMusic
       'duration
       (ly:make-duration 0 0 num den)
       'articulations
       '())
))

\relative c' {
  \time 3/2
  \autoMMR
  c'1.

  \compoundMeter #'((1 4)(3 8))
  \autoMMR
  \repeat unfold 5 c8 \repeat unfold 10 c16
}

%<------------------------------

I know that applyContext creates its own "(make-music ..." block, so maybe there's some scoping issue I'm not aware of. Any further help would be greatly appreciated!

-Abraham
Reply | Threaded
Open this post in threaded view
|

Re: How to extract the current time signature

Urs Liska-3
[Reviving a pretty ancient thread]

Hi Abraham and Harm (and others),

Am 22.01.15 um 14:17 schrieb tisimst:

> Harm,
>
>
> Thomas Morley-2 wrote
>> Maybe:
>>
>> \version "2.19.15"
>>
>> printTimeSignatureFraction =
>> \applyContext #(lambda (ctx)
>>    (let* ((context
>>             (ly:context-property-where-defined ctx 'timeSignatureFraction))
>>           (time-sig-frac
>>             (ly:context-property context 'timeSignatureFraction)))
>>    (display time-sig-frac)))
>>
>> \relative c' {
>>      \time 3/2
>>      \printTimeSignatureFraction % => (3 . 2)
>>      c''1
>>          \compoundMeter #'((1 4) (3 8))
>>      \printTimeSignatureFraction % => (5 . 8) !!
>>          \repeat unfold 5 c8 \repeat unfold 10 c16
>> }
>>
>> Though the compound TimeSig will return "summarized"
>>
>> Cheers,
>>    Harm
> That works great! Thanks so much for your help. Perhaps I should have
> mentioned it in the original post, but I'd like to be able to use the values
> in time-sig-frac to automatically make a MultiMeasureRest with the duration
> of the full measure, but when I attempt to do so, nothing gets added to my
> score. Here's my latest and greatest:
>
> %<------------------------------
>
> \version "2.18.2"
>
> autoMMR =
> \applyContext #(lambda (ctx)
>    (let* ((context
>             (ly:context-property-where-defined ctx 'timeSignatureFraction))
>           (time-sig-frac
>             (ly:context-property context 'timeSignatureFraction))
>           (num (car time-sig-frac))
>           (den (cdr time-sig-frac)))
>      (make-music 'MultiMeasureRestMusic
>         'duration
>         (ly:make-duration 0 0 num den)
>         'articulations
>         '())
> ))
>
> \relative c' {
>    \time 3/2
>    \autoMMR
>    c'1.
>
>    \compoundMeter #'((1 4)(3 8))
>    \autoMMR
>    \repeat unfold 5 c8 \repeat unfold 10 c16
> }
>
> %<------------------------------
>
> I know that applyContext creates its own "(make-music ..." block, so maybe
> there's some scoping issue I'm not aware of. Any further help would be
> greatly appreciated!
>
> -Abraham
>
I've just run into the very same issue (also trying to create a MMR for
the current measure's duration.

Looking at the code examples above I'm pretty sure the problem is not a
"scoping" but a "timing" issue - I think \applyContext performs the
context lookup long after the MMR has been created. This seems pretty
clear because at the time a music-function is interpreted (and the
duration would be needed to create the MMR) it is not clear where this
music will end up. Consider the case when you define this in a variable
which you'll then reuse multiple times (possibly starting at different
moments in a measure or wrapped in \scaleDurations or \tuplet-s).

So while I get why this doesn't work that way, is there any chance to
create a one-measure MMR from a music-function?

My use case is that I want to align an arbitrary markup (or music of
arbitrary length) with a measure by (ab)using the MMR, I don't want to
require a duration argument to the music function, and making it
optional seems to interfere with the rest of the function signature.

Urs


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

Re: How to extract the current time signature

David Kastrup
Urs Liska <[hidden email]> writes:

> [Reviving a pretty ancient thread]
>
> Hi Abraham and Harm (and others),
>
> Am 22.01.15 um 14:17 schrieb tisimst:
>> Harm,
>>
>>
>> Thomas Morley-2 wrote
>>> Maybe:
>>>
>>> \version "2.19.15"
>>>
>>> printTimeSignatureFraction =
>>> \applyContext #(lambda (ctx)
>>>    (let* ((context
>>>             (ly:context-property-where-defined ctx 'timeSignatureFraction))
>>>           (time-sig-frac
>>>             (ly:context-property context 'timeSignatureFraction)))
>>>    (display time-sig-frac)))

This is completely unrelated but this code is nonsensical.  It's
identical to

printTimeSignatureFraction =
\applyContext #(lambda (ctx)
   (let* ((time-sig-frac
            (ly:context-property ctx 'timeSignatureFraction)))
     (display time-sig-frac)))

since context property lookups are hierarchical/inherited.  There is no
point in finding out just _which_ parent context defined
timeSignatureFraction for reading it.  If you are planning to rewrite
it, there is some incentive to do it at the level you got it from.  But
for reading, this is pointless.

--
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: How to extract the current time signature

David Kastrup
In reply to this post by Urs Liska-3
Urs Liska <[hidden email]> writes:

> [Reviving a pretty ancient thread]

>> That works great! Thanks so much for your help. Perhaps I should have
>> mentioned it in the original post, but I'd like to be able to use the values
>> in time-sig-frac to automatically make a MultiMeasureRest with the duration
>> of the full measure, but when I attempt to do so, nothing gets added to my
>> score. Here's my latest and greatest:
>>
> I've just run into the very same issue (also trying to create a MMR
> for the current measure's duration.
>
> Looking at the code examples above I'm pretty sure the problem is not
> a "scoping" but a "timing" issue - I think \applyContext performs the
> context lookup long after the MMR has been created. This seems pretty
> clear because at the time a music-function is interpreted (and the
> duration would be needed to create the MMR) it is not clear where this
> music will end up. Consider the case when you define this in a
> variable which you'll then reuse multiple times (possibly starting at
> different moments in a measure or wrapped in \scaleDurations or
> \tuplet-s).
>
> So while I get why this doesn't work that way, is there any chance to
> create a one-measure MMR from a music-function?

You could try sequential music with an elements-callback field.  That
callback is called at a time for producing a list of music expressions
when a context is available.  Unfortunately, it does not get to see more
than the original music expression and thus has no idea about current
properties either.  But the first element it produces can be an
\applyContext that fetches the required information and modifies the
second element then which could be the MMR.

--
David Kastrup

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