[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: rhythm shift
From: |
Gilles THIBAULT |
Subject: |
Re: rhythm shift |
Date: |
Mon, 28 Mar 2016 18:11 +0200 |
User-agent: |
KMail/4.14.5 (Linux/4.1.15-desktop-2.mga5; KDE/4.14.5; x86_64; ; ) |
> \time 2/4
> r4 a4 ~ |
> a4 b4 ~|
> b4 r4
> How can I shift (convert) it to:
> \time 2/4
> a2 |
> b2 |
> r4
For "shifting" rhythm, you can use this snippet :
http://lsr.di.unimi.it/LSR/Item?id=542
To transform 2 tied notes into a single note, you have to make your own
function...
----------------------------------------------------------------------------
\include "extractMusic.ly"
%% to download here
%% http://gillesth.free.fr/Lilypond/extractMusic/
#(define (name-of music)
(ly:music-property music 'name))
%% TODO: this function probably does not work with chords -:(
twoTiedNotesToOneNote = #(define-music-function (parser location music)
(ly:music?)
"Transform 2 tied notes in a note with a length equal to the sum of their
lengths"
(let loop ((notes (reverse ;; easier for managing multiple tied notes)
(extract-named-music music 'NoteEvent ;; 'EventChords
))))
(if (or (null? notes)(null? (cdr notes)))
(music-filter (lambda(mus)(not (eq? 'Music (name-of mus))))
music)
(let ((note1 (first notes))
(note2 (second notes)))
;; (display "-------------"\n)
;; (display-scheme-music note1)
;; (display-scheme-music note2)
(if (pair? (extract-named-music note2 'TieEvent))
(let* ((mom1 (ly:music-length note1))
(mom2 (ly:music-length note2))
(new-mom2 (ly:moment-add mom1 mom2))
;; the following moment->rhythm function
;; is defined in "extractMusic.ly"
(new-dur2 (moment->rhythm new-mom2)))
(ly:music-set-property! note2 'duration new-dur2)
(ly:music-set-property! note2 'articulations
(filter (lambda(mus)(not (eq? 'TieEvent (name-of mus))))
(ly:music-property note2 'articulations)))
;; (set! note1 (ly:make-music 'Music)) ;; doesn't work...
(ly:music-set-property! note1 'name 'Music)))
;; well, changing the property 'name is not "standard"
(loop (cdr notes))))))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
music = {
\time 2/4
r4 a4-"4" ~
a4-"3" b4-"2" ~
b4-"1" r4
}
\new Staff \music
\new Staff {
\time 2/4
\extractEnd
\twoTiedNotesToOneNote \music
s4
}
music = \relative c' {
s2. s8. d16 ~ % 31
d8. d16 ~ d8 b'16 b16 ~ b16 b8 b16 ~ b16 b8 b16 ~ % 32
b8 a16 g16 ~ g4
}
\new Staff \music
\new Staff {
\extractEnd
\twoTiedNotesToOneNote \music
{ s2. s8. }
}
--------------------------------------------------------------
Note that if you "shift" rhythm, you have to delete barcheck |
--
Gilles
- rhythm shift, Gianmaria Lari, 2016/03/25
- Re: rhythm shift,
Gilles THIBAULT <=