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
59 ;;; * user-interface, keybindings
60 ;;; * cleanups: (too many) global vars
62 ;;; Note: this install information is volatile
63 ;;; you'll probably want to pull all from
64 ;;; from guile-gnome-devel@gnu.org--2004 soon
76 ## 1. install gnome-devel (Debian/unstable: apt-get install gnome-devel)
78 ## 2. *** NOTE: use guile-1.6 for g-wrap and guile-gnome ***
79 ##### using GUILE CVS g-wrap/guile-gnome is experimental (read: segfaults)
84 tla register-archive a.rottmann@gmx.at--2004-main http://people.debian.org/~rotty/arch/a.rottmann@gmx.at/2004-main || true
87 ## tla get a.rottmann@gmx.at--2004-main/g-wrap--tng g-wrap
88 ## pull latest g-wrap from janneke -- this step is probably no longer
89 ## necessary when you read this
90 tla register-archive janneke@gnu.org--2004-gnome http://lilypond.org/~janneke/{arch}/2004-gnome || true
91 tla get janneke@gnu.org--2004-gnome/g-wrap--janneke g-wrap
94 rm -rf $HOME/usr/pkg/g-wrap
95 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
98 ../configure --prefix=$HOME/usr/pkg/g-wrap
101 # cp srfi-34.scm from CVS head ? --hwn
102 (cd $HOME/usr/pkg/g-wrap/share/guile/site
103 mv srfi-34.scm srfi-34.scm-g-wrap
104 cp $HOME/usr/pkg/guile/share/guile-1.7/srfi/srfi-34.scm .)
108 ## 4. get guile-gnome
109 tla register-archive guile-gnome-devel@gnu.org--2004 http://people.debian.org/~rotty/arch/guile-gnome-devel@gnu.org/2004/ || true
111 tla get guile-gnome-devel@gnu.org--2004/dists--dev guile-gnome
113 tla build-config -r configs/gnu.org/dev
116 ## 5. get the gnome canvas module
117 tla get guile-gnome-devel@gnu.org--2004/libgnomecanvas--dev libgnomecanvas
119 ## pull latest defs from janneke -- this step is probably no longer
120 ## necessary when you read this
121 ## tla register-archive janneke@gnu.org--2004-gnome http://lilypond.org/~janneke/{arch}/2004-gnome || true
123 ## tla get janneke@gnu.org--2004-gnome/defs--janneke defs
125 rm -rf $HOME/usr/pkg/guile-gnome
126 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
130 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$GUILE_LOAD_PATH
131 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$LD_LIBRARY_PATH
132 export PKG_CONFIG_PATH=$HOME/usr/pkg/g-wrap/lib/pkgconfig:$PKG_CONFIG_PATH
134 ../src/configure --prefix=$HOME/usr/pkg/guile-gnome
136 G_WRAP_MODULE_DIR=$HOME/usr/pkg/g-wrap/share/guile/site make install
138 export GUILE_LOAD_PATH=$HOME/usr/pkg/guile-gnome/share/guile:$GUILE_LOAD_PATH
139 export LD_LIBRARY_PATH=$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
140 guile -s ../src/libgnomecanvas/examples/canvas.scm
144 guile -s ../src/libgnomecanvas/examples/canvas.scm
148 (debug-enable 'backtrace)
150 (define-module (scm output-gnome))
152 (define this-module (current-module))
160 (gnome gtk gdk-event)
161 ;; the name of the module will change to canvas rsn
162 ;;(gnome gw libgnomecanvas))
166 ;;; Lily output interface --- fix silly names and docme
169 The output interface has functions for
170 * formatting stencils, and
186 The Bare minimum interface for \score { \notes c } } should
189 INTERFACE-output-expression
194 and should intercept:
197 (define (dummy . foo) #f)
199 ;; minimal intercept list:
200 (define output-interface-intercept
214 (map (lambda (x) (module-define! this-module x dummy))
215 output-interface-intercept)
217 (define-public (gnome-output-expression expr port)
218 (display (dispatch expr) port))
220 (define (dispatch expr)
222 (let ((keyword (car expr)))
224 ((eq? keyword 'some-func) "")
225 ;;((eq? keyword 'placebox) (dispatch (cadddr expr)))
227 (if (module-defined? this-module keyword)
228 (apply (eval keyword this-module) (cdr expr))
231 (string-append "undefined: " (symbol->string keyword) "\n"))
236 (define main-window #f)
237 (define main-scrolled #f)
238 (define main-canvas #f)
239 (define canvas-root #f)
240 (define page-number 0)
242 (define page-stencils #f)
243 (define output-canvas #f)
245 (define system-origin '(0 . 0))
248 (define item-locations (make-hash-table 31))
251 (define canvas-width 400)
252 (define canvas-height
253 (inexact->exact (round (* 1.42 canvas-width))))
255 (define font-paper #f)
257 ;;(define pixels-per-unit 1.0)
258 (define pixels-per-unit 2.0)
260 ;; TODO: use canvas scaling, use output-scale for paper/canvas dimensions?
261 ;;(define output-scale (* 2 2.83464566929134))
262 ;;(define output-scale 2.83464566929134)
263 (define OUTPUT-SCALE 2.83464566929134)
264 (define output-scale (* OUTPUT-SCALE pixels-per-unit))
265 ;;(define output-scale 1)
268 (define (stderr string . rest)
269 (apply format (cons (current-error-port) (cons string rest)))
270 (force-output (current-error-port)))
274 ((< i #x80) (make-string 1 (integer->char i)))
275 ((< i #x800) (list->string
277 (list (+ #xc0 (quotient i #x40))
278 (+ #x80 (modulo i #x40))))))
280 (let ((x (quotient i #x1000))
281 (y (modulo i #x1000)))
285 (+ #x80 (quotient y #x40))
286 (+ #x80 (modulo y #x40)))))))
289 (define (custom-utf8 i)
292 (utf8 (+ #xee00 i))))
295 (define (get-x-editor)
297 (set! x-editor (getenv "XEDITOR")))
303 (set! ifs (getenv "IFS")))
308 (define (spawn-editor location)
309 (let* ((line (car location))
310 (column (cadr location))
311 (file-name (caddr location))
312 (template (substring (get-x-editor) 0))
314 ;; Adhere to %l %c %f?
316 (regexp-substitute/global
317 #f "%l" (regexp-substitute/global
319 (regexp-substitute/global
320 #f "%f" template 'pre file-name 'post)
321 'pre (number->string column)
323 'pre (number->string line) 'post)))
325 (stderr "spawning: ~s\n" command)
326 (if (= (primitive-fork) 0)
327 (let ((command-list (string-split command #\ )));; (get-ifs))))
328 (apply execlp command-list)
331 (define location-callback spawn-editor)
333 (define (item-event item event . data)
334 (case (gdk-event:type event)
335 ((enter-notify) (gobject-set-property item 'fill-color "white"))
336 ((leave-notify) (gobject-set-property item 'fill-color "black"))
338 (let ((location (hashq-ref item-locations item #f)))
340 (location-callback location)
341 (stderr "no location\n"))))
342 ((2button-press) (gobject-set-property item 'fill-color "red")))
345 ;; TODO: one list per-page
346 (define text-items '())
347 (define (scale-canvas factor)
348 (set! pixels-per-unit (* pixels-per-unit factor))
349 (set-pixels-per-unit main-canvas pixels-per-unit)
352 (let ((scale (gobject-get-property x 'scale))
353 (points (gobject-get-property x 'size-points)))
354 ;;(gobject-set-property x 'scale pixels-per-unit)
355 (gobject-set-property x 'size-points (* points factor))))
358 (define (key-press-event item event . data)
359 (let ((keyval (gdk-event-key:keyval event))
360 (mods (gdk-event-key:modifiers event)))
361 (cond ((and (or (eq? keyval gdk:q)
363 (equal? mods '(control-mask modifier-mask)))
365 ((and #t ;;(null? mods)
366 (eq? keyval gdk:plus))
368 ((and #t ;; (null? mods)
369 (eq? keyval gdk:minus))
371 ((or (eq? keyval gdk:Page-Up)
372 (eq? keyval gdk:BackSpace))
373 (dump-page (1- page-number)))
374 ((or (eq? keyval gdk:Page-Down)
375 (eq? keyval gdk:space))
376 (dump-page (1+ page-number))))
379 (define (char font i)
380 (text font (utf8 i)))
382 (define (placebox x y expr)
383 (stderr "item: ~S\n" expr)
386 ;; FIXME ugly hack to skip #unspecified ...
387 (if (and item (not (eq? item (if #f #f))))
390 (* output-scale (+ (car system-origin) x))
391 (* output-scale (- (car system-origin) y)))
392 (affine-relative item output-scale 0 0 output-scale 0 0)
394 (gtype-instance-signal-connect item 'event item-event)
396 (hashq-set! item-locations item location))
400 (define (round-filled-box breapth width depth height blot-diameter)
401 ;; FIXME: no rounded corners on rectangle
402 (make <gnome-canvas-rect>
404 #:x1 (- breapth) #:y1 depth #:x2 width #:y2 (- height)
405 #:fill-color "black" #:width-units blot-diameter))
407 ;;(define (fontify font expr)
410 (define (main outputter pages)
411 (let* ((window (make <gtk-window> #:type 'toplevel))
412 (button (make <gtk-button> #:label "Exit"))
413 (next (make <gtk-button> #:label "Next"))
414 (prev (make <gtk-button> #:label "Previous"))
415 (canvas (make <gnome-canvas>))
416 (vbox (make <gtk-vbox> #:homogeneous #f))
417 (hbox (make <gtk-hbox> #:homogeneous #f))
418 (scrolled (make <gtk-scrolled-window>)))
422 (add scrolled canvas)
424 ;;(set-size-request button canvas-width 20)
426 ;;(set-child-packing vbox button #f #f 0 'end)
429 (set-size-request hbox canvas-width 25)
430 (set-child-packing vbox hbox #f #f 0 'end)
432 (set-child-packing hbox button #f #f 0 'end)
433 ;;(set-size-request next 40 25)
434 ;;(set-size-request prev 40 25)
435 (set-size-request button (/ canvas-width 2) 25)
442 (gtype-instance-signal-connect button 'clicked
443 (lambda (b) (gtk-main-quit)))
444 (gtype-instance-signal-connect next 'clicked
445 (lambda (b) (dump-page (1+ page-number))))
446 (gtype-instance-signal-connect prev 'clicked
447 (lambda (b) (dump-page (1- page-number))))
450 (set-size-request canvas canvas-width canvas-height)
451 (set-scroll-region canvas 0 0 2000 4000)
452 (set-pixels-per-unit canvas pixels-per-unit)
454 (gtype-instance-signal-connect window 'key-press-event key-press-event)
458 (set! canvas-root (root canvas))
459 (set! main-canvas canvas)
460 (set! main-window window)
461 (set! output-canvas outputter)
462 (set! page-stencils pages)
463 (set! main-scrolled scrolled)
468 (define (pango-font-name font)
470 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
471 "lilypond-feta, regular 32")
473 (ly:font-filename font))))
475 (define (pango-font-size font)
476 (let* ((designsize (ly:font-design-size font))
477 (magnification (* (ly:font-magnification font)))
478 ;;(ops (ly:paper-lookup paper 'outputscale))
479 ;;(ops (* pixels-per-unit OUTPUT-SCALE))
480 ;;(ops (* pixels-per-unit pixels-per-unit))
481 (ops (* (/ 12 20) (* pixels-per-unit pixels-per-unit)))
482 (scaling (* ops magnification designsize)))
485 (define (text font string)
486 (stderr "font-name: ~S\n" (ly:font-name font))
487 ;; TODO s/filename/file-name/
488 (stderr "font-filename: ~S\n" (ly:font-filename font))
490 (stderr "pango-font-name: ~S\n" (pango-font-name font))
491 (stderr "pango-font-size: ~S\n" (pango-font-size font))
495 (make <gnome-canvas-text>
498 ;; #:font "new century schoolbook, i bold 20"
499 #:font (pango-font-name font)
501 #:size-points (pango-font-size font)
502 ;;#:size (pango-font-size font)
505 ;;apparently no effect :-(
515 (define (filledbox a b c d)
516 (round-filled-box a b c d 0.001))
518 ;; WTF is this in every backend?
519 (define (horizontal-line x1 x2 thickness)
520 ;;(let ((thickness 2))
521 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
523 (define (start-system origin . rest)
524 (set! system-origin origin))
526 ;; origin -- bad name
527 (define (define-origin file line col)
528 ;; ughr, why is this not passed as [part of] stencil object
529 (set! location (if (procedure? point-and-click)
530 ;; duh, only silly string append
531 ;; (point-and-click line col file)
535 (define (dump-page number)
536 (if (or (not page-stencils)
538 (>= number (vector-length page-stencils)))
539 (stderr "No such page: ~S\n" (1+ number))
541 (set! page-number number)
543 ;; no destroy method for gnome-canvas-text?
544 ;;(map destroy (gtk-container-get-children main-canvas))
545 ;;(map destroy text-items)
547 ;; UGHR - destroying the whole canvas....
549 (not (null? text-items)))
550 (let* ((canvas (make <gnome-canvas>))
551 (root (root canvas)))
553 (destroy main-canvas)
554 (add main-scrolled canvas)
557 (set-size-request canvas canvas-width canvas-height)
558 (set-scroll-region canvas 0 0 2000 4000)
559 (set-pixels-per-unit canvas pixels-per-unit)
562 (set! main-canvas canvas)
563 (set! canvas-root root)
564 (set! text-items '())))
566 (ly:outputter-dump-stencil output-canvas
567 (vector-ref page-stencils page-number)))))