lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add means to display objects accessible from a grob (issue 217260043 by


From: david . nalesnik
Subject: Add means to display objects accessible from a grob (issue 217260043 by address@hidden)
Date: Tue, 24 Mar 2015 16:38:52 +0000

Reviewers: ,

Message:
Please review.  Thanks!

Description:
Add means to display objects accessible from a grob

A convenient means of displaying the grobs and grob-arrays pointed to by
various internal properties of a given grob would be very helpful for
debugging and development purposes.  For example, it would facilitate
the
creation of advanced tweaks, which frequently require "lateral" access
to other grobs.

The output of the function 'grob::display-objects' shows all of the
grobs
accessible to a given grob through ly:grob-object, along with the
relevant
interfaces and properties.  It includes properties which are empty: not
all
properties within an interface may be set for or used by a grob
supporting
that interface.

Please review this at https://codereview.appspot.com/217260043/

Affected files (+38, -0 lines):
  M scm/output-lib.scm


Index: scm/output-lib.scm
diff --git a/scm/output-lib.scm b/scm/output-lib.scm
index 2b2a65c719f12ec575c6587c206180e8bf89fb8b..a73e2c0324977e6046d45c8cfb736bd59ec4c644 100644
--- a/scm/output-lib.scm
+++ b/scm/output-lib.scm
@@ -130,6 +130,44 @@

     line-thickness))

+(define (grob::objects-from-interface grob iface)
+  "For grob @var{grob} return the name and contents of all properties
+ within interface @var{iface} having type @code{ly:grob?} or
+ @code{ly:grob-array?}."
+  (let* ((iface-entry (hashq-ref (ly:all-grob-interfaces) iface))
+         (props (if iface-entry (last iface-entry) '()))
+         (pointer-props
+          (filter
+           (lambda (prop)
+             (let ((type (object-property prop 'backend-type?)))
+               (or (eq? type ly:grob?)
+                   (eq? type ly:grob-array?))))
+           props)))
+    (if (null? pointer-props)
+        '()
+        (list iface
+          (map
+           (lambda (prop) (list prop (ly:grob-object grob prop)))
+           pointer-props)))))
+
+(define-public (grob::all-objects grob)
+  "Return a list of the names and contents of all properties having type
+ @code{ly:grob?} or @code{ly:grob-array?} for all interfaces supported by
+ grob @var{grob}."
+  (let loop ((ifaces (ly:grob-interfaces grob)) (result '()))
+    (if (null? ifaces)
+        (cons grob (list result))
+        (let ((entry (grob::objects-from-interface grob (car ifaces))))
+          (if (pair? entry)
+              (loop (cdr ifaces) (append result (list entry)))
+              (loop (cdr ifaces) result))))))
+
+(use-modules (ice-9 pretty-print))
+(define-public (grob::display-objects grob)
+  "Display all objects stored in properties of grob @var{grob}."
+  (pretty-print (grob::all-objects grob))
+  (newline))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; beam slope






reply via email to

[Prev in Thread] Current Thread [Next in Thread]