annotate base/constructors.lisp @ 330:2fbff655ba47 tip

Removed cpitch-adj and cents SQL columns
author Jeremy Gow <jeremy.gow@gmail.com>
date Mon, 21 Jan 2013 11:08:11 +0000
parents 51389b0db7fe
children
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
io901tp@322 61 (defun make-diatonic-pitch-interval (interval accidentals)
io901tp@322 62 "Returns a diatonic pitch interval given a number for the interval which corresponds to a major/perfect diatonic interval (unison=1,second=2,third=3, ...), if accidentals=0. If accidental>0 (<0), the interval is modified by |accidentals| sharps (flats). The sign of the given interval number determines whether the interval is raising or falling"
io901tp@322 63 (let*
io901tp@322 64 ((direction (signum interval)) ; -1:falling interval, +1:raising interval , 0: undefined interval
io901tp@322 65 (octave (floor (/ (abs interval) 8))) ; determines the ocatve of the interval
io901tp@322 66 (ref-pitch (make-diatonic-pitch #\C 0 0)) ; use reference pitch for the calculation later
io901tp@322 67 (pitch-name ; calculate pitch from interval according to reference pitch
io901tp@322 68 (elt "CDEFGAB" (mod (1- (abs interval)) 7)))
io901tp@322 69 (diatonic-interval (pitch- (make-diatonic-pitch pitch-name accidentals octave) ref-pitch))) ; calculate interval
io901tp@322 70 (cond ((> direction 0) diatonic-interval) ; raising interval
io901tp@322 71 ((< direction 0) (pitch- (make-instance 'amuse:diatonic-pitch-interval :span '(0 0)) diatonic-interval)) ; falling interval
io901tp@322 72 ((= direction 0) (error 'invalid-argument :function 'make-diatonic-pitch-interval
io901tp@322 73 :argument "inverval = 0" ))))) ; the constructor is not defined if interval = 0
io901tp@322 74
m@24 75 ;; Events
m@24 76
m@24 77 (defun make-chromatic-pitched-event (pitch-number onset duration)
j@282 78 (make-instance 'standard-chromatic-pitched-event
m@24 79 :number pitch-number
m@24 80 :time onset
m@24 81 :interval duration))
m@24 82
d@136 83 (defun make-standard-time-signature (numerator denominator)
d@136 84 (make-instance 'standard-time-signature
d@136 85 :numerator numerator
d@136 86 :denominator denominator))
d@136 87
d@136 88 (defun make-standard-time-signature-period (numerator denominator onset duration)
d@136 89 (make-instance 'standard-time-signature-period
m@24 90 :numerator numerator
m@24 91 :denominator denominator
m@24 92 :time onset
m@24 93 :interval duration))
m@24 94
d@136 95 (defun make-standard-key-signature (sharp-count)
d@136 96 (make-instance 'standard-key-signature
d@136 97 :sharp-count sharp-count))
d@136 98
d@136 99 (defun make-standard-key-signature-period (sharp-count onset duration)
d@136 100 (make-instance 'standard-key-signature-period
m@24 101 :sharp-count sharp-count
m@24 102 :time onset
m@24 103 :interval duration))
m@24 104
d@136 105 (defun make-midi-key-signature (sharp-count mode)
m@40 106 (make-instance 'midi-key-signature
m@40 107 :sharp-count sharp-count
d@136 108 :mode mode))
d@136 109
d@136 110 (defun make-midi-key-signature-period (sharp-count mode onset duration)
d@136 111 (make-instance 'midi-key-signature-period
d@136 112 :sharp-count sharp-count
m@40 113 :mode mode
m@40 114 :time onset
m@40 115 :interval duration))
m@40 116
d@136 117 (defun make-standard-tempo (bpm)
d@136 118 (make-instance 'standard-tempo
d@137 119 :bpm bpm))
d@136 120
d@136 121 (defun make-standard-tempo-period (bpm onset duration)
d@136 122 (make-instance 'standard-tempo-period
d@136 123 :bpm bpm
d@136 124 :time onset
d@136 125 :interval duration))
d@174 126
d@174 127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d@174 128 ;;
d@174 129 ;; Experimental:
d@174 130 ;;
d@174 131
d@174 132 (defun make-standard-clef-period (type line onset duration &key octave-shift)
d@174 133 "Constructor for standard-clef-periods"
d@174 134 (make-instance 'standard-clef-period
d@174 135 :type type
d@174 136 :line line
d@174 137 :octave-shift octave-shift
d@174 138 :time onset
d@174 139 :interval duration))
d@174 140
d@174 141 (defun make-standard-treble-clef-period (onset duration)
d@174 142 "Convenience function for making treble clefs"
d@174 143 (make-instance 'standard-clef-period
d@174 144 :type :G
d@174 145 :line 2
d@174 146 :octave-shift nil
d@174 147 :time onset
d@174 148 :interval duration))
d@174 149
d@174 150 (defun make-standard-bass-clef-period (onset duration)
d@174 151 "Convenience function for making bass clefs"
d@174 152 (make-instance 'standard-clef-period
d@174 153 :type :F
d@174 154 :line 4
d@174 155 :octave-shift nil
d@174 156 :time onset
d@174 157 :interval duration))
d@174 158
d@174 159 (defun make-standard-alto-clef-period (onset duration)
d@174 160 "Convenience function for making alto clefs"
d@174 161 (make-instance 'standard-clef-period
d@174 162 :type :C
d@174 163 :line 3
d@174 164 :octave-shift nil
d@174 165 :time onset
j@282 166 :interval duration))