annotate base/constructors.lisp @ 139:ebfe054eea1c

Bug fixes from name changes darcs-hash:20070918114952-f76cc-feb59725a2f67edd6242947a5c2311d0a724cc43.gz
author David Lewis <d.lewis@gold.ac.uk>
date Tue, 18 Sep 2007 12:49:52 +0100
parents ee9dd7148eab
children 9b152d515275
rev   line source
m@24 1 (cl:in-package #:amuse)
m@24 2
m@24 3 ;; Time classes
m@24 4
d@136 5 (defun make-standard-moment (time)
d@136 6 "Returns a new standard-moment, taking a number as input for
d@136 7 the time point."
d@139 8 (make-instance 'standard-moment :time time))
m@24 9
m@24 10 ;; N.B. period should never be constructed directly - it's either
m@24 11 ;; floating or anchored or some other subclass.
m@24 12
d@136 13 (defun make-standard-period (interval)
d@136 14 "Returns a new (floating) period, taking a number for the
d@134 15 duration."
d@136 16 (make-instance 'standard-period :interval interval))
m@24 17
d@33 18
d@33 19 ;; Should this take a moment and/or a period too?
d@136 20 (defun make-standard-anchored-period (onset interval)
d@134 21 "Returns a new floating-period, taking numbers for onset and
d@134 22 duration."
d@136 23 (make-instance 'standard-anchored-period
m@24 24 :time onset
m@24 25 :interval interval))
m@24 26
m@24 27 ;; Pitch classes (no, not that sort of pitch class)
m@24 28
m@24 29 (defun make-chromatic-pitch (pitch-number)
d@134 30 "Returns a new chromatic pitch, taking a number for the
d@134 31 pitch."
m@24 32 (make-instance 'chromatic-pitch :number pitch-number))
m@24 33
m@24 34 (defun make-diatonic-pitch (name accidental octave)
d@134 35 "Returns a new diatonic pitch, taking as input a character for the name,
d@134 36 a positive or negative number for the accidental (+ve for sharps,
d@134 37 -ve for flats) and another for octave. (Is this description right?)"
c@106 38 (flet ((asa-string (name accidental octave)
c@106 39 (with-output-to-string (s)
c@106 40 (write-char name s)
c@106 41 (if (zerop accidental)
c@106 42 (write-char #\n s)
c@106 43 (let ((achar (if (plusp accidental) #\s #\f)))
c@106 44 (dotimes (i (abs accidental))
c@106 45 (write-char achar s))))
c@106 46 (write octave :stream s :base 10 :radix nil :pretty nil))))
c@106 47 (let* ((name (if (numberp name) (elt "ABCDEFG" name) name))
c@106 48 (asa-string (asa-string name accidental octave))
c@106 49 (p (mips:pn-p asa-string)))
c@109 50 (make-instance 'diatonic-pitch :cp (first p) :mp (second p)))))
m@24 51
m@81 52 (defun make-mips-pitch (cp mp)
c@109 53 (make-instance 'diatonic-pitch :cp cp :mp mp))
m@81 54
c@105 55 (defun make-chromatic-pitch-interval (span)
m@113 56 (make-instance 'chromatic-pitch-interval :span span))
m@24 57
c@111 58 (defun make-mips-pitch-interval (cspan mspan)
c@111 59 (make-instance 'diatonic-pitch-interval :span (list cspan mspan)))
c@111 60
m@24 61 ;; Events
m@24 62
m@24 63 (defun make-chromatic-pitched-event (pitch-number onset duration)
m@24 64 (make-instance 'chromatic-pitched-event
m@24 65 :number pitch-number
m@24 66 :time onset
m@24 67 :interval duration))
m@24 68
d@136 69 (defun make-standard-time-signature (numerator denominator)
d@136 70 (make-instance 'standard-time-signature
d@136 71 :numerator numerator
d@136 72 :denominator denominator))
d@136 73
d@136 74 (defun make-standard-time-signature-period (numerator denominator onset duration)
d@136 75 (make-instance 'standard-time-signature-period
m@24 76 :numerator numerator
m@24 77 :denominator denominator
m@24 78 :time onset
m@24 79 :interval duration))
m@24 80
d@136 81 (defun make-standard-key-signature (sharp-count)
d@136 82 (make-instance 'standard-key-signature
d@136 83 :sharp-count sharp-count))
d@136 84
d@136 85 (defun make-standard-key-signature-period (sharp-count onset duration)
d@136 86 (make-instance 'standard-key-signature-period
m@24 87 :sharp-count sharp-count
m@24 88 :time onset
m@24 89 :interval duration))
m@24 90
d@136 91 (defun make-midi-key-signature (sharp-count mode)
m@40 92 (make-instance 'midi-key-signature
m@40 93 :sharp-count sharp-count
d@136 94 :mode mode))
d@136 95
d@136 96 (defun make-midi-key-signature-period (sharp-count mode onset duration)
d@136 97 (make-instance 'midi-key-signature-period
d@136 98 :sharp-count sharp-count
m@40 99 :mode mode
m@40 100 :time onset
m@40 101 :interval duration))
m@40 102
d@136 103 (defun make-standard-tempo (bpm)
d@136 104 (make-instance 'standard-tempo
d@137 105 :bpm bpm))
d@136 106
d@136 107 (defun make-standard-tempo-period (bpm onset duration)
d@136 108 (make-instance 'standard-tempo-period
d@136 109 :bpm bpm
d@136 110 :time onset
d@136 111 :interval duration))