From: David Kastrup Date: Sat, 10 Dec 2011 15:02:39 +0000 (+0100) Subject: Revert "Give \displayLilyMusic and \displayMusic optional port arguments." X-Git-Tag: release/2.15.22-1~19^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=efc6ab5915f25e56a429043a3ca29343038e4440;p=lilypond.git Revert "Give \displayLilyMusic and \displayMusic optional port arguments." This reverts commit a9829dd9576b665961c395cc501f004ddd3b858d. \displayMusic c' did no longer work. Probably needs some amendments in optional argument parsing before it can be reapplied in good conscience. --- diff --git a/Documentation/extending/scheme-tutorial.itely b/Documentation/extending/scheme-tutorial.itely index f7bf2a027c..2486512169 100644 --- a/Documentation/extending/scheme-tutorial.itely +++ b/Documentation/extending/scheme-tutorial.itely @@ -1046,30 +1046,23 @@ will display By default, LilyPond will print these messages to the console along with all the other messages. To split up these messages and save -the results of @code{\display@{STUFF@}}, you can specify an optional -output port to use: +the results of @code{\display@{STUFF@}}, redirect the output to +a file. @example -@{ - \displayMusic #(open-output-file "display.txt") @{ c'4\f @} -@} +lilypond file.ly >display.txt @end example -This will overwrite a previous output file whenever it is called; if you -need to write more than one expression, you would use a variable for -your port and reuse it: +With a combined bit of Lilypond and Scheme magick, you can actually +let Lilypond direct just this output to a file of its own: + @example @{ - port = #(open-output-file "display.txt") - \displayMusic \port @{ c'4\f @} - \displayMusic \port @{ d'4 @} - #(close-output-port port) + $(with-output-to-file "display.txt" + (lambda () #@{ \displayMusic @{ c'4\f @} #@})) @} @end example -Guile's manual describes ports in detail. Closing the port is actually -only necessary if you need to read the file before Lilypond finishes; in -the first example, we did not bother to do so. A bit of reformatting makes the above information easier to read: diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 90cae893c6..038f2ef6ac 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -273,23 +273,18 @@ in a CueVoice oriented by @var{dir}.") displayLilyMusic = -#(define-music-function (parser location port music) ((port?) ly:music?) +#(define-music-function (parser location music) (ly:music?) (_i "Display the LilyPond input representation of @var{music} -to @var{port}, defaulting to the console.") - (if (not port) - (set! port (current-output-port))) - (newline port) - (display-lily-music music parser port) +to the console.") + (newline) + (display-lily-music music parser) music) displayMusic = -#(define-music-function (parser location port music) ((port?) ly:music?) - (_i "Display the internal representation of @var{music} to -@var{port}, default to the console.") - (if (not port) - (set! port (current-output-port))) - (newline port) - (display-scheme-music music port) +#(define-music-function (parser location music) (ly:music?) + (_i "Display the internal representation of @var{music} to the console.") + (newline) + (display-scheme-music music) music) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 6beff26744..250defcdd2 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -98,23 +98,24 @@ First it recurses over the children, then the function is applied to music (make-music 'Music))) ;must return music. -(define*-public (display-music music #:optional (port (current-output-port))) +(define-public (display-music music) "Display music, not done with @code{music-map} for clarity of presentation." - (display music port) - (display ": { " port) + + (display music) + (display ": { ") (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element))) - (display (ly:music-mutable-properties music) port) + (display (ly:music-mutable-properties music)) (if (pair? es) - (begin (display "\nElements: {\n" port) - (for-each (lambda (m) (display-music m port)) es) - (display "}\n" port))) + (begin (display "\nElements: {\n") + (map display-music es) + (display "}\n"))) (if (ly:music? e) (begin - (display "\nChild:" port) - (display-music e port)))) - (display " }\n" port) + (display "\nChild:") + (display-music e)))) + (display " }\n") music) ;;; @@ -210,7 +211,7 @@ which often can be read back in order to generate an equivalent expression. Returns `obj'. " (pretty-print (music->make-music obj) port) - (newline port) + (newline) obj) ;;; @@ -219,15 +220,14 @@ Returns `obj'. (use-modules (srfi srfi-39) (scm display-lily)) -(define*-public (display-lily-music expr parser #:optional (port (current-output-port)) - #:key force-duration) +(define*-public (display-lily-music expr parser #:key force-duration) "Display the music expression using LilyPond syntax" (memoize-clef-names supported-clefs) (parameterize ((*indent* 0) (*previous-duration* (ly:make-duration 2)) (*force-duration* force-duration)) - (display (music->lily-string expr parser) port) - (newline port))) + (display (music->lily-string expr parser)) + (newline))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;