On Wed, Dec 06, 2006 at 09:05:53PM +0100, [EMAIL PROTECTED] wrote:

[...]

> The first thing to do is to observe what the input music looks like, and
> what the output of your function should look like, using
> \displayMusic. The purpose of your function will then be to transform
> one into the other.
> 
>   \displayMusic <ees bes' d>4
>   \displayMusic { \tag #'tab {<ees bes' d>4}
>                   \tag #'score {<ees bes' d>8 ~ <ees bes' d>} }

Thank you Nicolas I found a way to do that.

For those who might be interrested, as an attachment you con find the
code to do this.

Maybe the code is ugly (my first scheme routine) and may be enhenced.
I thing about:
        - use relative music whitout being messed u by octave shifts
        - abbility to change tags 
        - put all in a scm file instead of a ly one
        - maybe more...

-- 
Sebastien Gross
% Chezwam lilypond Scheme functions 
%
% (c) 2006 Sebastien Gross <seb(HyPhEn)lily[At]chezwam{dOt}org>
% GPL

\version "2.11.0"
%{
"Create separate rhythm notation for both guitar tablature @var{tab}
and score @var{score} rhythms for a chord @var{chord}.
Notes are tieded together respecting @var{tab} and @var{score} rhythms.

The tablature part is tagged as 'tab and the score part is tagged as
'score.

Example:

        melody = \relative c { 
                c e g b \TabRhytm <c e g> { r4.. } { r16 r8 r4 } b g e c
        }

        % \melody would be expanded to:
        %
        % { c e g b {
        %               \tag #'tab { < c e g >4.. }
        %               \tag #'score { < c e g >16 ~  < c e g >8 ~  < c e g >4 
} }
        %       b g e c }


        \score {
        <<
            \new Staff { \keepWithTag #'score \melody }
        \new TabStaff { \keepWithTag #'tab \melody }
        >>
    \layout{
    }
        }


Please note @var{chord} is interpreted as non-relative music. So check
your octaves :-).

"
%}
TabRhytm = #(define-music-function (parser location chord tab score)
        (ly:music? ly:music? ly:music?)

        (define (get-duration d)
                (if
                        (not (list? d))
                        (if
                                (equal? (ly:music-property d 'name) 
'SequentialMusic)
                                (get-duration (ly:music-property d 'elements))
                                (get-duration (list d)))
                        ; d is a list (of RestEvent)
                        (let ((result '() ))
                                (do ((ptr d (cdr ptr)))
                                        ((null? ptr))
                                        (set! result
                                                (append result
                                                        (list 
                                                                
(ly:music-property
                                                                        (first 
(ly:music-property (car ptr) 'elements))
                                                                'duration)))))
                         result)))

        (define (set-durations ch d)
                (let*
                        ((me (ly:music-property ch 'elements))
                         (result '()))
                        (do ((ptr d (cdr ptr)))
                                ((null? ptr))
                                (let*
                                        ((nc  (ly:music-deep-copy ch)))
                                        (for-each (lambda (e)
                                                (ly:music-set-property! e 
'duration (car ptr)))
                                                (ly:music-property nc 
'elements))
                                        (if (not (null? (cdr ptr)))
                                (set! (ly:music-property nc 'elements) (append
                                                        (ly:music-property nc 
'elements)
                                                        (list (make-music 
'TieEvent)))))
                                        (set! result (append result (list  
nc)))))
                        result))

        (let*
                ((dtab (get-duration tab))
                 (dscore (get-duration score))
                 (mus (make-music
                        'SequentialMusic
                        'elements
                                (list
                                        (make-music
                                                'SequentialMusic
                                                'tags
                                                (list (quote tab))
                                                'elements
                                                (set-durations chord dtab))
                                        (make-music
                                                'SequentialMusic
                                                'tags
                                                (list (quote score))
                                                'elements
                                                (set-durations chord 
dscore))))))
                (make-music 'UnrelativableMusic 'element mus))
                                                
                                                )


% vim:ts=2:
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to