Hi everybody!

The attached patch implements some hooks that would allow my video generation
script to work without the requirement to patch some of lilyponds scm and ps 
files.

Knut
>From 230ad4aa3126562ab9ae87c891f7fe965c64a9de Mon Sep 17 00:00:00 2001
From: Knut Petersen <knut_peter...@t-online.de>
Date: Tue, 25 Jul 2017 08:51:12 +0200
Subject: [PATCH] Implement some hooks useful for producing score videos

Producing ps or pdf documents intended to be used as
a source for video production requires some changes to
the output at a very late stage.

Often a page needs to repeated more than once with only
changes to some kind of progress bar / line or changes
to the color of a few grobs.

Parts of this postprocessing might be passed to postscript,
parts of this postprocessing might be done in the dump-page
procedure.

Therefore this patch provides a hook to write arbitrary
code to the prolog section of postscript output and a
hook to take over the dump-page process.

Using rgb values  < 0 and > 1 for grobs is an efficient
way to pass the information that, when and for how long
an object should change its color to a late state of
processing. Therefore a way to disable the range
check implemented in color? and to disable the precision
restriction in setrgbcolor is provided.

Signed-off-by: Knut Petersen <knut_peter...@t-online.de>
---
 scm/framework-ps.scm    | 52 +++++++++++++++++++++++++++----------------------
 scm/lily.scm            |  3 ++-
 scm/output-lib.scm      |  2 +-
 scm/output-ps.scm       |  4 +++-
 scm/videoextensions.scm | 38 ++++++++++++++++++++++++++++++++++++
 5 files changed, 73 insertions(+), 26 deletions(-)
 create mode 100644 scm/videoextensions.scm

diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm
index 2cd9b5edc6..002b640189 100644
--- a/scm/framework-ps.scm
+++ b/scm/framework-ps.scm
@@ -109,29 +109,32 @@
    (if (ly:get-option 'strokeadjust) "true setstrokeadjust\n" "")
    ))
 
-(define (dump-page outputter page page-number page-count landscape?)
-  (ly:outputter-dump-string
-   outputter
-   (string-append
-    (format #f "%%Page: ~a ~a\n" page-number page-number)
-    "%%BeginPageSetup\n"
-    (if landscape?
-        "page-width output-scale lily-output-units mul mul 0 translate 90 rotate\n"
-        "")
-    "%%EndPageSetup\n"
-    "\n"
-    "gsave 0 paper-height translate set-ps-scale-to-lily-scale\n"
-    "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n"
-    "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n"
-    "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n"
-    "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n"
-    "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n"
-    "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n"
-    "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n"
-    "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n"
-    "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n"))
-  (ly:outputter-dump-stencil outputter page)
-  (ly:outputter-dump-string outputter "stroke grestore\nshowpage\n"))
+(define-public (dump-page outputter page page-number page-count landscape?)
+  (if use-ps-dump-page-replacement?
+    (ps-dump-page-replacement outputter page page-number page-count landscape?)
+    (begin
+      (ly:outputter-dump-string
+       outputter
+       (string-append
+        (format #f "%%Page: ~a ~a\n" page-number page-number)
+        "%%BeginPageSetup\n"
+        (if landscape?
+            "page-width output-scale lily-output-units mul mul 0 translate 90 rotate\n"
+            "")
+        "%%EndPageSetup\n"
+        "\n"
+        "gsave 0 paper-height translate set-ps-scale-to-lily-scale\n"
+        "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n"
+        "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n"
+        "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n"
+        "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n"
+        "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n"
+        "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n"
+        "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n"
+        "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n"
+        "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n"))
+      (ly:outputter-dump-stencil outputter page)
+      (ly:outputter-dump-string outputter "stroke grestore\nshowpage\n"))))
 
 (define (supplies-or-needs paper load-fonts?)
   (define (extract-names font)
@@ -579,6 +582,9 @@
   ;; adobe note 5002: should initialize variables before loading routines.
   (display (procset "music-drawing-routines.ps") port)
   (display (procset "lilyponddefs.ps") port)
+  (display (string-append "%%BeginResource: procset (ps-user-prolog.ps) 1 0\n"
+                          ps-user-prolog
+                          "%%EndResource\n") port)
   (display "%%EndProlog\n" port)
   (display "%%BeginSetup\ninit-lilypond-parameters\n%%EndSetup\n\n" port))
 
diff --git a/scm/lily.scm b/scm/lily.scm
index 4b3c9c7e1c..0dac46321f 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -641,7 +641,8 @@ messages into errors.")
 
     "paper.scm"
     "backend-library.scm"
-    "x11-color.scm"))
+    "x11-color.scm"
+    "videoextensions.scm"))
 ;;  - Files to be loaded last
 (define init-scheme-files-tail
   ;;  - must be after everything has been defined
diff --git a/scm/output-lib.scm b/scm/output-lib.scm
index 282cb233a7..21ff5b21e0 100644
--- a/scm/output-lib.scm
+++ b/scm/output-lib.scm
@@ -708,7 +708,7 @@ and duration-log @var{log}."
   (and (list? x)
        (= 3 (length x))
        (every number? x)
-       (every (lambda (y) (<= 0 y 1)) x)))
+       (if overloaded-rgb? #t (every (lambda (y) (<= 0 y 1)) x))))
 
 (define-public (rgb-color r g b) (list r g b))
 
diff --git a/scm/output-ps.scm b/scm/output-ps.scm
index 97909da80c..4fa054fdd0 100644
--- a/scm/output-ps.scm
+++ b/scm/output-ps.scm
@@ -206,7 +206,9 @@
 
 ;; save current color on stack and set new color
 (define (setcolor r g b)
-  (ly:format "gsave ~4l setrgbcolor\n"
+  (ly:format (if overloaded-rgb?
+                "gsave ~l setrgbcolor\n"
+                "gsave ~4l setrgbcolor\n")
              (list r g b)))
 
 ;; restore color from stack
diff --git a/scm/videoextensions.scm b/scm/videoextensions.scm
new file mode 100644
index 0000000000..0b73ecb2f3
--- /dev/null
+++ b/scm/videoextensions.scm
@@ -0,0 +1,38 @@
+;;;; This file is part of LilyPond, the GNU music typesetter.
+;;;;
+;;;; Copyright (C) 2017 Knut Petersen <knut_peter...@t-online.de>
+;;;;
+;;;; LilyPond is free software: you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License as published by
+;;;; the Free Software Foundation, either version 3 of the License, or
+;;;; (at your option) any later version.
+;;;;
+;;;; LilyPond is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;; GNU General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+
+;;
+;; If true disables the range check for rgb colors
+;; and removes the precision limit of rgb values
+;; written to the postscript output.
+;;
+(define-public overloaded-rgb? #f)
+
+
+;;
+;; This string is added to the prolog of postscript files
+;;
+(define-public ps-user-prolog "")
+
+;;
+;; If use-ps-dump-page-replacement? is set to true dump-page
+;; will pass its arguments to use-ps-dump-page-replacement.
+;; Obviously you must set! ps-dump-page-replacement to point
+;; to your replacement procedure first.
+;;
+(define-public use-ps-dump-page-replacement? #f)
+(define-public ps-dump-page-replacement #f)
-- 
2.13.3

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to