(define-public DOWN -1)
(define-public CENTER 0)
-(define-safe-public DOUBLE-FLAT-QTS -4)
-(define-safe-public THREE-Q-FLAT-QTS -3)
-(define-safe-public FLAT-QTS -2)
-(define-safe-public SEMI-FLAT-QTS -1)
-(define-safe-public NATURAL-QTS 0)
-(define-safe-public SEMI-SHARP-QTS 1)
-(define-safe-public SHARP-QTS 2)
-(define-safe-public THREE-Q-SHARP-QTS 3)
-(define-safe-public DOUBLE-SHARP-QTS 4)
-(define-safe-public SEMI-TONE-QTS 2)
-
(define-safe-public DOUBLE-FLAT -1)
(define-safe-public THREE-Q-FLAT -3/4)
(define-safe-public FLAT -1/2)
(define-public (scorify-music music)
"Preprocess @var{music}."
(ly:make-score
- (fold (lambda (f m) (f m parser))
+ (fold (lambda (f m) (f m))
music
toplevel-music-functions)))
-(define (get-current-filename parser book)
+(define (get-current-filename book)
"return any suffix value for output filename allowing for settings by
calls to bookOutputName function"
(or (paper-variable book 'output-filename)
(ly:parser-output-name)))
-(define (get-current-suffix parser book)
+(define (get-current-suffix book)
"return any suffix value for output filename allowing for settings by calls to
bookoutput function"
(let ((book-output-suffix (paper-variable book 'output-suffix)))
(define-public current-outfile-name #f) ; for use by regression tests
-(define (get-outfile-name parser book)
+(define (get-outfile-name book)
"return current filename for generating backend output files"
;; user can now override the base file name, so we have to use
;; the file-name concatenated with any potential output-suffix value
;; as the key to out internal a-list
- (let* ((base-name (get-current-filename parser book))
- (output-suffix (get-current-suffix parser book))
+ (let* ((base-name (get-current-filename book))
+ (output-suffix (get-current-suffix book))
(alist-key (format #f "~a~a" base-name output-suffix))
(counter-alist (ly:parser-lookup 'counter-alist))
(output-count (assoc-get alist-key counter-alist 0))
(set! current-outfile-name result)
result))
-(define (print-book-with parser book process-procedure)
+(define (print-book-with book process-procedure)
(let* ((paper (ly:parser-lookup '$defaultpaper))
(layout (ly:parser-lookup '$defaultlayout))
- (outfile-name (get-outfile-name parser book)))
+ (outfile-name (get-outfile-name book)))
(process-procedure book paper layout outfile-name)))
(define-public (print-book-with-defaults book)
- (print-book-with parser book ly:book-process))
+ (print-book-with book ly:book-process))
(define-public (print-book-with-defaults-as-systems book)
- (print-book-with parser book ly:book-process-to-systems))
+ (print-book-with book ly:book-process-to-systems))
;; Add a score to the current bookpart, book or toplevel
(define-public (add-score score)
((ly:parser-lookup 'book-score-handler)
(ly:parser-lookup '$current-book) score))
(else
- ((ly:parser-lookup 'toplevel-score-handler) parser score))))
+ ((ly:parser-lookup 'toplevel-score-handler) score))))
(define-public paper-variable
(let
((get-papers
- (lambda (parser book)
+ (lambda (book)
(append (if (and book (ly:output-def? (ly:book-paper book)))
(list (ly:book-paper book))
'())
(ly:parser-lookup '$papers)
(list (ly:parser-lookup '$defaultpaper))))))
(make-procedure-with-setter
- (lambda (parser book symbol)
+ (lambda (book symbol)
(any (lambda (p) (ly:output-def-lookup p symbol #f))
- (get-papers parser book)))
- (lambda (parser book symbol value)
+ (get-papers book)))
+ (lambda (book symbol value)
(ly:output-def-set-variable!
- (car (get-papers parser book))
+ (car (get-papers book))
symbol value)))))
(define-public (add-text text)
(define-public (coord-scale coordinate amount)
(coord-operation * amount coordinate))
-(define-public (coord-rotate coordinate degrees-in-radians)
- (let*
- ((coordinate
- (cons
- (exact->inexact (coord-x coordinate))
- (exact->inexact (coord-y coordinate))))
- (radius
- (sqrt
- (+ (* (coord-x coordinate) (coord-x coordinate))
- (* (coord-y coordinate) (coord-y coordinate)))))
- (angle (angle-0-2pi (atan (coord-y coordinate) (coord-x coordinate)))))
- (cons
- (* radius (cos (+ angle degrees-in-radians)))
- (* radius (sin (+ angle degrees-in-radians))))))
+(define-public (coord-rotate coordinate angle-in-radians)
+ (coord-rotated coordinate (/ angle-in-radians PI-OVER-180)))
+
+(define-public (coord-rotated coordinate direction)
+ ;; Same, in degrees or with a given direction
+ (let ((dir (ly:directed direction)))
+ (cons (- (* (car dir) (car coordinate))
+ (* (cdr dir) (cdr coordinate)))
+ (+ (* (car dir) (cdr coordinate))
+ (* (cdr dir) (car coordinate))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; trig
(define-public (cyclic-base-value value cycle)
"Take @var{value} and modulo-maps it between 0 and base @var{cycle}."
- (if (< value 0)
- (cyclic-base-value (+ value cycle) cycle)
- (if (>= value cycle)
- (cyclic-base-value (- value cycle) cycle)
- value)))
+ (cond ((< value 0)
+ (cyclic-base-value (+ value cycle) cycle))
+ ((>= value cycle)
+ (cyclic-base-value (- value cycle) cycle))
+ (else value)))
(define-public (angle-0-2pi angle)
"Take @var{angle} (in radians) and maps it between 0 and 2pi."
(define-public (polar->rectangular radius angle-in-degrees)
"Return polar coordinates (@var{radius}, @var{angle-in-degrees})
-as rectangular coordinates @ode{(x-length . y-length)}."
-
- (let ((complex (make-polar
- radius
- (degrees->radians angle-in-degrees))))
- (cons
- (real-part complex)
- (imag-part complex))))
+as rectangular coordinates @code{(x-length . y-length)}."
+ (ly:directed angle-in-degrees radius))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; string
(define-public (string-startswith s prefix)
(equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))
+(define-public (remove-whitespace strg)
+"Remove characters satisfying @code{char-whitespace?} from string @var{strg}"
+ (if (guile-v2)
+ (string-delete char-whitespace? strg)
+ (string-delete strg char-whitespace?)))
+
(define-public (string-encode-integer i)
(cond
((= i 0) "o")
(fancy-format #f (car custom-format) num))
(else (fancy-format #f "~(~@r~)" num))))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; lilypond version
+
+(define (lexicographic-list-compare? op a b)
+ "Lexicographically compare two lists @var{a} and @var{b} using
+ the operator @var{op}. The types of the list elements have to
+ be comparable with @var{op}. If the lists are of different length
+ the trailing elements of the longer list are ignored."
+ (let* ((ca (car a))
+ (iseql (op ca ca)))
+ (let loop ((ca ca) (cb (car b)) (a (cdr a)) (b (cdr b)))
+ (let ((axb (op ca cb)))
+ (if (and (pair? a) (pair? b)
+ (eq? axb iseql (op cb ca)))
+ (loop (car a) (car b) (cdr a) (cdr b))
+ axb)))))
+
+(define (ly:version? op ver)
+ "Using the operator @var{op} compare the currently executed LilyPond
+ version with a given version @var{ver} which is passed as a list of
+ numbers."
+ (lexicographic-list-compare? op (ly:version) ver))
+
;;;;;;;;;;;;;;;;
;; other
(ly:format "~a:1" input-file-name)
(_ "no \\version statement found, please add~afor future compatibility")
(format #f "\n\n\\version ~s\n\n" (lilypond-version))))
+
+(define-public (output-module? module)
+ "Returns @code{#t} if @var{module} belongs to an output module
+usually carrying context definitions (@code{\\midi} or
+@code{\\layout})."
+ (or (module-ref module 'is-midi #f)
+ (module-ref module 'is-layout #f)))