annotate implementations/gsharp/methods.lisp @ 163:83023a2668d2

Add constructors for gsharp identifiers darcs-hash:20071218120203-40ec0-dc2bf7d840f4459d4277b11a70b4b9895d0eaf7d.gz
author d.lewis <d.lewis@gold.ac.uk>
date Tue, 18 Dec 2007 12:02:03 +0000
parents 110e957a7e3c
children f1d0ea63581c
rev   line source
csr21@59 1 (in-package "AMUSE-GSHARP")
csr21@59 2
csr21@59 3 (defmethod time-signatures ((composition gsharp-composition))
csr21@59 4 ())
csr21@59 5
d@162 6 (defmethod get-composition ((id gsharp-gsh-identifier))
d@162 7 "Makes a gsharp buffer from .gsh file and generates a composition
d@162 8 from its first segment. N.B. 1) This is not compatible with
d@162 9 multi-segment files 2) No application frame is created (=> data flow
d@162 10 is pretty much one way)"
d@162 11 (let ((buffer (with-open-file (s (%gsharp-identifier-pathname id))
d@162 12 (gsharp::read-buffer-from-stream s))))
d@162 13 (gsharp::recompute-measures buffer)
d@162 14 (segment-composition (car (gsharp::segments buffer)))))
d@162 15
d@162 16 (defmethod get-composition ((id gsharp-mxml-identifier))
d@162 17 "Makes a gsharp buffer from .mxml file and generates a composition
d@162 18 from its first segment. N.B. 1) This is not compatible with
d@162 19 multi-segment files 2) No application frame is created (=> data flow
d@162 20 is pretty much one way)"
d@162 21 (let ((buffer (gsharp-mxml::parse-mxml
d@162 22 (gsharp-mxml::musicxml-document
d@162 23 (%gsharp-identifier-pathname id)))))
d@162 24 (gsharp::recompute-measures buffer)
d@162 25 (segment-composition (car (gsharp::segments buffer)))))
d@162 26
d@163 27 ;; These may want another file
d@163 28 (defun gsh-id (pathname)
d@163 29 "Creates an identifier for gsh files, based on a pathname"
d@163 30 (make-instance 'gsharp-gsh-identifier :path pathname))
d@163 31
d@163 32 (defun mxml-id (pathname)
d@163 33 "Creates an identifier for MusicXML files, based on a pathname"
d@163 34 (make-instance 'gsharp-mxml-identifier :path pathname))
d@163 35
d@162 36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d@162 37 ;;
d@162 38 ;; These versions may not be useful, but create and return a gsharp
d@162 39 ;; application frame as well as a composition
d@162 40
d@162 41 (defgeneric get-composition-with-application-frame (identifier))
d@162 42 (defmethod get-composition-with-application-frame ((id gsharp-identifier))
d@162 43 (let* ((frame (clim:make-application-frame 'gsharp:gsharp))
d@162 44 (clim:*application-frame* frame)
d@162 45 (esa:*esa-instance* frame))
d@162 46 (clim:adopt-frame (clim:find-frame-manager :server-path '(:null)) frame)
d@162 47 (import-from-identifier frame id)
d@162 48 (gsharp::recompute-measures (car (esa-buffer::buffers frame)))
d@162 49 (values (segment-composition (car (gsharp::segments (car (esa-buffer::buffers frame)))))
d@162 50 frame)))
d@162 51
d@162 52 (defgeneric import-from-identifier (frame id))
d@162 53 (defmethod import-from-identifier (frame (id gsharp-gsh-identifier))
d@162 54 (clim:execute-frame-command frame '(gsharp::com-new-buffer))
d@162 55 (gsharp::frame-find-file frame (%gsharp-identifier-pathname id)))
d@162 56 (defmethod import-from-identifier (frame (id gsharp-mxml-identifier))
d@162 57 (clim:execute-frame-command frame `(gsharp::com-import-musicxml ,(%gsharp-identifier-pathname id))))