Re: Help understanding how code works (or doesn't)
On 9/16/10 4:55 PM, Neil Puttock n.putt...@gmail.com wrote: On 15 September 2010 03:40, Carl Sorensen c_soren...@byu.edu wrote: Note that at this point, I haven't changed the value to which I am setting 'measurePosition. So, can anybody help me see why this code doesn't work? It looks like adding the extra iteration step (ApplyContext) delays the 'measurePosition setting. It might be the case that it ends up being overridden by the Timing_translator before it's been read by the autobeamer. How would one go about trying to verify this with the debugger? I get lost once we get past the parsing stage; I know that iteration happens, but I have very little clue about *how* iteration happens. Using an iterator directly seems to work (see attached), but might be considered a dubious hack; what do you think? :) Actually, I like the patch. I don't think it's a hack. I think it's a bigger hack to set context properties in Scheme (when we can't read the context properties from Scheme). I'd support pushing it as-is. Thanks, Carl ___ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Help understanding how code works (or doesn't)
On 18 September 2010 20:38, Carl Sorensen c_soren...@byu.edu wrote: How would one go about trying to verify this with the debugger? You could try following the ApplyContext path, to check it leads up to a set_property () call. TBH, I'm now not so sure what I said earlier is really happening: I've just tried adding a breakpoint in Context::internal_set_property (), and there's no evidence that 'measurePosition gets set from the ApplyContext procedure. It seems there's no effect from the revised \partial constructor; it's as if it's invisible, since the result's the same if it's left out (apart from the debug output). Actually, I like the patch. I don't think it's a hack. I think it's a bigger hack to set context properties in Scheme (when we can't read the context properties from Scheme). Thanks. I'm warming to it too, since it has a nice side-effect: it allows the display method to cater for scaled durations easily if we leave the duration-moment conversion to the iterator. I've made a few changes and posted a revised version here: http://codereview.appspot.com/2228042/ Cheers, Neil ___ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Help understanding how code works (or doesn't)
On 15 September 2010 03:40, Carl Sorensen c_soren...@byu.edu wrote: Note that at this point, I haven't changed the value to which I am setting 'measurePosition. So, can anybody help me see why this code doesn't work? It looks like adding the extra iteration step (ApplyContext) delays the 'measurePosition setting. It might be the case that it ends up being overridden by the Timing_translator before it's been read by the autobeamer. Using an iterator directly seems to work (see attached), but might be considered a dubious hack; what do you think? :) Cheers, Neil From fe26d8b7ddce8fb00a072853d938e6a612a20979 Mon Sep 17 00:00:00 2001 From: Neil Puttock n.putt...@gmail.com Date: Thu, 16 Sep 2010 23:54:10 +0100 Subject: [PATCH] Possible fix for #372. --- lily/partial-iterator.cc | 27 +++ scm/define-music-types.scm |6 ++ scm/ly-syntax-constructors.scm |6 -- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 lily/partial-iterator.cc diff --git a/lily/partial-iterator.cc b/lily/partial-iterator.cc new file mode 100644 index 000..bb175d4 --- /dev/null +++ b/lily/partial-iterator.cc @@ -0,0 +1,27 @@ +#include context.hh +#include moment.hh +#include music.hh +#include simple-music-iterator.hh + +class Partial_iterator : public Simple_music_iterator +{ +public: + DECLARE_SCHEME_CALLBACK (constructor, ()); + protected: + virtual void process (Moment); +}; + +void +Partial_iterator::process (Moment m) +{ + Moment length += robust_scm2moment (get_music ()-get_property (partial-length), + Moment (0)); + Context *ctx = get_outlet (); + Moment now = ctx-now_mom (); + ctx-set_property (measurePosition, (now - length).smobbed_copy ()); + + Simple_music_iterator::process (m); +} + +IMPLEMENT_CTOR_CALLBACK (Partial_iterator); diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 7f4525e..96fe7c2 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -349,6 +349,12 @@ Syntax: @code{\\override} [ @var{context} @code{.} ] (types . (general-music break-event page-turn-event event)) )) +(PartialSet + . ((description . Create an anacrusis.) + (iterator-ctor . ,ly:partial-iterator::constructor) + (types . (general-music partial-set)) + )) + (PartCombineMusic . ((description . Combine two parts on a staff, either merged or as separate voices.) diff --git a/scm/ly-syntax-constructors.scm b/scm/ly-syntax-constructors.scm index decc515..d73f6b9 100644 --- a/scm/ly-syntax-constructors.scm +++ b/scm/ly-syntax-constructors.scm @@ -250,10 +250,12 @@ into a @code{MultiMeasureTextEvent}. (define-ly-syntax-simple (partial dur) Make a partial measure. - (let ((mom (ly:moment-sub ZERO-MOMENT (ly:duration-length dur + (let ((mom (ly:duration-length dur))) ;; We use `descend-to-context' here instead of `context-spec-music' to ;; ensure \partial still works if the Timing_translator is moved (descend-to-context - (context-spec-music (make-property-set 'measurePosition mom) 'Timing) + (context-spec-music (make-music 'PartialSet + 'partial-length mom) + 'Timing) 'Score))) -- 1.7.0.4 ___ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel
Help understanding how code works (or doesn't)
I'm trying to fix Issue 372, which has \partial 4 \grace f16 d4 | \repeat unfold 8 c8 fail to autobeam the 8th notes. In running through the debugger, the problem is caused because a grace part shows up in the measure position, so the autobeam never kicks in. I think that the reason for this is because the \partial command sets only the main part of the measure position. And in this case, because of the grace note, I think the grace part should be set as well. So in order to try this, I decided to modify the code for \partial, which IIUC appears in scm/ly-syntax-constructors.scm: (define-ly-syntax-simple (partial dur) Make a partial measure. (let ((mom (ly:moment-sub ZERO-MOMENT (ly:duration-length dur ;; We use `descend-to-context' here instead of `context-spec-music' to ;; ensure \partial still works if the Timing_translator is moved (descend-to-context (context-spec-music (make-property-set 'measurePosition mom) 'Timing) 'Score))) In order to get the grace part of the current moment, I think I need to use make-apply-context. So I wrote some code: (define-ly-syntax-simple (partial dur) Make a partial measure. (let ((mom (ly:moment-sub ZERO-MOMENT (ly:duration-length dur ;; We use `descend-to-context' here instead of `context-spec-music' to ;; ensure \partial still works if the Timing_translator is moved (descend-to-context (context-spec-music (make-apply-context (lambda (c) (let ((now (ly:context-current-moment c))) (display \nIn partial\n) (display now)(newline) (display mom)(newline) (make-property-set 'measurePosition mom 'Timing) 'Score))) When I used this code, the autobeaming worked, but the bar check in the above code failed. sorensen2:lilypond Carl$ lilypond test-372.ly GNU LilyPond 2.13.34 Processing `test-372.ly' Parsing... Interpreting music... In partial #Mom 0G-1/16 #Mom -1/4 test-372.ly:7:5: warning: barcheck failed at: 1/4 d4 | Preprocessing graphical objects... Finding the ideal number of pages... Fitting music on 1 page... Drawing systems... Layout output to `test-372.ps'... Converting to `./test-372.pdf'... success: Compilation successfully completed Note that at this point, I haven't changed the value to which I am setting 'measurePosition. So, can anybody help me see why this code doesn't work? Thanks, Carl ___ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel