First pass at organizing.
[lilypond.git] / ly / graphviz-init.ly
blobcae11b1a29a191af49a56e78c80e325c915c4613
1 \version "2.11.15"
3 #(use-modules (scm graphviz))
5 #(define last-grob-action '())
7 #(define sym-blacklist '())
8 #(define sym-whitelist '())
10 #(define file-line-blacklist '())
11 #(define file-line-whitelist '())
13 #(define grob-blacklist '())
14 #(define grob-whitelist '())
16 #(define (blacklist-symbol sym)
17 (set! sym-blacklist (cons sym sym-blacklist)))
19 #(define (whitelist-symbol sym)
20 (set! sym-whitelist (cons sym sym-whitelist)))
22 #(define (whitelist-grob str)
23 (set! grob-whitelist (cons str grob-whitelist)))
25 #(define graph (make-empty-graph (ly:parser-output-name parser)))
27 #(define (grob-name g)
28 (let* ((meta (ly:grob-property g 'meta))
29 (name-pair (assq 'name meta)))
30 (if (pair? name-pair)
31 (cdr name-pair)
32 #f)))
34 % an event is relevant if
35 % (it is on some whitelist or all whitelists are empty)
36 % and
37 % (it isn't on any blacklist)
39 #(define (relevant? grob file line prop)
40 (let ((file-line `(,file . ,line)))
41 (and
42 (or
43 (= 0 (length file-line-whitelist) (length sym-whitelist) (length grob-whitelist))
44 (memq prop sym-whitelist)
45 (memq (grob-name grob) grob-whitelist)
46 (member file-line file-line-whitelist))
47 (and
48 (not (memq prop sym-blacklist))
49 (not (memq (grob-name grob) grob-blacklist))
50 (not (member file-line file-line-blacklist))))))
52 #(define (grob-event-node grob label cluster)
53 (let ((node-id (add-node graph label cluster))
54 (prev (assv grob last-grob-action)))
55 (if (pair? prev)
56 (add-edge graph (cdr prev) node-id))
57 (set! last-grob-action (assv-set! last-grob-action grob node-id))))
59 #(define (truncate-value val)
60 (let ((val-str (format "~a" val)))
61 (string-take val-str (min 50 (string-length val-str)))))
63 #(define (grob-mod grob file line func prop val)
64 (let* ((val-str (truncate-value val))
65 (label (format "~a\\n~a:~a\\n~a <- ~a" (grob-name grob) file line prop val-str)))
66 (if (relevant? grob file line prop)
67 (grob-event-node grob label file))))
69 #(define (grob-cache grob prop callback value)
70 (let* ((val-str (truncate-value value))
71 (label (format "caching ~a.~a\\n~a -> ~a" (grob-name grob) prop callback value)))
72 (if (relevant? grob #f #f prop)
73 (grob-event-node grob label #f))))
75 #(define (grob-create grob file line func)
76 (let ((label (format "~a\\n~a:~a" (grob-name grob) file line)))
77 (grob-event-node grob label file)))
79 #(ly:set-grob-modification-callback grob-mod)
80 #(ly:set-property-cache-callback grob-cache)
81 %#(ly:set-grob-creation-callback grob-create)