changeset 201:4e0a5c7026ca

Midi importing functionality committer: David Lewis <d.lewis@gold.ac.uk>
author David Lewis <david@localhost.localdomain>
date Wed, 08 Sep 2010 13:06:36 +0100
parents 305bf70fc017
children 3e7b33ae3a0d
files implementations/midi/classes.lisp implementations/midi/midifile-import.lisp
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/implementations/midi/classes.lisp	Wed Sep 08 13:06:36 2010 +0100
+++ b/implementations/midi/classes.lisp	Wed Sep 08 13:06:36 2010 +0100
@@ -3,6 +3,11 @@
 (defclass midi-object (amuse-object) ()
   (:documentation "MIDI base class"))
 
+;; rhythms not as notated
+(defclass unquantized-composition () ())
+;; onsets as notated, but durations free
+(defclass partially-quantized-composition (unquantized-composition) ())
+
 (defclass midi-composition (standard-composition midi-object)
   ((time-signatures :initarg :time-signatures
 		    :initform 'nil
--- a/implementations/midi/midifile-import.lisp	Wed Sep 08 13:06:36 2010 +0100
+++ b/implementations/midi/midifile-import.lisp	Wed Sep 08 13:06:36 2010 +0100
@@ -1,5 +1,7 @@
 (cl:in-package #:amuse-midi) 
 
+(defparameter *default-tempo* 120)
+
 (defclass midifile-identifier (composition-identifier midi-object)
   ((pathname :initarg :path
 	     :reader midifile-identifier-pathname
@@ -24,6 +26,10 @@
 	(division (midi:midifile-division midifile))
 	(notes) (time-sigs) (key-sigs) (tempi) (misses 0)
 	(track-no -1) (last-time 0))
+    (when *default-tempo*
+      (push (make-instance 'standard-tempo-period 
+			   :time 0
+			   :bpm *default-tempo*) tempi))
     (dolist (track tracks)
       (incf track-no)
       (setf track (sort (copy-seq track)
@@ -101,10 +107,18 @@
 		   key-sigs))
 	    ((typep event 'midi:tempo-message)
 	     (when tempi
-	       (setf (duration (car tempi))
-		     (- (/ (midi:message-time event)
-			   division)
-			(timepoint (car tempi)))))
+	       (if (= (midi:message-time event) 0)
+		   ;; to allow for default tempo kludge. Nightingale
+		   ;; seems to happily export midi with no initial
+		   ;; tempo, but tempo changes later. Making this
+		   ;; uncertainty last beyond import could prove
+		   ;; confusing (though is probably the `right'
+		   ;; answer)
+		   (setf tempi nil)
+		   (setf (duration (car tempi))
+			 (- (/ (midi:message-time event)
+			       division)
+			    (timepoint (car tempi))))))
 	     (push (make-instance 'standard-tempo-period
 				  :time (/ (midi:message-time event)
 					   division)