X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Foutput-socket.scm;h=28e22f72a3c3ba3733d290b443e8b1a47d804a91;hb=e2b40e567fec0a6799919271dba9b8df6a593bcf;hp=52f80348ee3bc989f3b190f2fe7d3b88ef5c08b4;hpb=4e34058754b48872b6dc751d833c38da4e6706c6;p=lilypond.git diff --git a/scm/output-socket.scm b/scm/output-socket.scm index 52f80348ee..28e22f72a3 100644 --- a/scm/output-socket.scm +++ b/scm/output-socket.scm @@ -1,104 +1,106 @@ +;;;; output-socket.scm +;;;; +;;;; implement network-based output (socket) in Scheme (define-module (scm output-socket) - #:re-export (quote) - ) + #:re-export (quote)) (use-modules (guile) (srfi srfi-1) (srfi srfi-13) (lily)) -(define (dummy . rest) - "") -(for-each - (lambda (x) - (module-define! (current-module) - x - dummy)) - - (ly:all-stencil-expressions)) +(define format ergonomic-simple-format) +(define (event-cause grob) + (let* + ((cause (ly:grob-property grob 'cause))) -(define-public (draw-line thick x1 y1 x2 y2) - (format "drawline ~a ~a ~a ~a ~a" - thick x1 y2 x2 y2)) + (if (ly:stream-event? cause) + cause + #f))) -(define-public (polygon xy-coords blot do-fill) - (format "polygon ~a ~a ~a" - blot - (if do-fill "True" "False") - (string-join - (map number->string xy-coords)) - )) +(define (grob-bbox grob offset) + (let* + ((x-ext (ly:grob-extent grob grob X)) + (y-ext (ly:grob-extent grob grob Y)) + (x (car offset)) + (y (cdr offset))) + + (if (interval-empty? x-ext) + (set! x-ext '(0 . 0))) + + (if (interval-empty? y-ext) + (set! y-ext '(0 . 0))) + + (list (+ x (car x-ext)) + (+ y (car y-ext)) + (+ x (cdr x-ext)) + (+ y (cdr y-ext))))) + +(define (escape-string str) + (string-regexp-substitute + " " "\\040" + (string-regexp-substitute "\"" "\\\"" str))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; stencil commands +;;; + +(define (bezier-sandwich lst thick) + (format #f "bezier_sandwich ~a [~a]" + thick + (string-append + (string-join (map + (lambda (x) + (format #f "(~a,~a)" (car x) (cdr x))) + lst) + ",")))) + +(define (draw-line thick x1 y1 x2 y2) + (format #f "drawline ~a ~a ~a ~a ~a" + thick x1 y2 x2 y2)) -(define-public (named-glyph font glyph) - (format "glyphshow ~a \"~a\" ~a \"~a\"" +(define (grob-cause offset grob) + (let* + ((cause (event-cause grob)) + (tag (if (and cause (integer? (ly:event-property cause 'input-tag))) + (ly:event-property cause 'input-tag) + -1)) + (name (assoc-get 'name (ly:grob-property grob 'meta)))) + + (apply format #f + "cause ~a \"~a\" ~a ~a ~a ~a\n" tag name + (grob-bbox grob offset)))) + +(define (named-glyph font glyph) + (format #f "glyphshow ~a \"~a\" ~a \"~a\"" (ly:font-glyph-name-to-charcode font glyph) (ly:font-name font) (modified-font-metric-font-scaling font) - glyph - )) - -(define-public (placebox x y s) - (format "at ~a ~a ~a\n" x y s)) + glyph)) -(define-public (round-filled-box breapth width depth height blot-diameter) - (format "draw_round_box ~a ~a ~a ~a ~a" - breapth width depth height blot-diameter - )) +(define (no-origin) + "nocause\n") -(define (music-cause grob) - (let* - ((cause (ly:grob-property grob 'cause))) +(define (placebox x y s) + (if (not (string-null? s)) + (format #f "at ~a ~a ~a\n" x y s) + "")) - (cond - ((ly:music? cause) cause) - ((ly:grob? cause) (music-cause cause)) - (else - #f)))) +(define (polygon xy-coords blot do-fill) + (format #f "polygon ~a ~a ~a" + blot + (if do-fill "True" "False") + (string-join (map number->string xy-coords)))) -(define (grob-bbox grob offset) - (let* - ((x-ext (ly:grob-extent grob grob X)) - (y-ext (ly:grob-extent grob grob Y)) - (x (car offset)) - (y (cdr offset)) - ) - - (map (lambda (x) - (if (inf? x) 0.0 x)) - - (list (+ x (car x-ext)) - (+ y (car y-ext)) - (+ x (cdr x-ext)) - (+ y (cdr y-ext))) - ))) - -(define-public (no-origin) - "nocause\n") +(define (round-filled-box breapth width depth height blot-diameter) + (format #f "draw_round_box ~a ~a ~a ~a ~a" + breapth width depth height blot-diameter)) -(define-public (grob-cause offset grob) - (let* - ((cause (music-cause grob)) - (tag (if (and cause (integer? (ly:music-property cause 'input-tag))) - (ly:music-property cause 'input-tag) - -1)) - (name (cdr (assoc 'name (ly:grob-property grob 'meta)))) - ) - - (apply format - (append (list "cause ~a \"~a\" ~a ~a ~a ~a\n" - tag name) - - (grob-bbox grob offset)) - ))) - -(define-public (glyph-string - postscript-font-name - size cid? - x-y-named-glyphs) - - (format "text \"~a\" ~a ~a " postscript-font-name size - (string-join (map (lambda (xyn) (caddr xyn)) - x-y-named-glyphs)))) +(define (utf-8-string descr string) + (format #f "utf-8 \"~a\" \"~a\"" + (escape-string descr) + ;; don't want unescaped spaces. + (escape-string string)))