From 95dd8165a846068c7c2e1775364d51cac1b9d33c Mon Sep 17 00:00:00 2001 From: hanwen Date: Mon, 10 Jan 2005 22:33:33 +0000 Subject: [PATCH] * lily/include/lily-lexer.hh (class Lily_lexer): lose hungarian _b suffix for main_input_b_. * scm/music-functions.scm (toplevel-music-functions): precompute music lengths for music expressions. --- ChangeLog | 8 ++++++++ lily/include/lily-lexer.hh | 2 +- lily/lexer.ll | 12 ++++++------ lily/lily-lexer.cc | 4 ++-- lily/lily-parser.cc | 2 +- lily/music.cc | 4 +++- scm/define-grobs.scm | 4 ++-- scm/define-music-properties.scm | 3 ++- scm/define-music-types.scm | 12 ++++++------ scm/music-functions.scm | 11 ++++++++++- 10 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99b7d155b8..cff57e8791 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-01-10 Han-Wen Nienhuys + + * lily/include/lily-lexer.hh (class Lily_lexer): lose hungarian _b + suffix for main_input_b_. + + * scm/music-functions.scm (toplevel-music-functions): + precompute music lengths for music expressions. + 2005-01-11 Nicolas Sceaux * lily/include/input.hh (class Input): new `end_' slot for end of diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index 0e42719912..0cd081cd52 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -39,7 +39,7 @@ public: String main_input_name_; void *lexval; Input *lexloc; - bool main_input_b_; + bool is_main_input_; Sources *sources_; diff --git a/lily/lexer.ll b/lily/lexer.ll index 2e4d96401e..a56385cd2a 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -216,7 +216,7 @@ HYPHEN -- } <> { LexerError (_ ("EOF found inside a comment").to_str0 ()); - main_input_b_ = false; + is_main_input_ = false; if (! close_input ()) yyterminate (); // can't move this, since it actually rets a YY_NULL } @@ -224,10 +224,10 @@ HYPHEN -- \\maininput { - if (!main_input_b_) + if (!is_main_input_) { start_main_input (); - main_input_b_ = true; + is_main_input_ = true; } else error (_ ("\\maininput not allowed outside init files")); @@ -279,7 +279,7 @@ HYPHEN -- Input hi = here_input(); hi.step_forward (); SCM sval = ly_parse_scm (hi.start_, &n, hi, - be_safe_global && main_input_b_); + be_safe_global && is_main_input_); if (sval == SCM_UNDEFINED) { @@ -536,9 +536,9 @@ HYPHEN -- } <> { - if (main_input_b_) + if (is_main_input_) { - main_input_b_ = false; + is_main_input_ = false; if (!close_input ()) /* Returns YY_NULL */ yyterminate (); diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index de95f11f44..559d5340a3 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -91,7 +91,7 @@ Lily_lexer::Lily_lexer (Sources *sources) sources_ = sources; scopes_ = SCM_EOL; error_level_ = 0; - main_input_b_ = false; + is_main_input_ = false; smobify_self (); @@ -109,7 +109,7 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src) sources_ = src.sources_; error_level_ = src.error_level_; - main_input_b_ = src.main_input_b_; + is_main_input_ = src.is_main_input_; scopes_ = SCM_EOL; diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 3eb14cd13e..534352be30 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -142,7 +142,7 @@ Lily_parser::parse_string (String ly_code) self_scm ()); lexer_->main_input_name_ = ""; - lexer_->main_input_b_ = true; + lexer_->is_main_input_ = true; set_yydebug (0); lexer_->new_input (lexer_->main_input_name_, ly_code, sources_); diff --git a/lily/music.cc b/lily/music.cc index 5183763f8d..3ce9c302ce 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -88,7 +88,9 @@ Music::get_length () const SCM lst = get_property ("length"); if (unsmob_moment (lst)) return *unsmob_moment (lst); - else if (ly_c_procedure_p (lst)) + + lst = get_property ("length-callback"); + if (ly_c_procedure_p (lst)) { SCM res = scm_call_1 (lst, self_scm ()); return *unsmob_moment (res); diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index ad4a6fa658..8c477e6e61 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -338,7 +338,6 @@ break-aligned-interface item-interface )))) )) - (DotColumn . ( (axes . (0)) @@ -707,7 +706,8 @@ (staff-padding . 0.25) (meta . ((interfaces . (side-position-interface multi-measure-interface self-alignment-interface font-interface spanner-interface text-interface)))) )) - (NoteCollision + + (NoteCollision . ( (axes . (0 1)) (X-extent-callback . ,Axis_group_interface::group_extent_callback) diff --git a/scm/define-music-properties.scm b/scm/define-music-properties.scm index c3c6eadac5..b8aba452ff 100644 --- a/scm/define-music-properties.scm +++ b/scm/define-music-properties.scm @@ -65,7 +65,8 @@ e.g. @code{\\tag #'part ...} could tag a piece of music as only being active in (inversion ,boolean? "If set, this chord note is inverted.") (label ,markup? "label of a mark.") (last-pitch ,ly:pitch? "The last pitch after relativization.") - (length ,procedure? "How to compute the duration of this music") + (length ,ly:moment? "The duration of this music") + (length-callback ,procedure? "How to compute the duration of this music") (internal-class-name ,string? "C++ class to use for this Music object") (name ,symbol? "Name of this music object") (numerator ,integer? "numerator of a time signature") diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 5784760d32..57d4acf8dd 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -615,7 +615,7 @@ does not create staffs or voices implicitly. Syntax: @code{\\skip }@var{duration}.") (internal-class-name . "Music") - (length . ,ly:music-duration-length) + (length-callback . ,ly:music-duration-length) (iterator-ctor . ,Simple_music_iterator::constructor) (types . (general-music event rhythmic-event skip-event)) )) @@ -712,7 +712,7 @@ Syntax: @code{\\\\}") (internal-class-name . "Repeated_music") (description . "") (start-moment-function . ,Repeated_music::first_start) - (length . ,Repeated_music::volta_music_length) + (length-callback . ,Repeated_music::volta_music_length) (types . (general-music repeated-music volta-repeated-music)) )) @@ -723,7 +723,7 @@ Syntax: @code{\\\\}") (start-moment-function . ,Repeated_music::first_start) (internal-class-name . "Repeated_music") (types . (general-music repeated-music unfolded-repeated-music)) - (length . ,Repeated_music::unfolded_music_length) + (length-callback . ,Repeated_music::unfolded_music_length) )) (PercentRepeatedMusic . ( @@ -731,7 +731,7 @@ Syntax: @code{\\\\}") (description . "Repeats encoded by percents.") (iterator-ctor . ,Percent_repeat_iterator::constructor) (start-moment-function . ,Repeated_music::first_start) - (length . ,Repeated_music::unfolded_music_length) + (length-callback . ,Repeated_music::unfolded_music_length) (types . (general-music repeated-music percent-repeated-music)) )) @@ -743,7 +743,7 @@ Syntax: @code{\\\\}") (start-moment-function . ,Repeated_music::first_start) ;; the length of the repeat is handled by shifting the note logs - (length . ,Repeated_music::folded_music_length) + (length-callback . ,Repeated_music::folded_music_length) (types . (general-music repeated-music tremolo-repeated-music)) )) @@ -754,7 +754,7 @@ Syntax: @code{\\\\}") (description . "Repeats with alternatives placed in parallel. ") (iterator-ctor . ,Folded_repeat_iterator::constructor) (start-moment-function . ,Repeated_music::minimum_start) - (length . ,Repeated_music::folded_music_length) + (length-callback . ,Repeated_music::folded_music_length) (types . (general-music repeated-music folded-repeated-music)) )) )) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index f4bee703a2..b19cc5cf88 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -21,7 +21,10 @@ ly:grob-set-property!)) (define-public (music-map function music) - "Apply @var{function} to @var{music} and all of the music it contains. " + "Apply @var{function} to @var{music} and all of the music it contains. + +First it recurses over the children, then the function is applied to MUSIC. +" (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element))) (set! (ly:music-property music 'elements) @@ -635,12 +638,18 @@ Syntax: (set! (ly:music-property music 'error-found) #t)) music) +(define (precompute-music-length music) + (set! (ly:music-property music 'length) + (ly:music-length music)) + music) + (define-public toplevel-music-functions (list ;; check-start-chords ; ; no longer needed with chord syntax. (lambda (music parser) (voicify-music music)) (lambda (x parser) (music-map glue-mm-rest-texts x)) (lambda (x parser) (music-map music-check-error x)) + (lambda (x parser) (music-map precompute-music-length x)) (lambda (music parser) (music-map (quote-substitute (ly:parser-lookup parser 'musicQuotes)) music)) -- 2.39.2