changeset 162:110e957a7e3c

Add get-composition methods for gsharp darcs-hash:20071218104432-40ec0-5fdd50a969609f1f50623d2c88a1746f391c984a.gz
author d.lewis <d.lewis@gold.ac.uk>
date Tue, 18 Dec 2007 10:44:32 +0000
parents 676283afe8fb
children 83023a2668d2
files implementations/gsharp/classes.lisp implementations/gsharp/methods.lisp
diffstat 2 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/implementations/gsharp/classes.lisp	Tue Dec 11 15:03:33 2007 +0000
+++ b/implementations/gsharp/classes.lisp	Tue Dec 18 10:44:32 2007 +0000
@@ -7,3 +7,19 @@
 (defclass gsharp-pitched-event (standard-chromatic-pitched-event)
   ((note :initarg :note :reader note)
    (slice-index :initarg :slice-index)))
+
+(defclass gsharp-identifier (identifier)
+  ((pathname :initarg :path
+             :reader %gsharp-identifier-pathname
+	     :initform 'nil))
+  (:documentation "Identifier for files that can be read in GSharp,
+  containing pathname information"))
+
+(defclass gsharp-gsh-identifier (gsharp-identifier)
+  ()
+  (:documentation "Identifier for .gsh files for gsharp"))
+
+(defclass gsharp-mxml-identifier (gsharp-identifier)
+  ()
+  (:documentation "Identifier for MusicXML files for gsharp"))
+
--- a/implementations/gsharp/methods.lisp	Tue Dec 11 15:03:33 2007 +0000
+++ b/implementations/gsharp/methods.lisp	Tue Dec 18 10:44:32 2007 +0000
@@ -3,3 +3,46 @@
 (defmethod time-signatures ((composition gsharp-composition))
   ())
 
+(defmethod get-composition ((id gsharp-gsh-identifier))
+  "Makes a gsharp buffer from .gsh file and generates a composition
+from its first segment. N.B. 1) This is not compatible with
+multi-segment files 2) No application frame is created (=> data flow
+is pretty much one way)"
+  (let ((buffer (with-open-file (s (%gsharp-identifier-pathname id))
+                  (gsharp::read-buffer-from-stream s))))
+    (gsharp::recompute-measures buffer)
+    (segment-composition (car (gsharp::segments buffer)))))
+
+(defmethod get-composition ((id gsharp-mxml-identifier))
+  "Makes a gsharp buffer from .mxml file and generates a composition
+from its first segment. N.B. 1) This is not compatible with
+multi-segment files 2) No application frame is created (=> data flow
+is pretty much one way)"
+  (let ((buffer (gsharp-mxml::parse-mxml 
+                 (gsharp-mxml::musicxml-document
+                  (%gsharp-identifier-pathname id)))))
+    (gsharp::recompute-measures buffer)
+    (segment-composition (car (gsharp::segments buffer)))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; These versions may not be useful, but create and return a gsharp
+;; application frame as well as a composition
+
+(defgeneric get-composition-with-application-frame (identifier))
+(defmethod get-composition-with-application-frame ((id gsharp-identifier))
+  (let* ((frame (clim:make-application-frame 'gsharp:gsharp))
+         (clim:*application-frame* frame)
+         (esa:*esa-instance* frame))
+    (clim:adopt-frame (clim:find-frame-manager :server-path '(:null)) frame)
+    (import-from-identifier frame id)
+    (gsharp::recompute-measures (car (esa-buffer::buffers frame)))
+    (values (segment-composition (car (gsharp::segments (car (esa-buffer::buffers frame)))))
+            frame)))
+
+(defgeneric import-from-identifier (frame id))
+(defmethod import-from-identifier (frame (id gsharp-gsh-identifier))
+  (clim:execute-frame-command frame '(gsharp::com-new-buffer))
+  (gsharp::frame-find-file frame (%gsharp-identifier-pathname id)))
+(defmethod import-from-identifier (frame (id gsharp-mxml-identifier))
+  (clim:execute-frame-command frame `(gsharp::com-import-musicxml ,(%gsharp-identifier-pathname id))))