3 ;;;; implement network-based output (socket) in Scheme
5 (define-module (scm output-socket)
14 (define format ergonomic-simple-format)
16 (define (event-cause grob)
18 ((cause (ly:grob-property grob 'cause)))
20 (if (ly:stream-event? cause)
24 (define (grob-bbox grob offset)
26 ((x-ext (ly:grob-extent grob grob X))
27 (y-ext (ly:grob-extent grob grob Y))
31 (if (interval-empty? x-ext)
32 (set! x-ext '(0 . 0)))
34 (if (interval-empty? y-ext)
35 (set! y-ext '(0 . 0)))
37 (list (+ x (car x-ext))
42 (define (escape-string str)
43 (string-regexp-substitute
45 (string-regexp-substitute "\"" "\\\"" str)))
47 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 (define (bezier-sandwich lst thick)
52 (format "bezier_sandwich ~a [~a]"
57 (format "(~a,~a)" (car x) (cdr x)))
61 (define (draw-line thick x1 y1 x2 y2)
62 (format "drawline ~a ~a ~a ~a ~a"
65 (define (grob-cause offset grob)
67 ((cause (event-cause grob))
68 (tag (if (and cause (integer? (ly:event-property cause 'input-tag)))
69 (ly:event-property cause 'input-tag)
71 (name (assoc-get 'name (ly:grob-property grob 'meta))))
74 (append (list "cause ~a \"~a\" ~a ~a ~a ~a\n" tag name)
75 (grob-bbox grob offset)))))
77 (define (named-glyph font glyph)
78 (format "glyphshow ~a \"~a\" ~a \"~a\""
79 (ly:font-glyph-name-to-charcode font glyph)
81 (modified-font-metric-font-scaling font)
87 (define (placebox x y s)
88 (if (not (string-null? s))
89 (format "at ~a ~a ~a\n" x y s)
92 (define (polygon xy-coords blot do-fill)
93 (format "polygon ~a ~a ~a"
95 (if do-fill "True" "False")
96 (string-join (map number->string xy-coords))))
98 (define (round-filled-box breapth width depth height blot-diameter)
99 (format "draw_round_box ~a ~a ~a ~a ~a"
100 breapth width depth height blot-diameter))
102 (define (utf-8-string descr string)
103 (format "utf-8 \"~a\" \"~a\""
104 (escape-string descr)
105 ;; don't want unescaped spaces.
106 (escape-string string)))