Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar *album*)
- (defun quotient (x y)
- (/ (- x (mod x y)) y))
- (defclass time-spec ()
- ((min :initform 0)
- (sec :initform 0)))
- (defmethod t-min ((time-spec time-spec))
- (slot-value time-spec 'min))
- (defmethod t-sec ((time-spec time-spec))
- (slot-value time-spec 'sec))
- (defmethod set-min ((time-spec time-spec) min)
- (if (and (typep min 'integer)
- (>= min 0))
- (setf (slot-value time-spec 'min) min)
- (error "Value must be an integer, greater than 0"))
- time-spec)
- (defmethod set-sec ((time-spec time-spec) sec)
- (if (and (typep sec 'integer)
- (>= sec 0))
- (setf (slot-value time-spec 'sec) sec)
- (error "Value must be an integer, greater than 0"))
- time-spec)
- (defmethod time-in-seconds ((time-spec time-spec))
- (+ (* (t-min time-spec) 60) (t-sec time-spec)))
- (defmethod set-time-in-seconds ((time-spec time-spec) time-in-sec)
- (let* ((sec (mod time-in-sec 60))
- (min (quotient time-in-sec 60)))
- (set-min time-spec min)
- (set-sec time-spec sec)
- time-spec))
- (defun make-time (min sec)
- (let ((time-instance (make-instance 'time-spec)))
- (set-min time-instance min)
- (set-sec time-instance sec)
- time-instance))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defclass track ()
- ((name :initform nil)
- (len :initform (make-time 0 0))))
- (defmethod name ((track track))
- (slot-value track 'name))
- (defmethod len ((track track))
- (slot-value track 'len))
- (defmethod set-name ((track track) name)
- (if (typep name 'string)
- (setf (slot-value track 'name) name)
- (error "Name of the track must be a string"))
- track)
- (defmethod set-len ((track track) time-instance)
- (setf (slot-value track 'len) time-instance)
- track)
- (defmethod print-track ((track track))
- (format t "~A~1,40T~2D:~2D~%" (name track) (t-min (len track)) (t-sec (len track)))
- track)
- (defun make-track (name time)
- (let ((track-instance (make-instance 'track)))
- (set-name track-instance name)
- (set-len track-instance time)
- track-instance))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defclass album ()
- ((artist :initform nil)
- (title :initform nil)
- (tracks :initform nil)
- (year-of-release :initform 0)))
- (defmethod artist ((album album))
- (slot-value album 'artist))
- (defmethod title ((album album))
- (slot-value album 'title))
- (defmethod tracks ((album album))
- (slot-value album 'tracks))
- (defmethod year-of-release ((album album))
- (slot-value album 'year-of-release))
- (defmethod set-artist ((album album) artist)
- (if (typep artist 'string)
- (setf (slot-value album 'artist) artist)
- (error "Name of the artist must be a string"))
- album)
- (defmethod set-title ((album album) title)
- (if (typep title 'string)
- (setf (slot-value album 'title) title)
- (error "Name of the album must be a string"))
- album)
- (defmethod set-tracks ((album album) tracks)
- (setf (slot-value album 'tracks) tracks)
- album)
- (defmethod set-year-of-release ((album album) year)
- (if (typep year 'integer)
- (setf (slot-value album 'year-of-release) year)
- (error "Year must be an integer"))
- album)
- (defmethod track-count ((album album))
- (length (slot-value album 'tracks)))
- (defmethod album-length ((album album))
- (let* ((temp-sec (apply #'+ (mapcar (lambda (x) (t-sec (len x))) (slot-value album 'tracks))))
- (sec (mod temp-sec 60))
- (min (+ (apply #'+ (mapcar (lambda (x) (t-min (len x))) (slot-value album 'tracks)))
- (quotient temp-sec 60))))
- (make-time min sec)))
- (defun make-album (artist title tracks year-of-release)
- (let ((album (make-instance 'album)))
- (set-artist album artist)
- (set-title album title)
- (set-tracks album tracks)
- (set-year-of-release album year-of-release)
- album))
- (defmethod print-headlines ((album album))
- (format t "Album ~D by ~D, released ~D~%~%"
- (title album)
- (artist album)
- (year-of-release album)))
- (defmethod print-tracks ((album album))
- (dotimes (x (track-count album))
- (format t "~D. " (+ x 1))
- (print-track (nth x (tracks album)))))
- (defmethod print-total-length ((album album))
- (format t "Total length: ~D:~D"
- (t-min (album-length album))
- (t-sec (album-length album))))
- (defmethod print-album ((album album))
- (print-headlines album)
- (print-tracks album)
- (print-total-length album))
- (setf *album* (make-album "Miles Davis"
- "Bitches Brew"
- (list (make-track "Pharaoh's Dance" (make-time 20 05)) (make-track "Bitches Brew" (make-time 26 58))
- (make-track "Spanish Key" (make-time 17 32))
- (make-track "John McLaughlin" (make-time 4 22))
- (make-track "Miles Runs the Voodoo Down" (make-time 14 01))
- (make-track "Sanctuary" (make-time 10 56))
- (make-track "Feio" (make-time 11 49)))
- 1969))
Add Comment
Please, Sign In to add comment