annotate base/constructors.lisp @ 108:b445959f4cc1

MIPS generic functions and methods for diatonic pitches Define and implement DIATONIC-PITCH-MP and DIATONIC-PITCH-CP for mips-pitches (soon to be diatonic-pitches). Supersedes MEREDITH-FOO darcs-hash:20070726131018-dc3a5-3421fb2c4beceae2370932768fefa1115050cfdd.gz
author c.rhodes <c.rhodes@gold.ac.uk>
date Thu, 26 Jul 2007 14:10:18 +0100
parents 8528c316fbcc
children a9a1c7aa86a9
rev   line source
m@24 1 (cl:in-package #:amuse)
m@24 2
m@24 3 ;; Time classes
m@24 4
m@24 5 (defun make-moment (time)
m@24 6 (make-instance 'moment :time time))
m@24 7
m@24 8 ;; N.B. period should never be constructed directly - it's either
m@24 9 ;; floating or anchored or some other subclass.
m@24 10
m@24 11 (defun make-floating-period (interval)
m@24 12 (make-instance 'floating-period :interval interval))
m@24 13
d@33 14
d@33 15 ;; Should this take a moment and/or a period too?
m@24 16 (defun make-anchored-period (onset interval)
m@24 17 (make-instance 'anchored-period
m@24 18 :time onset
m@24 19 :interval interval))
m@24 20
m@24 21 ;; Pitch classes (no, not that sort of pitch class)
m@24 22
m@24 23 (defun make-chromatic-pitch (pitch-number)
m@24 24 (make-instance 'chromatic-pitch :number pitch-number))
m@24 25
m@24 26 (defun make-diatonic-pitch (name accidental octave)
c@106 27 (flet ((asa-string (name accidental octave)
c@106 28 (with-output-to-string (s)
c@106 29 (write-char name s)
c@106 30 (if (zerop accidental)
c@106 31 (write-char #\n s)
c@106 32 (let ((achar (if (plusp accidental) #\s #\f)))
c@106 33 (dotimes (i (abs accidental))
c@106 34 (write-char achar s))))
c@106 35 (write octave :stream s :base 10 :radix nil :pretty nil))))
c@106 36 (let* ((name (if (numberp name) (elt "ABCDEFG" name) name))
c@106 37 (asa-string (asa-string name accidental octave))
c@106 38 (p (mips:pn-p asa-string)))
c@106 39 (make-instance 'mips-pitch :cp (first p) :mp (second p)))))
m@24 40
m@81 41 (defun make-mips-pitch (cp mp)
m@81 42 (make-instance 'mips-pitch :cp cp :mp mp))
m@81 43
c@105 44 (defun make-chromatic-pitch-interval (span)
m@24 45 (make-instance 'pitch-interval :span span))
m@24 46
m@24 47 ;; Events
m@24 48
m@24 49 (defun make-chromatic-pitched-event (pitch-number onset duration)
m@24 50 (make-instance 'chromatic-pitched-event
m@24 51 :number pitch-number
m@24 52 :time onset
m@24 53 :interval duration))
m@24 54
m@24 55 (defun make-basic-time-signature (numerator denominator onset duration)
m@24 56 (make-instance 'basic-time-signature
m@24 57 :numerator numerator
m@24 58 :denominator denominator
m@24 59 :time onset
m@24 60 :interval duration))
m@24 61
m@24 62 (defun make-basic-key-signature (sharp-count onset duration)
m@24 63 (make-instance 'basic-key-signature
m@24 64 :sharp-count sharp-count
m@24 65 :time onset
m@24 66 :interval duration))
m@24 67
m@40 68 (defun make-midi-key-signature (sharp-count mode onset duration)
m@40 69 (make-instance 'midi-key-signature
m@40 70 :sharp-count sharp-count
m@40 71 :mode mode
m@40 72 :time onset
m@40 73 :interval duration))
m@40 74
m@24 75 (defun make-tempo (bpm onset duration)
m@24 76 (make-instance 'tempo
m@24 77 :bpm bpm
m@24 78 :time onset
m@24 79 :interval duration))