1 ;;;; output-gnome.scm -- implement GNOME canvas output
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;;; HIP -- hack in progress
12 ;;; * guile-1.6.4 (NOT CVS)
13 ;;; * Rotty's g-wrap--tng, possibly Janneke's if you have libffi-3.4.
14 ;;; * lilypond branch: lilypond_2_3_2b; the framework-* backend
15 ;;; loads output-gnome.scm at startup, which seems to break g-wrapped
18 ;;; see also: guile-gtk-general@gnu.org
22 ;;; * Install g-wrap, guile-gnome (see script below)
24 ;;; * Use latin1 encoding for gnome backend, do
26 ;;; make -C mf ENCODING_FILE=$(kpsewhich cork.enc)
27 ;;; (cd mf/out && mkfontdir)
28 ;;; xset +fp $(pwd)/mf/out
33 # do not use guile CVS:
34 export PATH=/usr/bin/:$PATH
35 # use g-wrap and guile-gnome from usr/pkg
36 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$HOME/usr/pkg/g-wrap/share/guile/site/g-wrap:$HOME/usr/pkg/guile-gnome/share/guile
37 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$HOME/usr/pkg/guile-gnome/lib
40 ;;; * Set XEDITOR and add
41 ;;; #(ly:set-point-and-click 'line-column)
42 ;;; to your .ly to get point-and-click
44 ;;; * Run lily: lilypond-bin -fgnome input/simple-song.ly
47 ;;; todo: hmm --output-base broken?
48 ;;; ### cd mf && mftrace --encoding=$(kpsewhich cork.enc) --autotrace --output-base=feta-cork-20 feta20.mf && mv feta20.pfa out
51 ;;; * pango+feta font (see archives gtk-i18n-list@gnome.org and
53 ;;; - wait for/help with pango 1.6
54 ;;; - convert feta to OpenType (CFF) or TrueType (fontforge?)
55 ;;; - hack feta20/feta20.pfa?:
56 ;;; * font, canvas, scaling?
57 ;;; * implement missing stencil functions
58 ;;; * implement missing commands (next, prev? page)
59 ;;; * user-interface, keybindings
61 ;;; Note: this install information is volatile
62 ;;; you'll probably want to pull all from
63 ;;; from guile-gnome-devel@gnu.org--2004 soon
75 ## 1. install gnome-devel (Debian/unstable: apt-get install gnome-devel)
77 ## 2. *** NOTE: use guile-1.6 for g-wrap and guile-gnome ***
78 ##### using GUILE CVS g-wrap/guile-gnome is experimental (read: segfaults)
83 tla register-archive a.rottmann@gmx.at--2004-main http://people.debian.org/~rotty/arch/a.rottmann@gmx.at/2004-main || true
86 ## tla get a.rottmann@gmx.at--2004-main/g-wrap--tng g-wrap
87 ## pull latest g-wrap from janneke -- this step is probably no longer
88 ## necessary when you read this
89 tla register-archive janneke@gnu.org--2004-gnome http://lilypond.org/~janneke/{arch}/2004-gnome || true
90 tla get janneke@gnu.org--2004-gnome/g-wrap--janneke g-wrap
93 rm -rf $HOME/usr/pkg/g-wrap
94 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
97 ../configure --prefix=$HOME/usr/pkg/g-wrap
100 # cp srfi-34.scm from CVS head ? --hwn
101 (cd $HOME/usr/pkg/g-wrap/share/guile/site
102 mv srfi-34.scm srfi-34.scm-g-wrap
103 cp $HOME/usr/pkg/guile/share/guile-1.7/srfi/srfi-34.scm .)
107 ## 4. get guile-gnome
108 tla register-archive guile-gnome-devel@gnu.org--2004 http://people.debian.org/~rotty/arch/guile-gnome-devel@gnu.org/2004/ || true
110 tla get guile-gnome-devel@gnu.org--2004/dists--dev guile-gnome
112 tla build-config -r configs/gnu.org/dev
115 ## 5. get the gnome canvas module
116 tla get guile-gnome-devel@gnu.org--2004/libgnomecanvas--dev libgnomecanvas
118 ## pull latest defs from janneke -- this step is probably no longer
119 ## necessary when you read this
120 ## tla register-archive janneke@gnu.org--2004-gnome http://lilypond.org/~janneke/{arch}/2004-gnome || true
122 ## tla get janneke@gnu.org--2004-gnome/defs--janneke defs
124 rm -rf $HOME/usr/pkg/guile-gnome
125 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
129 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$GUILE_LOAD_PATH
130 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$LD_LIBRARY_PATH
131 export PKG_CONFIG_PATH=$HOME/usr/pkg/g-wrap/lib/pkgconfig:$PKG_CONFIG_PATH
133 ../src/configure --prefix=$HOME/usr/pkg/guile-gnome
135 G_WRAP_MODULE_DIR=$HOME/usr/pkg/g-wrap/share/guile/site make install
137 export GUILE_LOAD_PATH=$HOME/usr/pkg/guile-gnome/share/guile:$GUILE_LOAD_PATH
138 export LD_LIBRARY_PATH=$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
139 guile -s ../src/libgnomecanvas/examples/canvas.scm
143 guile -s ../src/libgnomecanvas/examples/canvas.scm
147 (debug-enable 'backtrace)
149 (define-module (scm output-gnome)
152 (define this-module (current-module))
160 (gnome gtk gdk-event)
161 (gnome gw libgnomecanvas))
164 ;;; Lily output interface --- fix silly names and docme
167 The output interface has functions for
168 * formatting stencils, and
184 The Bare minimum interface for \score { \notes c } } should
187 INTERFACE-output-expression
192 and should intercept:
195 (define (dummy . foo) #f)
197 ;; minimal intercept list:
198 (define output-interface-intercept
212 (map (lambda (x) (module-define! this-module x dummy))
213 output-interface-intercept)
215 (define-public (gnome-output-expression expr port)
216 (display (dispatch expr) port))
218 (define (dispatch expr)
220 (let ((keyword (car expr)))
222 ((eq? keyword 'some-func) "")
223 ;;((eq? keyword 'placebox) (dispatch (cadddr expr)))
225 (if (module-defined? this-module keyword)
226 (apply (eval keyword this-module) (cdr expr))
229 (string-append "undefined: " (symbol->string keyword) "\n"))
234 (define main-window #f)
235 (define main-canvas #f)
236 (define canvas-root #f)
238 (define system-origin '(0 . 0))
241 (define item-locations (make-hash-table 31))
244 (define canvas-width 400)
245 (define canvas-height
246 (inexact->exact (round (* 1.42 canvas-width))))
248 (define font-paper #f)
250 ;;(define pixels-per-unit 1.0)
251 (define pixels-per-unit 2.0)
253 ;; TODO: use canvas scaling, use output-scale for paper/canvas dimensions?
254 ;;(define output-scale (* 2 2.83464566929134))
255 ;;(define output-scale 2.83464566929134)
256 (define OUTPUT-SCALE 2.83464566929134)
257 (define output-scale (* OUTPUT-SCALE pixels-per-unit))
258 ;;(define output-scale 1)
261 (define (stderr string . rest)
262 (apply format (cons (current-error-port) (cons string rest)))
263 (force-output (current-error-port)))
267 ((< i #x80) (make-string 1 (integer->char i)))
268 ((< i #x800) (list->string
270 (list (+ #xc0 (quotient i #x40))
271 (+ #x80 (modulo i #x40))))))
273 (let ((x (quotient i #x1000))
274 (y (modulo i #x1000)))
278 (+ #x80 (quotient y #x40))
279 (+ #x80 (modulo y #x40)))))))
282 (define (custom-utf8 i)
285 (utf8 (+ #xee00 i))))
288 (define (get-x-editor)
290 (set! x-editor (getenv "XEDITOR")))
296 (set! ifs (getenv "IFS")))
301 (define (spawn-editor location)
302 (let* ((line (car location))
303 (column (cadr location))
304 (file-name (caddr location))
305 (template (substring (get-x-editor) 0))
307 ;; Adhere to %l %c %f?
309 (regexp-substitute/global
310 #f "%l" (regexp-substitute/global
312 (regexp-substitute/global
313 #f "%f" template 'pre file-name 'post)
314 'pre (number->string column)
316 'pre (number->string line) 'post)))
318 (stderr "spawning: ~s\n" command)
319 (if (= (primitive-fork) 0)
320 (let ((command-list (string-split command #\ )));; (get-ifs))))
321 (apply execlp command-list)
324 (define location-callback spawn-editor)
326 (define (item-event item event . data)
327 (case (gdk-event:type event)
328 ((enter-notify) (gobject-set-property item 'fill-color "white"))
329 ((leave-notify) (gobject-set-property item 'fill-color "black"))
331 (let ((location (hashq-ref item-locations item #f)))
333 (location-callback location)
334 (stderr "no location\n"))))
335 ((2button-press) (gobject-set-property item 'fill-color "red")))
338 ;; TODO: one list per-page
339 (define text-items '())
340 (define (scale-canvas factor)
341 (set! pixels-per-unit (* pixels-per-unit factor))
342 (set-pixels-per-unit main-canvas pixels-per-unit)
345 (let ((scale (gobject-get-property x 'scale))
346 (points (gobject-get-property x 'size-points)))
347 ;;(stderr "scaling item:~S to ~S\n" x scale)
348 ;; (stderr "scaling item:~S to ~S\n" x points)
349 (gobject-set-property x 'size-points (* points factor))))
350 ;;(gobject-set-property x 'scale pixels-per-unit)
351 ;;(gobject-set-property x 'scale-set #t))
354 (define (key-press-event item event . data)
355 (let ((keyval (gdk-event-key:keyval event))
356 (mods (gdk-event-key:modifiers event)))
357 (cond ((and (or (eq? keyval gdk:q)
359 (equal? mods '(control-mask modifier-mask)))
361 ((and #t ;;(null? mods)
362 (eq? keyval gdk:plus))
364 ((and #t ;; (null? mods)
365 (eq? keyval gdk:minus))
369 (define (char font i)
370 (text font (utf8 i)))
372 (define (placebox x y expr)
373 (stderr "item: ~S\n" expr)
376 ;; FIXME ugly hack to skip #unspecified ...
377 (if (and item (not (eq? item (if #f #f))))
380 (* output-scale (+ (car system-origin) x))
381 (* output-scale (- (car system-origin) y)))
382 (affine-relative item output-scale 0 0 output-scale 0 0)
384 (gtype-instance-signal-connect item 'event item-event)
386 (hashq-set! item-locations item location))
390 (define (round-filled-box breapth width depth height blot-diameter)
391 ;; FIXME: no rounded corners on rectangle
392 (make <gnome-canvas-rect>
394 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
395 #:fill-color "black" #:width-units blot-diameter))
397 (define (fontify font expr)
403 (define (header . rest)
404 (let* ((window (make <gtk-window> #:type 'toplevel))
405 (button (make <gtk-button> #:label "Exit"))
406 (canvas (make <gnome-canvas>))
407 (vbox (make <gtk-vbox> #:homogeneous #f))
408 (scrolled (make <gtk-scrolled-window>)))
412 (add scrolled canvas)
414 (set-size-request button canvas-width 20)
416 (set-child-packing vbox button #f #f 0 'end)
418 (gtype-instance-signal-connect button 'clicked
419 (lambda (b) (gtk-main-quit)))
422 (set-size-request canvas canvas-width canvas-height)
423 (set-scroll-region canvas 0 0 2000 4000)
425 (gtype-instance-signal-connect window 'key-press-event key-press-event)
427 (set-pixels-per-unit canvas pixels-per-unit)
429 (set! canvas-root (root canvas))
430 (set! main-canvas canvas)
431 (set! main-window window)))
433 (define (pango-font-name font)
435 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
436 "lilypond-feta, regular 32")
438 (ly:font-filename font))))
440 (define (pango-font-size font)
441 (let* ((designsize (ly:font-design-size font))
442 (magnification (* (ly:font-magnification font)))
443 ;;(ops (ly:paper-lookup paper 'outputscale))
444 ;;(ops (* pixels-per-unit OUTPUT-SCALE))
445 ;;(ops (* pixels-per-unit pixels-per-unit))
446 (ops (* (/ 12 20) (* pixels-per-unit pixels-per-unit)))
447 (scaling (* ops magnification designsize)))
450 (define (text font string)
451 (stderr "font-name: ~S\n" (ly:font-name font))
452 ;; TODO s/filename/file-name/
453 (stderr "font-filename: ~S\n" (ly:font-filename font))
455 (stderr "pango-font-name: ~S\n" (pango-font-name font))
456 (stderr "pango-font-size: ~S\n" (pango-font-size font))
460 (make <gnome-canvas-text>
463 ;; #:font "new century schoolbook, i bold 20"
464 #:font (pango-font-name font)
466 #:size-points (pango-font-size font)
467 ;;#:size (pango-font-size font)
470 ;;apparently no effect :-(
480 (define (filledbox a b c d)
481 (round-filled-box a b c d 0.001))
483 ;; WTF is this in every backend?
484 (define (horizontal-line x1 x2 thickness)
485 ;;(let ((thickness 2))
486 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
488 (define (start-system origin . rest)
489 (set! system-origin origin))
491 ;; origin -- bad name
492 (define (define-origin file line col)
493 ;; ughr, why is this not passed as [part of] stencil object
494 (set! location (if (procedure? point-and-click)
495 ;; duh, only silly string append
496 ;; (point-and-click line col file)