[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
routine pour arpèges ou accords
From: |
jp lanquetin |
Subject: |
routine pour arpèges ou accords |
Date: |
Thu, 23 Apr 2009 09:55:29 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Windows/20090302) |
Bonjour,
Avec ma formation de programmeur, je suis persuadé
qu'on peut dans Lilypond utiliser un système analogue
aux routines ou sous-programmes ( ou encore fonctions )
qui permette une économie de notation, et qui confectionne le code
complet à partir d'éléments synthètiques comme :
arpège ( do ) ==> do8 mi sol mi sol mi
ou bien
arpège (do mi sol ; 1 2 3 2 3 2 ) ==> do mi sol mi sol mi
ou bien valse ( do : m ) ==> do4 <mib sol> <mib sol>
pour faire simple
je suis tombé sur un morceau de code nommé rhythm.ly
qui ressemble furieusement à ce que je cherche, mais comment
l'utiliser ?
Merci de toute piste
J.P. LANQUETIN
\version "2.11.37 " %%devrait marcher aussi pour la 2.10
#(define rhythmVectorIndex 0)
#(define (transformEachNote chordElt rhythmVector)
(begin
(if (eq? 'NoteEvent (ly:music-property chordElt 'name))
(set! (ly:music-property chordElt 'duration) (vector-ref
rhythmVector rhythmVectorIndex))
)
chordElt
))
#(define (getChords musicElt rhythmVector)
(begin
(if (eq? 'EventChord (ly:music-property musicElt 'name))
(begin
(map
(lambda (x) (transformEachNote x rhythmVector))
(ly:music-property musicElt 'elements)
)
(set! rhythmVectorIndex (1+ rhythmVectorIndex))
(if (= rhythmVectorIndex (vector-length rhythmVector))
(set! rhythmVectorIndex 0))
)
)
musicElt
))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#(define (string->duration strElt)
(
let*(
(ptindex (string-index strElt #\. ))
;; position of "." in
"4." for exemple. #f if no ".".
(ptnumber 0)
(val (string->number (if ptindex (substring strElt 0 ptindex)
strElt)))
;; val = 1 2 4 8 ...
(without the ".")
(dur (ly:intlog2 val))
;; dur = 0 1 2 3 ...
(need for ly:make-duration)
)
;; find the number of
"." in Duration
(while ptindex (
begin
(set! ptnumber (1+ ptnumber))
(set! ptindex (string-index strElt #\. (1+ ptindex) ))
)
)
(ly:make-duration dur ptnumber 1 1)
))
#(define (string->vectorDuration str)
( let* (
(i 0)
(strList (string-split str #\space ))
(len (length strList))
(v (make-vector len))
)
(map
(lambda (x)
(begin
(vector-set! v i (string->duration x))
(set! i (1+ i))
)
x
)
strList
)
v
))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
makeRhythm = #(define-music-function (parser location m str) (ly:music?
string?)
( let* (
(prevWasSpace #t)
(trimmedStr
(string-delete
(string-trim-right str)
(lambda (c)
( let*
(
(currentIsSpace
(char=? c #\space))
(res (and
prevWasSpace currentIsSpace))
)
(if (not res) (set!
prevWasSpace currentIsSpace))
res
)
)
)
)
)
(set! rhythmVectorIndex 0)
(music-map
(lambda (x)
(getChords x (string->vectorDuration trimmedStr)))
m
)
))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- routine pour arpèges ou accords,
jp lanquetin <=