Hi Abraham,

On Sat, Mar 21, 2015 at 9:13 PM, tisimst <tisimst.lilyp...@gmail.com> wrote:

> David,
>
> You are a genius! I've almost got it, but I'm not sure how to handle
> rests. Here's my current function:
>
> #(define (flipnotes grob)
>    (let ((notes (ly:grob-array->list (ly:grob-object grob 'note-heads))))
>      (for-each
>        (lambda (note)
>          (let* ((pitch (ly:event-property (event-cause note) 'pitch))
>                 (stem (ly:grob-object note 'stem))
>                 (dir (ly:grob-property stem 'direction))
>                 (offset (ly:grob-relative-coordinate note grob X)))
>            (if (eq? dir DOWN)
>                (if (and (< offset 0.1) (> offset -0.1))
>                  (ly:grob-set-property! note 'rotation '(180 0 0))
>                  (ly:grob-set-property! note 'rotation '(0 0 0)))
>                (if (and (< offset 0.1) (> offset -0.1))
>                    (ly:grob-set-property! note 'rotation '(0 0 0))
>                    (ly:grob-set-property! note 'rotation '(180 0 0)))
>                )
>            ))
>        notes)))
>
>
> This works perfectly when there are NO rests, but I get this error when
> there is a rest in the NoteColumn:
>
> In procedure ly:grob-array->list in expression (ly:grob-array->list
> (ly:grob-object grob #)): Wrong type argument in position 1 (expecting
> Grob_array): ()
>
>
>
Glad I could help!

If there's a rest, then the note-heads array will be empty.  To make this
work, just add a check that the note-heads list isn't the empty list '().

%%%%
#(define (flipnotes grob)
   (let ((notes (ly:grob-array->list (ly:grob-object grob 'note-heads))))
     (if (pair? notes)
         (for-each
          (lambda (note)
            (let* (;(pitch (ly:event-property (event-cause note) 'pitch))
;; don't need this
                   (stem (ly:grob-object note 'stem))
                   (dir (ly:grob-property stem 'direction))
                   (offset (ly:grob-relative-coordinate note grob X)))
              (if (eq? dir DOWN)
                  (if (and (< offset 0.1) (> offset -0.1))
                      (ly:grob-set-property! note 'rotation '(180 0 0))
                      (ly:grob-set-property! note 'rotation '(0 0 0)))
                  (if (and (< offset 0.1) (> offset -0.1))
                      (ly:grob-set-property! note 'rotation '(0 0 0))
                      (ly:grob-set-property! note 'rotation '(180 0 0)))
                  )
              ))
          notes)
         ; alternate return?

         )))

%%%%

If you get a rest, this function will return an unspecified value, so you
might want to add another clause to the if-block if you need meaningful
output.

Hope this helps!

David
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to