lilypond-user
[Top][All Lists]
Advanced

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

Re: broken octaves


From: Jay Anderson
Subject: Re: broken octaves
Date: Sat, 26 Jul 2008 11:43:04 -0700

On Sat, Jul 26, 2008 at 1:56 AM, Dominic Neumann <address@hidden> wrote:
> Hi Jay,
>
> nice example! But I think it would be even better if I could write
> \brokenoctaves #1 { c4 d e f g8 a b c } meaning that the function also
> recognizes the durations of the notes.
> Maybe you could be so kind to explain how your functions work. Then we
> could also learn from it and possibly improve it. Is that possible?
>

I've rewritten it from scratch below where it uses the lengths of the
input notes and works with chords. It still has problems (dynamics
doubled, tuplets or nested structures don't work), but I'll try to
explain it.

The first note of the first chord needs to be unmodified. All second
notes are in octave arg-1. If arg is 1 we get '0'. '0' means go up an
octave, '-2' means go down an octave, '-1' means stay in the current
octave. The next input note we come to needs to be moved to <current
octave>-arg. So if arg is '1' and the current octave of the note is -1
we end up with -2 which means go down an octave from the previous
note. I'm sure that's clear as mud.

Essentially it loops through the list of chords applying the octave
logic from above. Normally to cover tuplets I'd use music-map, but
here we're adding notes after current notes instead of just modifying
notes. I'm sure there's a clean way to do it, but I haven't tried too
much yet.

-----Jay

\version "2.11.52"

#(define (make-sequential-music elements)
  (make-music
    'SequentialMusic
    'elements
    elements))

#(define (make-music-note pitch duration)
  (make-music
    'NoteEvent
    'pitch pitch
    'duration duration))

#(define (make-music-chord elements)
  (make-music
    'EventChord
    'elements elements))

#(define (broken-octaves muslist arg first?)
  (if (null? muslist) '()
    (let* ((notes (ly:music-property (car muslist) 'elements))
          (pitch (ly:music-property (car notes) 'pitch))
          (first-pitch
            (if first?
              pitch
              (ly:make-pitch
                (+ (- arg) (ly:pitch-octave pitch))
                (ly:pitch-notename pitch)
                (ly:pitch-alteration pitch))))
          (second-pitch (ly:make-pitch (1- arg) (ly:pitch-notename
pitch) (ly:pitch-alteration pitch)))
          (duration (ly:music-property (car notes) 'duration))
          (first-chord
            (make-music-chord
              (cons (make-music-note first-pitch duration) (cdr notes))))
          (second-chord
            (make-music-chord
              (cons (make-music-note second-pitch duration)
(ly:music-deep-copy (cdr notes))))))
      (cons first-chord (cons second-chord (broken-octaves (cdr
muslist) arg #f))))))

brokenoctaves = #(define-music-function (parser location arg mus)
(integer? ly:music?)
  (make-sequential-music (broken-octaves (ly:music-property mus
'elements) arg #t)))

\score
{
  \new Staff \relative c'
  {
    %first argument is 1 for up and -1 for down.
    %second argument is the music
    %
    %Shortcomings:
    % - Next note after \brokenoctave section is in the wrong octave.
    % - dynamics are copied to second note.
    % - tuplets don't work.
    \brokenoctaves #1 { <c e>4( d e f g8)\f c, c' c,}
  }
}




reply via email to

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