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 05:41:34 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Stefan Thomas <kontrapunktstefan <at> googlemail.com> writes:
> 
> Dear Lilypond-users, I have in mind an input like:\relative { \brokenoctaves
{c d e f g }}and the desired output is:\relative { c c' d d' e e' f f' g g' }Can
this be done automatically?
> 

Play with this see if it does what you want.

-----Jay

\version "2.11.52"

#(define (get-pitches mus)
  (map
    (lambda (x)
      (ly:music-property (car (ly:music-property x 'elements)) 'pitch))
    (ly:music-property mus 'elements)))

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

#(define (interleave-lists l1 l2)
  (cond ((null? l1) l2)
        ((null? l2) l1)
        ((and (null? l1) (null? l2)) '())
        (else (cons (car l1) (cons (car l2) (interleave-lists (cdr l1) (cdr
l2)))))))

#(define (interleave-music m1 m2)
  (make-sequential-music
    (interleave-lists (ly:music-property m1 'elements) (ly:music-property m2
'elements))))

#(define (create-music-list pitches duration)
  (make-sequential-music
    (map
      (lambda (p)
        (make-music
          'EventChord
          'elements
          (list (make-music
                  'NoteEvent
                  'duration duration
                  'pitch p))))
      pitches)))

#(define (transpose-all-but-first pitches amt)
  (cons (car pitches) (map
    (lambda (pitch)
      (ly:make-pitch
        (+ amt (ly:pitch-octave pitch))
        (ly:pitch-notename pitch)
        (ly:pitch-alteration pitch)))
    (cdr pitches))))

#(define (set-octave pitches octave)
  (map
    (lambda (pitch) (ly:make-pitch octave (ly:pitch-notename pitch)
(ly:pitch-alteration pitch)))
    pitches))

brokenoctaves = #(define-music-function (parser location dur arg mus) (integer?
integer? ly:music?)
  (let* ((pitches (get-pitches mus))
         (duration (ly:make-duration dur 0 1 1)))
    (interleave-music
      (create-music-list (transpose-all-but-first pitches (- arg)) duration)
      (create-music-list (set-octave pitches (1- arg)) duration))))

\score
{
  \new Staff \relative c'
  {
    %First argument is the duration (3 - eight, 4 - sixteenth, etc.).
    %Second argument is 1 for up and -1 for down.
    %Third argument is the music
    %
    %Shortcomings:
    % - Next note after \brokenoctave section is in the wrong octave
    %   compared with what one would expect in relative mode.
    \brokenoctaves #3 #1 { c d e f g c, c' c,}
    \brokenoctaves #3 #-1 { c, d e f g c, c' c,}
  }
}






reply via email to

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