X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Flily-library.scm;h=472a82da24c4a785a5ef6c267f48f25327773d8c;hb=0ea80a5e850c6114d1ba7dc4cfd81d5a45d9604a;hp=43b05e57c20d8fa6b5b9e784d434cb5c564d1c58;hpb=ef5c8e061ba49682c06cdfbd3816c971d6accba4;p=lilypond.git diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 43b05e57c2..472a82da24 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -1,6 +1,6 @@ ;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen +;;;; Copyright (C) 1998--2014 Jan Nieuwenhuizen ;;;; Han-Wen Nienhuys ;;;; ;;;; LilyPond is free software: you can redistribute it and/or modify @@ -22,6 +22,8 @@ ;; for define-safe-public when byte-compiling using Guile V2 (use-modules (scm safe-utility-defs)) +(use-modules (ice-9 pretty-print)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; constants. @@ -80,6 +82,11 @@ (cons (ly:moment-main-numerator moment) (ly:moment-main-denominator moment))) +(define-public (seconds->moment s context) + "Return a moment equivalent to s seconds at the current tempo." + (ly:moment-mul (ly:context-property context 'tempoWholesPerMinute) + (ly:make-moment (/ s 60)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; durations @@ -116,6 +123,16 @@ non-visual scale factor 1." duration (base note length and dot count), as a number of whole notes." (duration-length (duration-visual dur))) +(define-public (unity-if-multimeasure context dur) + "Given a context and a duration, return @code{1} if the duration is +longer than the @code{measureLength} in that context, and @code{#f} otherwise. +This supports historic use of @code{Completion_heads_engraver} to split +@code{c1*3} into three whole notes." + (if (ly:momentstring def)) def)))) -;; -;; don't confuse users with # syntax. -;; +(define (self-evaluating? x) + (or (number? x) (string? x) (procedure? x) (boolean? x))) + +(define (ly-type? x) + (any (lambda (p) ((car p) x)) lilypond-exported-predicates)) + +(define-public (pretty-printable? val) + (and (not (self-evaluating? val)) + (not (symbol? val)) + (not (hash-table? val)) + (not (ly-type? val)))) + (define-public (scm->string val) - (if (and (procedure? val) - (symbol? (procedure-name val))) - (symbol->string (procedure-name val)) - (string-append - (if (self-evaluating? val) - (if (string? val) - "\"" - "") - "'") - (call-with-output-string (lambda (port) (display val port))) - (if (string? val) - "\"" - "")))) + (let* ((quote-style (if (string? val) + 'double + (if (or (null? val) ; (ly-type? '()) => #t + (and (not (self-evaluating? val)) + (not (vector? val)) + (not (hash-table? val)) + (not (ly-type? val)))) + 'single + 'none))) + ; don't confuse users with # syntax + (str (if (and (procedure? val) + (symbol? (procedure-name val))) + (symbol->string (procedure-name val)) + (call-with-output-string + (if (pretty-printable? val) + ; property values in PDF hit margin after 64 columns + (lambda (port) + (pretty-print val port #:width (case quote-style + ((single) 63) + (else 64)))) + (lambda (port) (display val port))))))) + (case quote-style + ((single) (string-append + "'" + (string-regexp-substitute "\n " "\n " str))) + ((double) (string-append "\"" str "\"")) + (else str)))) (define-public (!= lst r) (not (= lst r)))