Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
Reviewers: , Message: Please review. Description: Add Scheme function to return column associated with Item. The C++ function PaperColumn::get_column is used frequently, and it makes sense to have a Scheme function which performs the same task. An example of a practical application is the request by users to return the location of a particular grob in a score: this is done by examining the PaperColumn or NonMusicalPaperColumn associated with the grob. Please review this at https://codereview.appspot.com/203910043/ Affected files (+15, -0 lines): M lily/item-scheme.cc Index: lily/item-scheme.cc diff --git a/lily/item-scheme.cc b/lily/item-scheme.cc index 0e6b71ef30a8191931495c3ff16bd6d9bb5fcadb..24ccf5bf0de97ba751afa514b2e777392c73 100644 --- a/lily/item-scheme.cc +++ b/lily/item-scheme.cc @@ -19,6 +19,7 @@ */ #include item.hh +#include paper-column.hh LY_DEFINE (ly_item_p, ly:item?, 1, 0, 0, (SCM g), @@ -39,3 +40,17 @@ LY_DEFINE (ly_item_break_dir, ly:item-break-dir, Item *me = Item::unsmob (it); return scm_from_int (me-break_status_dir ()); } + +LY_DEFINE (ly_item_get_column, ly:item-get-column, + 1, 0, 0, (SCM it), + Return the @code{PaperColumn} or @code{NonMusicalPaperColumn} +associated with this @code{Item}.) +{ + LY_ASSERT_SMOB (Item, it, 1); + Item *me = Item::unsmob (it); + + if (Paper_column *col = me-get_column ()) +return col-self_scm (); + + return SCM_EOL; +} ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
Can't judge the code but the idea looks great :-) Urs Am 15. Februar 2015 08:27:20 EST, schrieb david.nales...@gmail.com: Reviewers: , Message: Please review. Description: Add Scheme function to return column associated with Item. The C++ function PaperColumn::get_column is used frequently, and it makes sense to have a Scheme function which performs the same task. An example of a practical application is the request by users to return the location of a particular grob in a score: this is done by examining the PaperColumn or NonMusicalPaperColumn associated with the grob. Please review this at https://codereview.appspot.com/203910043/ Affected files (+15, -0 lines): M lily/item-scheme.cc Index: lily/item-scheme.cc diff --git a/lily/item-scheme.cc b/lily/item-scheme.cc index 0e6b71ef30a8191931495c3ff16bd6d9bb5fcadb..24ccf5bf0de97ba751afa514b2e777392c73 100644 --- a/lily/item-scheme.cc +++ b/lily/item-scheme.cc @@ -19,6 +19,7 @@ */ #include item.hh +#include paper-column.hh LY_DEFINE (ly_item_p, ly:item?, 1, 0, 0, (SCM g), @@ -39,3 +40,17 @@ LY_DEFINE (ly_item_break_dir, ly:item-break-dir, Item *me = Item::unsmob (it); return scm_from_int (me-break_status_dir ()); } + +LY_DEFINE (ly_item_get_column, ly:item-get-column, + 1, 0, 0, (SCM it), + Return the @code{PaperColumn} or @code{NonMusicalPaperColumn} +associated with this @code{Item}.) +{ + LY_ASSERT_SMOB (Item, it, 1); + Item *me = Item::unsmob (it); + + if (Paper_column *col = me-get_column ()) +return col-self_scm (); + + return SCM_EOL; +} ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
On Sun, Feb 15, 2015 at 7:58 AM, Urs Liska u...@openlilylib.org wrote: Can't judge the code but the idea looks great :-) Thanks--I'm noticing that bits of code get reused on the lists, so there's a need. This will help tuck away some of the code gobbledygook that is so off-putting.. It occurs to me that it shouldn't be any trouble to add something like ly:item-location later on. It could return (global-timestep . (measure . measure-position)).. David ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
On Sun, Feb 15, 2015 at 12:34 PM, Thomas Morley thomasmorle...@gmail.com wrote: 2015-02-15 19:28 GMT+01:00 Thomas Morley thomasmorle...@gmail.com: Oops, definition for 'grob-name' is missing: #(define grob-name (lambda (x) (if (ly:grob? x) (assq-ref (ly:grob-property x 'meta) 'name) (ly:error ~a is not a grob x Now, a function to get a grob's name would certainly be useful. I'm sick to death of constantly recreating it or looking it up (as I bet you are)! If there's a question of usefulness, I think we've established the need... The benefit of doing this in C++ is that there's probably something in place already and it will get automatically documented in the Scheme functions list. ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
2015-02-15 18:50 GMT+01:00 David Nalesnik david.nales...@gmail.com: On Sun, Feb 15, 2015 at 7:58 AM, Urs Liska u...@openlilylib.org wrote: Can't judge the code but the idea looks great :-) Thanks--I'm noticing that bits of code get reused on the lists, so there's a need. This will help tuck away some of the code gobbledygook that is so off-putting.. It occurs to me that it shouldn't be any trouble to add something like ly:item-location later on. It could return (global-timestep . (measure . measure-position)).. David Hi David, I can't review C++ code, though it looks like the C++-version of your: #(define (get-paper-column grob) (if (not (ly:grob? grob)) (ly:message column not found) (if (grob::has-interface grob 'paper-column-interface) grob (get-paper-column (ly:grob-parent grob X) Some time ago I wrote a more generic code: #(define (look-up-for-parent name-symbol axis grob) Return the parent of @var{grob}, specified by it's @var{name-symbol} in axis @var{axis}. If not found, look up for the next parent. (let* ((parent (ly:grob-parent grob axis))) (cond ((not (ly:grob? parent)) (ly:error (_Perhaps typing error for \~a\ or \~a\ is not in the parent-tree.) name-symbol name-symbol)) ((not (equal? name-symbol (grob-name parent))) (look-up-for-parent name-symbol axis parent)) (else parent I wonder whether something like this may be implemented at C++ level and your ly:item-get-column as a special case of it. What do you think? Cheers, Harm ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
2015-02-15 19:28 GMT+01:00 Thomas Morley thomasmorle...@gmail.com: 2015-02-15 18:50 GMT+01:00 David Nalesnik david.nales...@gmail.com: On Sun, Feb 15, 2015 at 7:58 AM, Urs Liska u...@openlilylib.org wrote: Can't judge the code but the idea looks great :-) Thanks--I'm noticing that bits of code get reused on the lists, so there's a need. This will help tuck away some of the code gobbledygook that is so off-putting.. It occurs to me that it shouldn't be any trouble to add something like ly:item-location later on. It could return (global-timestep . (measure . measure-position)).. David Hi David, I can't review C++ code, though it looks like the C++-version of your: #(define (get-paper-column grob) (if (not (ly:grob? grob)) (ly:message column not found) (if (grob::has-interface grob 'paper-column-interface) grob (get-paper-column (ly:grob-parent grob X) Some time ago I wrote a more generic code: Oops, definition for 'grob-name' is missing: #(define grob-name (lambda (x) (if (ly:grob? x) (assq-ref (ly:grob-property x 'meta) 'name) (ly:error ~a is not a grob x #(define (look-up-for-parent name-symbol axis grob) Return the parent of @var{grob}, specified by it's @var{name-symbol} in axis @var{axis}. If not found, look up for the next parent. (let* ((parent (ly:grob-parent grob axis))) (cond ((not (ly:grob? parent)) (ly:error (_Perhaps typing error for \~a\ or \~a\ is not in the parent-tree.) name-symbol name-symbol)) ((not (equal? name-symbol (grob-name parent))) (look-up-for-parent name-symbol axis parent)) (else parent I wonder whether something like this may be implemented at C++ level and your ly:item-get-column as a special case of it. What do you think? Cheers, Harm ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
Hi Harm, On Sun, Feb 15, 2015 at 12:28 PM, Thomas Morley thomasmorle...@gmail.com wrote: Some time ago I wrote a more generic code: #(define (look-up-for-parent name-symbol axis grob) Return the parent of @var{grob}, specified by it's @var{name-symbol} in axis @var{axis}. If not found, look up for the next parent. (let* ((parent (ly:grob-parent grob axis))) (cond ((not (ly:grob? parent)) (ly:error (_Perhaps typing error for \~a\ or \~a\ is not in the parent-tree.) name-symbol name-symbol)) ((not (equal? name-symbol (grob-name parent))) (look-up-for-parent name-symbol axis parent)) (else parent I wonder whether something like this may be implemented at C++ level and your ly:item-get-column as a special case of it. What do you think? The patch simply makes a commonly used C++ function available through Scheme, on the model of functions like ly:grob-system. Now I couldn't say whether the function it wraps--Paper_column::get_column--could benefit from a different approach. In any case, this patch just provides an interface for it, whatever its implementation details are. I do think that what you're describing would be very useful as another function usable in C++ and Scheme: given a grob, check whether it related by parentage to some other grob. (I know that ly:grob-extent and ly:grob-relative-coordinate require this, so your function would help finding appropriate input for them.) I wonder if it should operate by the actual grob pointer instead of its name, in line with the way other functions work. This is so useful, that I wonder if there's a C++ function which just hasn't been made accessible yet! ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
On Sun, Feb 15, 2015 at 1:14 PM, David Nalesnik david.nales...@gmail.com wrote: Now, a function to get a grob's name would certainly be useful. I'm sick to death of constantly recreating it or looking it up (as I bet you are)! If there's a question of usefulness, I think we've established the need... The benefit of doing this in C++ is that there's probably something in place already and it will get automatically documented in the Scheme functions list. Yup--there's Grob::name. Couldn't resist--patch up for ly:grob-name. --David ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
2015-02-15 20:14 GMT+01:00 David Nalesnik david.nales...@gmail.com: On Sun, Feb 15, 2015 at 12:34 PM, Thomas Morley thomasmorle...@gmail.com wrote: 2015-02-15 19:28 GMT+01:00 Thomas Morley thomasmorle...@gmail.com: Oops, definition for 'grob-name' is missing: #(define grob-name (lambda (x) (if (ly:grob? x) (assq-ref (ly:grob-property x 'meta) 'name) (ly:error ~a is not a grob x Now, a function to get a grob's name would certainly be useful. I'm sick to death of constantly recreating it or looking it up (as I bet you are)! Yeah! If there's a question of usefulness, I think we've established the need... Indeed. The benefit of doing this in C++ is that there's probably something in place already and it will get automatically documented in the Scheme functions list. ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
2015-02-15 20:56 GMT+01:00 David Nalesnik david.nales...@gmail.com: On Sun, Feb 15, 2015 at 1:14 PM, David Nalesnik david.nales...@gmail.com wrote: Now, a function to get a grob's name would certainly be useful. I'm sick to death of constantly recreating it or looking it up (as I bet you are)! If there's a question of usefulness, I think we've established the need... The benefit of doing this in C++ is that there's probably something in place already and it will get automatically documented in the Scheme functions list. Yup--there's Grob::name. Couldn't resist--patch up for ly:grob-name. --David Can't review C++, so I'll not post there. But: YIPEE! Cheers, Harm ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Add Scheme function to return column associated with Item. (issue 203910043 by david.nales...@gmail.com)
Harm, On Sun, Feb 15, 2015 at 2:42 PM, Thomas Morley thomasmorle...@gmail.com wrote: Can't review C++, so I'll not post there. There IS something you can help with, though. In the patch as it stands, I'm simply making Grob::name available through Scheme. It thus returns a string. (Grob::name actually converts the Scheme symbol into a string.) Do you think that the Scheme function ought to return a symbol? This is doable, but I'd have to think of the best way. But: YIPEE! Yeah, life is way too short... ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel