On Monday 19 June 2006 16:02, Erik Sandberg wrote: > On 6/19/06, Han-Wen Nienhuys <[EMAIL PROTECTED]> wrote: > > Erik Sandberg schreef > > > BTW: May I change Sequential_iterator::get_music_list to return > > > something like scm_call_1 (get_music ()->get_property > > > ("child-list-callback"), get_music ()->self_scm ()); > > > ? > > > > > > This would make it possible to soft-code e.g. percent-repeat-iterator. > > > > > > but, all in all, I don't see what advantage this would get us. > > Custom iterators makes it easier to make music expressions more > abstract, in the sense that the current time-scaled-music is abstract > (one music expression can acts as an alias for a more complex pattern > of nested expressions). Writing a two-line Scheme function is IMHO > easier and more elegant than creating a new iterator C++ module. > > In most examples I've seen so far, customised Sequential-iterators > seem to be sufficient for abstracting music expressions.
The attached patch makes my proposed change to sequential-iterators, and uses this to clean up multi measure rests. The patch obsoletes the following: - glue-mm-rests - MultiMeasureRestMusicGroup - Sequential_music_iterator I know mm rests can be further cleaned up by creating spanner events, but I won't do that this time (IIRC you want to do some related cleanups of mm rests, and I want to avoid double work) -- Erik
Index: lily/sequential-iterator.cc =================================================================== RCS file: /sources/lilypond/lilypond/lily/sequential-iterator.cc,v retrieving revision 1.42 diff -u -r1.42 sequential-iterator.cc --- lily/sequential-iterator.cc 18 Jun 2006 12:57:37 -0000 1.42 +++ lily/sequential-iterator.cc 27 Jun 2006 06:11:15 -0000 @@ -42,7 +42,12 @@ SCM Sequential_iterator::get_music_list () const { - return SCM_EOL; + Music *m = get_music (); + SCM proc = m->get_property ("elements-callback"); + if (scm_procedure_p (proc)) + return scm_call_1 (proc, m->self_scm ()); + else + return SCM_EOL; } void Index: scm/define-music-types.scm =================================================================== RCS file: /sources/lilypond/lilypond/scm/define-music-types.scm,v retrieving revision 1.81 diff -u -r1.81 define-music-types.scm --- scm/define-music-types.scm 5 Jun 2006 13:57:05 -0000 1.81 +++ scm/define-music-types.scm 27 Jun 2006 06:11:15 -0000 @@ -7,6 +7,20 @@ ;; TODO: should link back into user manual. +(define (mm-rest-child-list music) + "Check if we have R1*4-\\markup { .. }, and if applicable convert to +a property set for MultiMeasureRestNumber." + (let ((location (ly:music-property music 'origin)) + (duration (ly:music-property music 'duration))) + (list (make-music 'BarCheck + 'origin location) + (make-event-chord (cons (make-music 'MultiMeasureRestEvent + 'origin location + 'duration duration) + (ly:music-property music 'articulations))) + (make-music 'BarCheck + 'origin location)))) + (define-public music-descriptions `( (AbsoluteDynamicEvent @@ -281,7 +295,16 @@ Syntax: @code{c4\\melisma d\\melismaEnd}.") (types . (general-music melisma-span-event event)) )) - + (MultiMeasureRestNew + . ( + (description . "Rests that may be compressed into Multi rests. + +Syntax [EMAIL PROTECTED] for 4 measures in 3/4 time.") + (iterator-ctor . ,ly:sequential-iterator::constructor) + (elements-callback . ,mm-rest-child-list) + (types . (general-music sequential-music)) + )) (MultiMeasureRestEvent . ( (description . "Rests that may be compressed into Multi rests. @@ -445,7 +468,8 @@ (length-callback . ,ly:music-sequence::cumulative-length-callback) (start-callback . ,ly:music-sequence::first-start-callback) - (iterator-ctor . ,ly:sequential-music-iterator::constructor) + (elements-callback . ,(lambda (m) (ly:music-property m 'elements))) + (iterator-ctor . ,ly:sequential-iterator::constructor) (types . (general-music sequential-music)) )) Index: scm/ly-syntax-constructors.scm =================================================================== RCS file: /sources/lilypond/lilypond/scm/ly-syntax-constructors.scm,v retrieving revision 1.2 diff -u -r1.2 ly-syntax-constructors.scm --- scm/ly-syntax-constructors.scm 13 Jun 2006 22:01:19 -0000 1.2 +++ scm/ly-syntax-constructors.scm 27 Jun 2006 06:11:15 -0000 @@ -85,9 +85,27 @@ (define-ly-syntax-simple (repeat type num body alts) (make-repeat type num body alts)) +(define (script-to-mmrest-text music) + "Extract 'direction and 'text from SCRIPT-MUSIC, and transform MultiMeasureTextEvent" + (if (memq 'script-event (ly:music-property music 'types)) + + (let ((dir (ly:music-property music 'direction)) + (p (make-music 'MultiMeasureTextEvent + 'text (ly:music-property music 'text)))) + (if (ly:dir? dir) + (set! (ly:music-property p 'direction) dir)) + p) + music)) + +(define-ly-syntax (multi-measure-rest parser location duration articulations) + (make-music 'MultiMeasureRestNew + 'articulations (map script-to-mmrest-text articulations) + 'duration duration + 'origin location)) + ;; UGH. TODO: represent mm rests in a decent way as music expressions. ;; Also eliminate glue-mm-rests while we are at it. -(define-ly-syntax (multi-measure-rest parser location duration articulations) +(define-ly-syntax (multi-measure-rest-old parser location duration articulations) (let* ((mus (make-multi-measure-rest duration location)) (elts (ly:music-property mus 'elements))) (set! (ly:music-property mus 'elements)
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel