lilypond-user
[Top][All Lists]
Advanced

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

Re: Function to add a drone staff?


From: Gilles
Subject: Re: Function to add a drone staff?
Date: Fri, 10 Apr 2015 16:01:36 +0200
User-agent: Scarlet Webmail

Hi.

Thanks a lot for your efforts.
[I'm ashamed I never got to learn the internals of LilyPond for
the very rare cases where the software did not already provide
the best solution.]

On Thu, 9 Apr 2015 20:11:25 -0700 (MST), Paul Morris wrote:
Gilles Sadowski wrote
With the "manual" drone, one writes ties between
the notes; is it possible to add it to the function?

Well, the first thing I tried was to just add a tie to every note like so:

dronify =
#(define-music-function (parser location drone melody)
   (ly:pitch? ly:music?)
   (music-map
    (lambda (m)
      (if (ly:pitch? (ly:music-property m 'pitch))
          (begin
           (ly:music-set-property! m 'pitch drone)
           (ly:music-set-property! m 'articulations
             (list (make-music (quote TieEvent))))))
      m)
    melody))

But that led to "warning: unterminated tie" any time there was a rest. So I came up with the following, which is not that elegant, but seems to get the job done and without warnings. No guarantees on how robust it is with
actual music.

It works but the sound is still cut after every bar: It looks like no
tie was added to the last note of a bar.

What is the advantage of using "\makeOctaves" wrt having two "\dronify"?


Thanks and best regards,
Gilles



%%%%%%%%%%%%%%%%%%%%%%%%%%

\version "2.18.2"

dronify =
#(define-music-function (parser location drone melody)
   (ly:pitch? ly:music?)
   (let* ((prev #{ #})
          (current #{ #})
          (art '())
          (drone-part
           (music-map
            (lambda (m)
              (set! prev current)

              (if (and (music-is-of-type? m 'note-event)
                       (ly:pitch? (ly:music-property m 'pitch)))
                  ;; change the pitch
                  (begin
                   (ly:music-set-property! m 'pitch drone)
                   (if (and (music-is-of-type? prev 'note-event)
(ly:pitch? (ly:music-property prev 'pitch)))
                       ;; add tie to previous note
                       ;; avoid overwriting existing articulations
                       (begin
(set! art (ly:music-property prev 'articulations))
                        (ly:music-set-property! prev 'articulations
                          (append art (list (make-music (quote
TieEvent)))))))))

              (set! current m)
              prev)
            melody)))
     #{ #drone-part #current #}))


#(define (octave-up m t)
   (let* ((octave (1- t))
          (new-note (ly:music-deep-copy m))
          (new-pitch (ly:make-pitch
                      octave
(ly:pitch-notename (ly:music-property m 'pitch)) (ly:pitch-alteration (ly:music-property m 'pitch)))))
     (set! (ly:music-property new-note 'pitch) new-pitch)
     new-note))

#(define (octavize-chord elements t)
   (cond ((null? elements) elements)
     ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
      (cons (car elements)
        (cons (octave-up (car elements) t)
          (octavize-chord (cdr elements) t))))
(else (cons (car elements) (octavize-chord (cdr elements ) t)))))

#(define (octavize music t)
   (if (eq? (ly:music-property music 'name) 'EventChord)
       (ly:music-set-property! music 'elements (octavize-chord
(ly:music-property music
'elements) t)))
   music)

makeOctaves = #(define-music-function (parser location arg mus) (integer?
ly:music?)
(music-map (lambda (x) (octavize x arg)) (event-chord-wrap!
mus)))

melody = \relative f' {
  c4 d c8( d8) r4
  g4\staccato a r b4
}

<<
  \melody
  \makeOctaves #1 \dronify g \melody





reply via email to

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