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
10 ;;; This first working version needs Rotty's g-wrap--tng.
11 ;;; (janneke's guile-gnome patches now in main archive).
12 ;;; see also: guile-gtk-general@gnu.org
16 ;;; * Use latin1 encoding for gnome backend, do
18 ;;; make -C mf ENCODING_FILE=$(kpsewhich cork.enc)
19 ;;; (cd mf/out && mkfontdir)
20 ;;; xset +fp $(pwd)/mf/out
22 ;;; * lilypond-bin -fgnome input/simple-song.ly
24 ;;; todo: hmm --output-base broken?
25 ;;; ### cd mf && mftrace --encoding=$(kpsewhich cork.enc) --autotrace --output-base=feta-cork-20 feta20.mf && mf feta20.pfa out
27 ;;; Set XEDITOR and add
28 ;;; #(ly:set-point-and-click 'line-column)
29 ;;; to your .ly to get point-and-click
32 ;;; * pango+feta font (see archives gtk-i18n-list@gnome.org and
34 ;;; - wait for/help with pango 1.6
35 ;;; - convert feta to OpenType (CFF) or TrueType (fontforge?)
36 ;;; - hack feta20/feta20.pfa?:
37 ;;; * font, canvas, scaling?
38 ;;; * implement missing stencil functions
39 ;;; * implement missing commands (next, prev? page)
40 ;;; * user-interface, keybindings
42 ;;; Note: this install information is volatile
43 ;;; you'll probably want to pull all from
44 ;;; from guile-gnome-devel@gnu.org--2004 soon
46 ;;; move this into workbook?
49 ## install gnome-devel
51 ## use guile-1.6 for g-wrap/guile-gnome
55 tla register-archive a.rottmann@gmx.at--2004-main http://people.debian.org/~rotty/arch/a.rottmann@gmx.at/2004-main || true
58 tla get a.rottmann@gmx.at--2004-main/g-wrap--tng gw-pristine
61 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
64 ../configure --prefix=$HOME/usr/pkg/g-wrap
70 tla register-archive guile-gnome-devel@gnu.org--2004 http://people.debian.org/~rotty/arch/guile-gnome-devel@gnu.org/2004/ || true
72 tla guile-gnome-devel@gnu.org--2004/dists--dev guile-gnome
74 tla build-config -r configs/gnu.org/dev
77 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
81 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$GUILE_LOAD_PATH
82 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$LD_LIBRARY_PATH
83 export PKG_CONFIG_PATH=$HOME/usr/pkg/g-wrap/lib/pkgconfig:$PKG_CONFIG_PATH
85 ../src/configure --prefix=$HOME/usr/pkg/guile-gnome
87 G_WRAP_MODULE_DIR=$HOME/usr/pkg/g-wrap/share/guile/site make install
89 (cd $HOME/usr/pkg/guile-gnome/share/guile/gnome && mv gtk/g[dt]k.scm gw)
91 export GUILE_LOAD_PATH=$HOME/usr/pkg/guile-gnome/share/guile:$GUILE_LOAD_PATH
92 export LD_LIBRARY_PATH=$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
93 guile -s ../src/gtk/examples/hello.scm
100 (debug-enable 'backtrace)
102 (define-module (scm output-gnome))
103 (define this-module (current-module))
111 (gnome gtk gdk-event)
112 (gnome gw libgnomecanvas))
115 ;;; Lily output interface --- fix silly names and docme
118 The output interface has functions for
119 * formatting stencils, and
135 The Bare minimum interface for \score { \notes c } } should
138 INTERFACE-output-expression
143 and should intercept:
146 (define (dummy . foo) #f)
148 ;; minimal intercept list:
149 (define output-interface-intercept
165 (map (lambda (x) (module-define! this-module x dummy))
166 output-interface-intercept)
168 (define-public (gnome-output-expression expr port)
169 (display (dispatch expr) port))
171 (define (dispatch expr)
173 (let ((keyword (car expr)))
175 ((eq? keyword 'some-func) "")
176 ;;((eq? keyword 'placebox) (dispatch (cadddr expr)))
178 (if (module-defined? this-module keyword)
179 (apply (eval keyword this-module) (cdr expr))
182 (string-append "undefined: " (symbol->string keyword) "\n"))
187 (define main-window #f)
188 (define main-canvas #f)
189 (define canvas-root #f)
191 (define system-origin '(0 . 0))
194 (define item-locations (make-hash-table 31))
197 (define canvas-width 400)
198 (define canvas-height
199 (inexact->exact (round (* 1.42 canvas-width))))
201 (define font-paper #f)
203 ;;(define pixels-per-unit 1.0)
204 (define pixels-per-unit 2.0)
206 ;; TODO: use canvas scaling, use output-scale for paper/canvas dimensions?
207 ;;(define output-scale (* 2 2.83464566929134))
208 ;;(define output-scale 2.83464566929134)
209 (define OUTPUT-SCALE 2.83464566929134)
210 (define output-scale (* OUTPUT-SCALE pixels-per-unit))
211 ;;(define output-scale 1)
214 (define (stderr string . rest)
215 (apply format (cons (current-error-port) (cons string rest)))
216 (force-output (current-error-port)))
220 ((< i #x80) (make-string 1 (integer->char i)))
221 ((< i #x800) (list->string
223 (list (+ #xc0 (quotient i #x40))
224 (+ #x80 (modulo i #x40))))))
226 (let ((x (quotient i #x1000))
227 (y (modulo i #x1000)))
231 (+ #x80 (quotient y #x40))
232 (+ #x80 (modulo y #x40)))))))
235 (define (custom-utf8 i)
238 (utf8 (+ #xee00 i))))
241 (define (get-x-editor)
243 (set! x-editor (getenv "XEDITOR")))
249 (set! ifs (getenv "IFS")))
254 (define (spawn-editor location)
255 (let* ((line (car location))
256 (column (cadr location))
257 (file-name (caddr location))
258 (template (substring (get-x-editor) 0))
260 ;; Adhere to %l %c %f?
262 (regexp-substitute/global
263 #f "%l" (regexp-substitute/global
265 (regexp-substitute/global
266 #f "%f" template 'pre file-name 'post)
267 'pre (number->string column)
269 'pre (number->string line) 'post)))
271 (stderr "spawning: ~s\n" command)
272 (if (= (primitive-fork) 0)
273 (let ((command-list (string-split command #\ )));; (get-ifs))))
274 (apply execlp command-list)
277 (define location-callback spawn-editor)
279 (define (item-event item event . data)
280 (case (gdk-event:type event)
281 ((enter-notify) (gobject-set-property item 'fill-color "white"))
282 ((leave-notify) (gobject-set-property item 'fill-color "black"))
284 (let ((location (hashq-ref item-locations item #f)))
286 (location-callback location)
287 (stderr "no location\n"))))
288 ((2button-press) (gobject-set-property item 'fill-color "red")))
291 (define (key-press-event item event . data)
292 (let ((keyval (gdk-event-key:keyval event))
293 (mods (gdk-event-key:modifiers event)))
294 (cond ((and (or (eq? keyval gdk:q)
296 (equal? mods '(control-mask modifier-mask)))
298 ((and #t ;;(null? mods)
299 (eq? keyval gdk:plus))
300 (set! pixels-per-unit (* pixels-per-unit 2))
301 (set-pixels-per-unit main-canvas pixels-per-unit))
302 ((and #t ;; (null? mods)
303 (eq? keyval gdk:minus))
304 (set! pixels-per-unit (/ pixels-per-unit 2))
305 (set-pixels-per-unit main-canvas pixels-per-unit)))
308 (define (char font i)
309 (text font (utf8 i)))
311 (define (placebox x y expr)
316 (* output-scale (+ (car system-origin) x))
317 (* output-scale (- (car system-origin) y)))
318 (affine-relative item output-scale 0 0 output-scale 0 0)
320 (gtype-instance-signal-connect item 'event item-event)
322 (hashq-set! item-locations item location))
326 (define (round-filled-box breapth width depth height blot-diameter)
327 ;; FIXME: no rounded corners on rectangle
328 (make <gnome-canvas-rect>
330 #:x1 (- breapth) #:y1 (- depth) #:x2 width #:y2 height
331 #:fill-color "black" #:width-units blot-diameter))
333 (define (fontify font expr)
339 (define (header . rest)
340 (let* ((window (make <gtk-window> #:type 'toplevel))
341 (button (make <gtk-button> #:label "Exit"))
342 (canvas (make <gnome-canvas>))
343 (vbox (make <gtk-vbox> #:homogeneous #f))
344 (scrolled (make <gtk-scrolled-window>)))
348 (add scrolled canvas)
350 (set-size-request button canvas-width 20)
352 (set-child-packing vbox button #f #f 0 'end)
354 (gtype-instance-signal-connect button 'clicked
355 (lambda (b) (gtk-main-quit)))
358 (set-size-request canvas canvas-width canvas-height)
359 (set-scroll-region canvas 0 0 2000 4000)
361 (gtype-instance-signal-connect window 'key-press-event key-press-event)
363 (set-pixels-per-unit canvas pixels-per-unit)
365 (set! canvas-root (root canvas))
366 (set! main-canvas canvas)
367 (set! main-window window)))
369 (define (pango-font-name font)
371 ((equal? (ly:font-name font) "GNU-LilyPond-feta-20")
372 "lilypond-feta, regular 32")
374 (ly:font-filename font))))
376 (define (pango-font-size font)
377 (let* ((designsize (ly:font-design-size font))
378 (magnification (* (ly:font-magnification font)))
379 ;;(ops (ly:paper-lookup paper 'outputscale))
380 ;;(ops (* pixels-per-unit OUTPUT-SCALE))
381 ;;(ops (* pixels-per-unit pixels-per-unit))
382 (ops (* (/ 12 20) (* pixels-per-unit pixels-per-unit)))
383 (scaling (* ops magnification designsize)))
386 (define (text font string)
387 (stderr "font-name: ~S\n" (ly:font-name font))
388 ;; TODO s/filename/file-name/
389 (stderr "font-filename: ~S\n" (ly:font-filename font))
390 (make <gnome-canvas-text>
393 ;; #:font "new century schoolbook, i bold 20"
394 #:font (pango-font-name font)
396 #:size-points (pango-font-size font)
397 ;;#:size (pango-font-size font)
402 (define (filledbox a b c d)
403 (round-filled-box a b c d 0.001))
405 ;; WTF is this in every backend?
406 (define (horizontal-line x1 x2 thickness)
407 ;;(let ((thickness 2))
408 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
410 (define (start-system origin . rest)
411 (set! system-origin origin))
413 ;; origin -- bad name
414 (define (define-origin file line col)
415 ;; ughr, why is this not passed as [part of] stencil object
416 (set! location (if (procedure? point-and-click)
417 ;; duh, only silly string append
418 ;; (point-and-click line col file)
423 ;;(define (define-fonts paper . rest)
424 ;;(define (define-fonts foebar paper)
426 ;; (set! font-paper paper))