lilypond-user
[Top][All Lists]
Advanced

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

Should \partial accept music instead of duration?


From: Aaron Hill
Subject: Should \partial accept music instead of duration?
Date: Sat, 19 Mar 2022 16:02:23 -0700

Here would be a possible refactoring:

%%%%
\version "2.22.0"

partial =
#(define-music-function (mus) (ly:music?)
  (_i "Make a partial measure.")
  (let* ((mom (ly:music-length mus))
         (dur (make-duration-of-length mom)))
    (make-music 'SequentialMusic
      'elements
      (list (context-spec-music
              (make-music 'PartialSet
                          'origin (*location*)
                          'duration dur)
              'Timing)
        mus))))


\fixed c' {
  \time 3/4
  \partial { g8 a4 }
  | g2. \bar "||"
  \partial { \grace { g16 } a8 b }
  | a2. \bar "||"
  \partial \tuplet 3/2 { g8 fis }
  | g2. \bar "|."
}
%%%%

A convert-ly rule would probably not be possible given the limited power of regular expressions. As such, \partial might need to support both duration and music arguments. Initially I thought this might not be possible, given that a naked duration can be treated as music; but the following does seem to work:

%%%%
\version "2.22.0"

#(define (duration-or-music? arg)
  (or (ly:duration? arg) (ly:music? arg)))

partial =
#(define-music-function (arg) (duration-or-music?)
  (_i "Make a partial measure.")
  (if (ly:duration? arg)
    (context-spec-music
      (make-music 'PartialSet
                  'origin (*location*)
                  'duration arg)
      'Timing)
    (let* ((mom (ly:music-length arg))
           (dur (make-duration-of-length mom)))
      (make-music 'SequentialMusic
        'elements
        (list (context-spec-music
                (make-music 'PartialSet
                            'origin (*location*)
                            'duration dur)
                'Timing)
          arg)))))


\fixed c' {
  \time 3/4
  \partial 4. g8 a4 %% Original syntax works.
  | g2. \bar "||"
  \partial { \grace { g16 } a8 b }
  | a2. \bar "||"
  \partial \tuplet 3/2 { g8 fis }
  | g2. \bar "|."
}
%%%%


-- Aaron Hill

Attachment: partial.cropped.png
Description: PNG image


reply via email to

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