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 ;;; status: hello-world
12 ;;; This first working version needs rotty's g-wrap--tng.
13 ;;; (janneke's guile-gnome patches now in main archive).
16 ;;; lilypond-bin -fgnome input/simple-song.ly
18 ;;; Set XEDITOR and add
19 ;;; #(ly:set-point-and-click 'line-column)
20 ;;; to your .ly to get point-and-click
23 ;;; * pango+feta font (see archives gtk-i18n-list@gnome.org and
25 ;;; - wait for/help with pango 1.6
26 ;;; - convert feta to OpenType (CFF) or TrueType (fontforge?)
27 ;;; - hack feta20: use latin1 encoding for gnome backend
28 ;;; * implement missing stencil functions
29 ;;; * implement missing commands (next, prev? page)
30 ;;; * user-interface, keybindings
32 ;;; Note: this install information is volatile
33 ;;; you'll probably want to pull all from
34 ;;; from guile-gnome-devel@gnu.org--2004 soon
36 ;;; move this into workbook?
39 ## install gnome-devel
41 ## use guile-1.6 for g-wrap/guile-gnome
45 tla register-archive a.rottmann@gmx.at--2004-main http://people.debian.org/~rotty/arch/a.rottmann@gmx.at/2004-main || true
48 tla get a.rottmann@gmx.at--2004-main/g-wrap--tng gw-pristine
51 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
54 ../configure --prefix=$HOME/usr/pkg/g-wrap
60 tla register-archive guile-gnome-devel@gnu.org--2004 http://people.debian.org/~rotty/arch/guile-gnome-devel@gnu.org/2004/ || true
62 tla guile-gnome-devel@gnu.org--2004/dists--dev guile-gnome
64 tla build-config -r configs/gnu.org/dev
67 AUTOMAKE=automake-1.8 AUTOCONF=autoconf2.50 sh autogen.sh --noconfigure
71 export GUILE_LOAD_PATH=$HOME/usr/pkg/g-wrap/share/guile/site:$GUILE_LOAD_PATH
72 export LD_LIBRARY_PATH=$HOME/usr/pkg/g-wrap/lib:$LD_LIBRARY_PATH
73 export PKG_CONFIG_PATH=$HOME/usr/pkg/g-wrap/lib/pkgconfig:$PKG_CONFIG_PATH
75 ../src/configure --prefix=$HOME/usr/pkg/guile-gnome
77 G_WRAP_MODULE_DIR=$HOME/usr/pkg/g-wrap/share/guile/site make install
79 (cd $HOME/usr/pkg/guile-gnome/share/guile/gnome && mv gtk/g[dt]k.scm gw)
81 export GUILE_LOAD_PATH=$HOME/usr/pkg/guile-gnome/share/guile:$GUILE_LOAD_PATH
82 export LD_LIBRARY_PATH=$HOME/usr/pkg/guile-gnome/lib:$LD_LIBRARY_PATH
83 guile -s ../src/gtk/examples/hello.scm
90 (debug-enable 'backtrace)
92 (define-module (scm output-gnome))
93 (define this-module (current-module))
101 (gnome gtk gdk-event)
102 (gnome gw libgnomecanvas))
105 ;;; Lily output interface --- fix silly names and docme
108 The output interface has functions for
109 * formatting stencils, and
125 The Bare minimum interface for \score { \notes c } } should
128 INTERFACE-output-expression
133 and should intercept:
136 (define (dummy . foo) #f)
138 ;; minimal intercept list:
139 (define output-interface-intercept
155 (map (lambda (x) (module-define! this-module x dummy))
156 output-interface-intercept)
158 (define-public (gnome-output-expression expr port)
159 (display (dispatch expr) port))
161 (define (dispatch expr)
163 (let ((keyword (car expr)))
165 ((eq? keyword 'some-func) "")
166 ;;((eq? keyword 'placebox) (dispatch (cadddr expr)))
168 (if (module-defined? this-module keyword)
169 (apply (eval keyword this-module) (cdr expr))
172 (string-append "undefined: " (symbol->string keyword) "\n"))
177 (define main-window #f)
178 (define main-canvas #f)
179 (define canvas-root #f)
181 (define system-origin '(0 . 0))
184 (define item-locations (make-hash-table 31))
187 (define canvas-width 400)
188 (define canvas-height
189 (inexact->exact (round (* 1.42 canvas-width))))
191 ;; TODO: use canvas scaling, use output-scale for paper/canvas dimensions?
192 (define output-scale (* 2 2.83464566929134))
193 ;;(define output-scale 2.83464566929134)
194 ;;(define output-scale 1)
197 (define (stderr string . rest)
198 (apply format (cons (current-error-port) (cons string rest)))
199 (force-output (current-error-port)))
203 (define (get-x-editor)
205 (set! x-editor (getenv "XEDITOR")))
211 (set! ifs (getenv "IFS")))
216 (define (spawn-editor location)
217 (let* ((line (car location))
218 (column (cadr location))
219 (file-name (caddr location))
220 (template (substring (get-x-editor) 0))
222 ;; Adhere to %l %c %f?
224 (regexp-substitute/global
225 #f "%l" (regexp-substitute/global
227 (regexp-substitute/global
228 #f "%f" template 'pre file-name 'post)
229 'pre (number->string column)
231 'pre (number->string line) 'post)))
233 (stderr "spawning: ~s\n" command)
234 (if (= (primitive-fork) 0)
235 (let ((command-list (string-split command #\ )));; (get-ifs))))
236 (apply execlp command-list)
239 (define location-callback spawn-editor)
241 (define (item-event item event . data)
242 (case (gdk-event:type event)
243 ((enter-notify) (gobject-set-property item 'fill-color "white"))
244 ((leave-notify) (gobject-set-property item 'fill-color "black"))
246 (let ((location (hashq-ref item-locations item #f)))
248 (location-callback location)
249 (stderr "no location\n"))))
250 ((2button-press) (gobject-set-property item 'fill-color "red")))
253 (define pixels-per-unit 1.0)
254 (define (key-press-event item event . data)
255 (let ((keyval (gdk-event-key:keyval event))
256 (mods (gdk-event-key:modifiers event)))
257 (cond ((and (or (eq? keyval gdk:q)
259 (equal? mods '(control-mask modifier-mask)))
261 ((and #t ;;(null? mods)
262 (eq? keyval gdk:plus))
263 (set! pixels-per-unit (* pixels-per-unit 2))
264 (set-pixels-per-unit main-canvas pixels-per-unit))
265 ((and #t ;; (null? mods)
266 (eq? keyval gdk:minus))
267 (set! pixels-per-unit (/ pixels-per-unit 2))
268 (set-pixels-per-unit main-canvas pixels-per-unit)))
271 (define (char font i)
272 ;;(text font (make-string 1 (integer->char i))))
275 (define (placebox x y expr)
280 (* output-scale (+ (car system-origin) x))
281 (* output-scale (- (car system-origin) y)))
282 (affine-relative item output-scale 0 0 output-scale 0 0)
284 (gtype-instance-signal-connect item 'event item-event)
286 (hashq-set! item-locations item location))
290 (define (round-filled-box breapth width depth height blot-diameter)
291 ;; FIXME: no rounded corners on rectangle
292 (make <gnome-canvas-rect>
294 #:x1 (- breapth) #:y1 (- depth) #:x2 width #:y2 height
295 #:fill-color "black" #:width-units blot-diameter))
297 (define (fontify font expr)
303 (define (header . rest)
304 (let* ((window (make <gtk-window> #:type 'toplevel))
305 (button (make <gtk-button> #:label "Exit"))
306 (canvas (make <gnome-canvas>))
307 (vbox (make <gtk-vbox> #:homogeneous #f))
308 (scrolled (make <gtk-scrolled-window>)))
312 (add scrolled canvas)
314 (set-size-request button canvas-width 20)
316 (set-child-packing vbox button #f #f 0 'end)
318 (gtype-instance-signal-connect button 'clicked
319 (lambda (b) (gtk-main-quit)))
322 (set-size-request canvas canvas-width canvas-height)
323 (set-scroll-region canvas 0 0 2000 4000)
325 (gtype-instance-signal-connect window 'key-press-event key-press-event)
328 (set! canvas-root (root canvas))
329 (set! main-canvas canvas)
330 (set! main-window window)))
332 (define (text font string)
333 (make <gnome-canvas-text>
338 #:font "new century schoolbook, i bold 20"
342 (define (filledbox a b c d)
343 (round-filled-box a b c d 0.001))
345 ;; WTF is this in every backend?
346 (define (horizontal-line x1 x2 thickness)
347 ;;(let ((thickness 2))
348 (filledbox (- x1) (- x2 x1) (* .5 thickness) (* .5 thickness)))
350 (define (start-system origin . rest)
351 (set! system-origin origin))
353 ;; origin -- bad name
354 (define (define-origin file line col)
355 ;; ughr, why is this not passed as [part of] stencil object
356 (set! location (if (procedure? point-and-click)
357 ;; duh, only silly string append
358 ;; (point-and-click line col file)