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 (draw-line thick x1 y1 x2 y2)
52 (format #f "drawline ~a ~a ~a ~a ~a"
55 (define (grob-cause offset grob)
57 ((cause (event-cause grob))
58 (tag (if (and cause (integer? (ly:event-property cause 'input-tag)))
59 (ly:event-property cause 'input-tag)
61 (name (assoc-get 'name (ly:grob-property grob 'meta))))
64 "cause ~a \"~a\" ~a ~a ~a ~a\n" tag name
65 (grob-bbox grob offset))))
67 (define (named-glyph font glyph)
68 (format #f "glyphshow ~a \"~a\" ~a \"~a\""
69 (ly:font-glyph-name-to-charcode font glyph)
71 (modified-font-metric-font-scaling font)
77 (define (placebox x y s)
78 (if (not (string-null? s))
79 (format #f "at ~a ~a ~a\n" x y s)
82 (define (polygon xy-coords blot do-fill)
83 (format #f "polygon ~a ~a ~a"
85 (if do-fill "True" "False")
86 (string-join (map number->string xy-coords))))
88 (define (round-filled-box breapth width depth height blot-diameter)
89 (format #f "draw_round_box ~a ~a ~a ~a ~a"
90 breapth width depth height blot-diameter))
92 (define (utf-8-string descr string)
93 (format #f "utf-8 \"~a\" \"~a\""
95 ;; don't want unescaped spaces.
96 (escape-string string)))