Adding parallel thirds to the notes of a melody

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

Adding parallel thirds to the notes of a melody

Gianmaria Lari
The following "test" function adds parallel thirds to the notes of a melody:

\version "2.21.0"
scale = {c d e f g a b}
test  = 
#(define-music-function (music) (ly:music?) 
   #{ 
     \partCombine $music \modalTranspose c e \scale $music
   #})

\test {\voiceOne a b c'}

I don't have lilypond programming experience and I would like to know:

- if there are hidden mistakes
- if it is better to write the function in a different way
- how I could avoid to write \voiceOne in \test {\voiceOne a b c'}
- how I can encapsulate scale, inside the "test" function

Thank you, g.

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

Re: Adding parallel thirds to the notes of a melody

Valentin Villenave-3
On 4/3/19, Gianmaria Lari <[hidden email]> wrote:
> I don't have lilypond programming experience and I would like to know:
> - if there are hidden mistakes

No, that’s quite clean actually!

> - if it is better to write the function in a different way

I think in this case, simpler is better.

> - how I could avoid to write \voiceOne in \test {\voiceOne a b c'}

Just invert the order of the arguments to \partCombine: first the
uppermost (transposed) music, then the original music.

> - how I can encapsulate scale, inside the "test" function

You can use a "local" (which means temporary, just for the scope of a
single function) variable, defined with "let":

%%%%
\version "2.21.0"
test  =
#(define-music-function (music) (ly:music?)
   (let ((scale #{ c d e f g a b #}))
     #{
       \partCombine
         \modalTranspose c e $scale $music
         $music
     #}))

\test { a b c'}

%%%%

See "Local Bindings" in
https://www.gnu.org/software/guile/manual/html_node/Local-Bindings.html#Local-Bindings

Cheers,
V.

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

Re: Adding parallel thirds to the notes of a melody

Mark Knoop-4
In reply to this post by Gianmaria Lari

At 07:15 on 03 Apr 2019, Gianmaria Lari wrote:

> The following "test" function adds parallel thirds to the notes of a
> melody:
>
> \version "2.21.0"
> scale = {c d e f g a b}
> test  =
> #(define-music-function (music) (ly:music?)
>    #{
>      \partCombine $music \modalTranspose c e \scale $music
>    #})
>
> \test {\voiceOne a b c'}
>
> I don't have lilypond programming experience and I would like to know:
>
> - if there are hidden mistakes
> - if it is better to write the function in a different way
> - how I could avoid to write \voiceOne in \test {\voiceOne a b c'}
> - how I can encapsulate scale, inside the "test" function

Funnily enough, I wrote something to do this last week, adapted from http://lsr.di.unimi.it/LSR/Item?id=445

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.19.82"
%% adapted from http://lsr.di.unimi.it/LSR/Item?id=445

#(define (third-up m)
   (let* ((new-note (ly:music-deep-copy m))
          (new-pitch (ly:pitch-transpose
                      (ly:music-property m 'pitch)
                      (ly:make-pitch 0 2 0))))
     (set! (ly:music-property new-note 'pitch) new-pitch)
     new-note))

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

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

makeThirds =
#(define-music-function
   (mus)
   (ly:music?)
   (music-map (lambda (x)
                (addthird x)) (event-chord-wrap! mus)))

\makeThirds {
  \clef bass
  dis8( e dis)~ dis8.( cis16 b8 ais gis dis) cis( dis <dis gis>)
  c d e fis gis aes bes c'
  \clef treble
  bes des' ees' f' g' a' b' c'' d'' e'' fis''
  <f c'>
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

--
Mark Knoop

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

Re: Adding parallel thirds to the notes of a melody

Aaron Hill
In reply to this post by Gianmaria Lari
On 2019-04-02 11:15 pm, Gianmaria Lari wrote:

> The following "test" function adds parallel thirds to the notes of a
> melody:
>
> \version "2.21.0"
> scale = {c d e f g a b}
> test  =
> #(define-music-function (music) (ly:music?)
>    #{
>      \partCombine $music \modalTranspose c e \scale $music
>    #})
>
> \test {\voiceOne a b c'}
>
> I don't have lilypond programming experience and I would like to know:
>
> - if there are hidden mistakes
> - if it is better to write the function in a different way
> - how I could avoid to write \voiceOne in \test {\voiceOne a b c'}
> - how I can encapsulate scale, inside the "test" function
In keeping with my predilection for over-engineering, here is my take on
your function:

%%%%
\version "2.19.82"

autoParallel =
#(define-music-function (root scale target music)
   (ly:pitch? number-pair-list? ly:pitch? ly:music?)
   (let* ((rscale #{ \transpose c $root { $@(map
            (lambda (x) (ly:make-pitch 0 (car x) (cdr x))) scale) } #})
          (transposed #{ \modalTranspose $root $target $rscale $music
#}))
     (if (ly:pitch<? root target)
       #{ \partcombine $transposed $music #}
       #{ \partcombine $music $transposed #})))

pentatonic = #`((0 . 0) (1 . 0) (2 . 0) (4 . 0) (5 . 0))

{
   \autoParallel c \major e \fixed c' { e8 f g d e d c4 }
   \autoParallel e \minor g, \fixed c'' { c8 d e fis g4 e4 }
   \autoParallel bes \pentatonic f' \fixed c' { f4 g16 bes c8 d4 f16 g
bes,8 }
}
%%%%

This is a little more verbose in usage, but it lets you easily specify
which scale you want using the built-in scale definitions (e.g.
\mixolydian, \phrygian, etc.) or by creating your own as demonstrated.

It also detects whether the harmony will be above or below and will
\partcombine appropriately.

NOTE: I only use 2.19 currently, so I still have to write \partcombine
instead of \partCombine.


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

auto-parallel.cropped.png (15K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adding parallel thirds to the notes of a melody

Gianmaria Lari
Thank you to everybody for your code !!
... and especially to Valentin for the comments about my code.
g.

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