- ;;; rips.lisp
- ;;; A simple database for CD rips
- ;;; by Daniel Rhodes-Mumby (DanielRM)
- ;;;
- ;;; Shamelessly adapted from Peter Seibel's "Practical Common Lisp"
- ;;;
- ;;; September 2008
- ;;;
- ;;; Function definitions are preceded by ';;' and an explanation of their purpose.
- ;;; Inline comments are preceded by ';'
- ;;;
- ;; Define the startup function and dependencies.
- ;; Also define the the save database function for completeness.
- (defun startup ()
- (format t "~a" "Welcome to the Rips-Lisp CD rips database program.")
- ;say hello
- (defun db-load (filename)
- ;define the load database function
- (with-open-file (in filename)
- (with-standard-io-syntax
- (setf *db-rips* (read in)))))
- ;this clobbers the working database
- (defun db-save (filename)
- ;define the save database function
- (with-open-file (out filename
- :direction :output
- :if-exists :supersede)
- ;overwrite an existing file - if the user's smart they'll avoid doing this without thinking
- (with-standard-io-syntax
- (print *db-rips* out))))
- ;let the user know the contents of the database
- (defvar *db-rips* nil))
- ;define the database variable
- ;;;
- ;; Define the function for making CD records.
- (defun cd-create (artist title priority ripped-mp3 ripped-ogg)
- (list :artist artist :title title :priority priority :ripped-mp3 ripped-mp3 :ripped-ogg ripped-ogg))
- ;;;
- ;; Define the function for showing the database.
- (defun db-dump (&optional (db *db-rips*))
- (dolist (cd db)
- (format t "~{~a:~20t~a~%~}~%" cd)))
- ;I quite honestly have no idea how most of this format call works.
- ;;;
- ;; Define record manipulation functions.
- (defun cd-add (cd)
- (push cd *db-rips*))
- ;push the record on to the database variable.
- ;;;
- ;; Define a prompt reader.
- (defun prompt-read (prompt)
- (format *query-io* "~a: " prompt)
- (force-output *query-io*)
- (read-line *query-io*))
- ;;;
- ;; Prompt for the CD now.
- (defun cd-prompt ()
- (cd-create
- (prompt-read "Artist")
- (prompt-read "Album name")
- (or (parse-integer (prompt-read "Priority") :junk-allowed t) 0)
- (y-or-n-p "Ripped to MP3 (you dirty capitalist) [y/n]: ")
- (y-or-n-p "Ripped to OGG (freedom uber alles!) [y/n]: ")))
- ;;;
- ;; Continually prompt.
- (defun cd-prompter ()
- (loop (cd-add (cd-prompt))
- (if (not (y-or-n-p "Another? [y/n]: "))
- ;loop around until the user doesn't want to add another CD
- (return))))
- ;;;
- ;; Write a selector function for queries.
- (defun select (selector-function)
- (db-dump (remove-if-not selector-function *db-rips*)))
- ;;;
- ;; Define a general selection category function.
- (defun where (&key artist title priority (ripped-mp3 nil ripped-mp3-p) (ripped-ogg nil ripped-ogg-p))
- #'(lambda (cd)
- (and
- (if artist (equal (getf cd :artist) artist) t)
- (if title (equal (getf cd :title) title) t)
- (if priority (equal (getf cd :priority) priority) t)
- (if ripped-mp3-p (equal (getf cd :ripped-mp3) ripped-mp3) t)
- (if ripped-ogg-p (equal (getf cd :ripped-ogg) ripped-ogg) t))))
- ;;; Actually run the startup function.
- (startup)
