view implementations/gsharp/methods.lisp @ 169:4a0e15e2829a

identifier becomes composition-identifier. Add constituent-identifier and get-constituents darcs-hash:20080103154317-40ec0-8398433cd150794de77cc9206296c82902df930b.gz
author d.lewis <d.lewis@gold.ac.uk>
date Thu, 03 Jan 2008 15:43:17 +0000
parents f1d0ea63581c
children e5de0895d843
line wrap: on
line source
(in-package "AMUSE-GSHARP")

(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 may want another file
(defun gsh-id (pathname)
  "Creates an identifier for gsh files, based on a pathname"
  (make-instance 'gsharp-gsh-identifier :path pathname))

(defun mxml-id (pathname)
  "Creates an identifier for MusicXML files, based on a pathname"
  (make-instance 'gsharp-mxml-identifier :path pathname))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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))))

(defmethod get-applicable-key-signatures (anchored-period (composition gsharp-composition))
  (let ((keysigs))
    (sequence::dosequence (event composition (reverse keysigs))
      (cond
        ((overlaps event anchored-period)
         (unless (member (gsharp::keysig event) keysigs)
           (push (gsharp::keysig event) keysigs)))
        ((not (before event anchored-period))
         (return-from get-applicable-key-signatures (reverse keysigs)))))))

(defmethod crotchet ((object gsharp-object))
  (make-standard-period 1))