Hi all, I'm trying to write a couple of functions that will attach a given text script to a note depending on the pitch. In the example below I get the first item in the list, as expected if I run (get-text 1). If I run (get-pitch msc) I get ((0)) and if I try to compile the file or run (add-text-script) I get
transformer.ly:23:44: In procedure - in expression (- n 1): transformer.ly:23:44: Wrong type argument in position 1: (0) I'm a beginner in Scheme so I'm probably doing something stupid here. It appears to me that I'm getting a list rather than an integer, but if I run (get-text texts (ly:pitch-semitones (ly:make-pitch 0 1 0))) I get the expected output. Why am I not getting an integer in my example and/or how can I access the integer value in my call to (ly:pitch-semitones)? Thanks for any input! /Henrik \version "2.12.3" #(define (make-text-script x) (make-music 'TextScriptEvent 'direction DOWN 'text (get-text texts x))) #(define (add-text-script m) (if (equal? (ly:music-property m 'name) 'EventChord) (set! (ly:music-property m 'elements) (cons (make-text-script (get-pitch m)) (ly:music-property m 'elements))) (let ((es (ly:music-property m 'elements)) (e (ly:music-property m 'element))) (map (lambda (y) (add-text-script y)) es) (if (ly:music? e) (add-text-script e)))) m) #(define get-text (lambda (ls n) (if (eq? n 1) (car ls) (get-text (cdr ls) (- n 1))))) #(define (get-pitch music) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (cond ((ly:pitch? p) (ly:pitch-semitones p)) ((pair? es) (map (lambda (x) (get-pitch x)) es)) ((ly:music? e) (get-pitch e))))) #(define texts '("one" "two" "three" "four")) #(define msc (make-music 'SequentialMusic 'elements (list (make-music 'EventChord 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 2 0 1 1) 'pitch (ly:make-pitch 0 0 0))))))) addText = #(define-music-function (parser location m) (ly:music?) (add-text-script m)) music = \relative c' { d } \score { \new Staff << { \addText { \music } } >> } _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user