Sat, 17 Apr 2004 12:45:34 +0200, Nicolas a dit :
> In the meantime I am trying some hacks to achieve the following:
> (define (textoffset dx dy)
> #{ \property Voice.TextScript #'offset = #(cons $dx $dy) #})
> that would expand in the following:
> (define (textoffset dx dy)
> (ly:parse-string (format #f " \property Voice.TextScript #'offset = #(cons ~a ~a)
> "
> dx dy)))
> and returns, when called, the music expression with the appropriate
> values inserted. I don't find it very eleguant, but it may be handy in
> user lily code. (I don't think `$' is often used in lily files?)
> nicolas
Here is a possible implementation, using the temp dirty
ly:parse-string
-------------------- scm/toto.scm ----------------------
(define-module (lily))
(export ly:parse-file)
(define-module (scm toto))
(use-modules (ice-9 format) (lily))
(define-public (ly:parse-string str)
"Fake!"
(let ((port (open-output-file "/tmp/tmplily.ly")))
(format port "vartmp = \\notes { ~a }
#(export vartmp)
#(define-module (scm toto))
#(use-modules (ice-9 format) (*anonymous-ly-15*))~%" str)
(close-port port)
(ly:parse-file "/tmp/tmplily.ly")
vartmp))
(define-public (read-lily-expression chr port)
(let* ((format-args '())
(lily-string (with-output-to-string
(lambda ()
(do ((c (read-char port) (read-char port)))
((and (char=? c #\#)
(char=? (peek-char port) #\}))
(read-char port))
(cond ((and (char=? c #\$)
(not (char=? (peek-char port) #\$)))
;; a $variable
(display "~a")
(set! format-args (cons (read port) format-args)))
((and (char=? c #\$)
(char=? (peek-char port) #\$))
;; just a $ character
(display (read-char port)))
(else
;; other caracters
(display c))))))))
`(ly:parse-string (format #f ,lily-string ,@(reverse! format-args)))))
(read-hash-extend #\{ read-lily-expression)
-------------------- scm/toto.scm ----------------------
---------------------- foo.ly --------------------------
#(use-modules (scm toto))
#(define (textoffset dx dy)
#{ \override Voice.TextScript #'extra-offset = #(cons $dx $dy) #})
myoffset=#(textoffset 3 -4)
\score {
\notes {
c'^"normal text"
%% uhrg, I cannot write scheme here
%% #(textoffset 3 -4)
\myoffset
c'^"text with offset"
}
}
---------------------- foo.ly --------------------------
which gives the expected result.
(this example is not exactly convincing)
_______________________________________________
Lilypond-devel mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/lilypond-devel