lilypond-devel
[Top][All Lists]
Advanced

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

TimeSignature with note in denominator


From: Kieren MacMillan
Subject: TimeSignature with note in denominator
Date: Mon, 8 Nov 2021 14:36:37 -0500

Hello all,

For my first official patch as a Lily-dev, I’m proposing to make the result of 
<https://lsr.di.unimi.it/LSR/Snippet?id=642> an official #'style in 
TimeSignature. Carl has been mentoring me off-list, but we both thought it 
might be a good time to move the discussion back on-list.

The ultimate goal is for an input like

    \override TimeSignature.style = #'note-denom
    \time #'(1 . "4.")

to output a 1/q. [where 'q' is standing in for a quarter note glyph]. The 
snippet already does a lot of the work, so I’m planning to base my code on that.

As a first step, I’m trying to convert the snippet to work in 2.22+ with all 
its improvements/changes. So far, I have this:

%%%  SNIPPET BEGINS
\version "2.22.1"

time =
#(define-music-function (beat-structure fraction)
  ((number-list? '()) pair?)
  (_i "Set @var{fraction} as time signature, with optional
number list @var{beat-structure} before it.")
 (make-music 'TimeSignatureMusic
             'numerator (car fraction)
             'denominator (cdr fraction)
             'beat-structure beat-structure))

#(define-public (format-time-sig-note grob)
  (let* ((frac (ly:grob-property grob 'fraction))
         (num (if (pair? frac) (car frac) 4))
         (den (if (pair? frac) (cdr frac) 4))
         (m (markup #:override '(baseline-skip . 0.5)
                    #:center-column (#:number (number->string num)
                                              #:override '(style . default)
                                              #:note (ly:make-duration 
(inexact->exact (/ (log den) (log 2))) 0 1) DOWN))))
    (grob-interpret-markup grob m)))

{
 \override Staff.TimeSignature.stencil = #format-time-sig-note
 \time #'(2 . 4)
 \repeat unfold 4 c'4

 \time #'(3 . 1)
 \repeat unfold 3 c'1

 \time #'(3 . 16)
 \repeat unfold 4 c'8.  
}
%%%  SNIPPET ENDS

Notes/Questions:

1. I’ve modified \time to accept a pair instead of a fraction — this is not 
strictly necessary for the examples shown, but is in anticipation of allowing 
the second value to be a string (e.g., "4.") or dotted duration (?). Does this 
plan make the most sense (especially with respect to backwards compatibility, 
which I believe is maintained here?) or is there a better way?

2. Is

  #:note (ly:make-duration (inexact->exact (/ (log den) (log 2))) 0 1) DOWN

the best way to accomplish what I want *at this point*? (Yes, I know it won’t 
handle strings and dotted values yet… I’m just looking for comments about the 
code I’ve used to turn a denominator integer into the note-log value.

3. Is there an ly:string->duration [or similar] function, that will take "4." 
and turn it into a duration that I can use to generate the right glyph(s)?

Thanks!
Kieren.
________________________________

Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kieren@kierenmacmillan.info




reply via email to

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