annotate base/constructors.lisp @ 202:3e7b33ae3a0d

Gsharp preview 'fixes' committer: David Lewis <d.lewis@gold.ac.uk>
author David Lewis <david@localhost.localdomain>
date Wed, 08 Sep 2010 13:06:57 +0100
parents 54d79a2c82d2
children 51389b0db7fe
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)
j@192 64 (make-instance 'standard-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))
d@174 112
d@174 113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d@174 114 ;;
d@174 115 ;; Experimental:
d@174 116 ;;
d@174 117
d@174 118 (defun make-standard-clef-period (type line onset duration &key octave-shift)
d@174 119 "Constructor for standard-clef-periods"
d@174 120 (make-instance 'standard-clef-period
d@174 121 :type type
d@174 122 :line line
d@174 123 :octave-shift octave-shift
d@174 124 :time onset
d@174 125 :interval duration))
d@174 126
d@174 127 (defun make-standard-treble-clef-period (onset duration)
d@174 128 "Convenience function for making treble clefs"
d@174 129 (make-instance 'standard-clef-period
d@174 130 :type :G
d@174 131 :line 2
d@174 132 :octave-shift nil
d@174 133 :time onset
d@174 134 :interval duration))
d@174 135
d@174 136 (defun make-standard-bass-clef-period (onset duration)
d@174 137 "Convenience function for making bass clefs"
d@174 138 (make-instance 'standard-clef-period
d@174 139 :type :F
d@174 140 :line 4
d@174 141 :octave-shift nil
d@174 142 :time onset
d@174 143 :interval duration))
d@174 144
d@174 145 (defun make-standard-alto-clef-period (onset duration)
d@174 146 "Convenience function for making alto clefs"
d@174 147 (make-instance 'standard-clef-period
d@174 148 :type :C
d@174 149 :line 3
d@174 150 :octave-shift nil
d@174 151 :time onset
j@192 152 :interval duration))