lilypond-user
[Top][All Lists]
Advanced

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

Re: problems with a difficult function


From: David Kastrup
Subject: Re: problems with a difficult function
Date: Fri, 26 Jul 2013 13:30:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Mark Polesky <address@hidden> writes:

> Hi everyone,
>
> I'm trying to write a function to deal with a peculiar problem;
> I've tried everything I know and I've hit the wall.
>
> I know it's weird, but the function would do this:
>
> 1) connect contiguous notes with glissandos
> 2) replace tied notes with spacers (except the first in a series),
>    thus allowing glissandos to pass over the spacers
> 3) do the same with chords
>
> The attached png makes it easier to see what I'm describing.
>
> Task #1 above has been solved, thanks to the kind help of David
> Kastrup.  (see the "glissandoize" function below).  However, the
> other tasks continue to elude me, after many hours of trying to
> solve them.  I sort of solved #2 for very simple cases, but my
> solution utterly fails when things like tuplets get in the way.
>
> Any help or advice would be greatly appreciated.

Well, this still does not work completely in the case of (repeat?)
chords, but it should at least be some step in the right direction, and
with suitable use of \displayMusic you should be able to figure out
where things go wrong.

untier =
#(define-music-function (parser location music) (ly:music?)
   (let ((tied #f))
     (let loop ((music music))
       (map-some-music
        (lambda (m)
          (cond
           ((music-is-of-type? m 'tie-event)
            (set! tied #t)
            (make-music 'TextScriptEvent 'text ""))
           ((not tied) #f)
           ((music-is-of-type? m 'note-event)
            (set! tied #f)
            (loop
             (apply make-music 'SkipEvent
                    (flatten-alist
                     (alist-delete 'pitch (ly:music-mutable-properties m))))))
           ((music-is-of-type? m 'event-chord)
            (if (ly:duration? (ly:music-property m 'duration))
                ;; repeat chord
                (loop
                 (make-music 'SkipEvent
                             'articulations
                             (append (ly:music-property m 'elements)
                                     (ly:music-property m 'articulations))))
                (begin
                  (set! (ly:music-property m 'elements)
                        (map-in-order
                         (lambda (m)
                           (if (music-is-of-type? m 'rhythmic-event)
                               (set! tied #t))
                           (loop m))
                         (ly:music-property m 'elements)))
                  m)))
           (else #f)))
        music))))


glissandoize =
#(define-music-function
   (p l music)
   (ly:music?)
   (let ((rh (extract-typed-music music '(event-chord note-event))))
     (if (pair? rh) 
       (for-each (lambda (a b)
                   (if (or (and (music-is-of-type? a 'note-event)
                                (music-is-of-type? b 'note-event))
                           (and (music-is-of-type? a 'event-chord)
                                (music-is-of-type? b 'event-chord)))
                     (set! (ly:music-property a 'articulations)
                       (cons (ly:music-deep-copy glissando)
                             (ly:music-property a 'articulations)))))
                 rh (cdr rh))))
   music)

\relative f' {
  \glissandoize \untier {
    % glissandos work with single notes
    \tuplet 3/2 { f8 g a~ } a4~
    \tuplet 3/2 { a8 g f~ } f8 r

    % but not with chords
    \tuplet 3/2 { <f a>8 <g b> <a c>~ } q4~
    \tuplet 3/2 { q8 <g b> <f a>~ } q8 r
  }
}

-- 
David Kastrup

reply via email to

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