فهرست منبع

cleaning up and refactoring code

Mark VandenBrink 12 سال پیش
والد
کامیت
4f314515db
9فایلهای تغییر یافته به همراه44 افزوده شده و 36 حذف شده
  1. 1 2
      README.md
  2. 0 5
      audio-streams.lisp
  3. 1 3
      iso-639-2.lisp
  4. 1 1
      logging.lisp
  5. 9 15
      mp4-atom.lisp
  6. 0 6
      mpeg.lisp
  7. 2 2
      packages.lisp
  8. 1 1
      taglib.asd
  9. 29 1
      utils.lisp

+ 1 - 2
README.md

@@ -11,8 +11,7 @@ A pure Lisp implementation for reading MPEG-4 audio and MPEG-3 audio tags and au
 All avalailable via quicklisp
 
 * log5
-* alexandria
-* cl-fad
+* cl-fad (for taglib-tests.lisp only)
 
 # References
 

+ 0 - 5
audio-streams.lisp

@@ -2,11 +2,6 @@
 ;;; Copyright (c) 2013, Mark VandenBrink. All rights reserved.
 
 (in-package #:audio-streams)
-(eval-when (:compile-toplevel :load-toplevel :execute)
-  (defconstant +optimize-fastest+ '(optimize (speed 3) (safety 0) (debug 0)))
-  (defmacro fastest (&body body)
-    `(locally (declare ,+optimize-fastest+)
-       ,@body)))
 
 (log5:defcategory cat-log-stream)
 (defmacro log-stream (&rest log-stuff) `(log5:log-for (cat-log-stream) ,@log-stuff))

+ 1 - 3
iso-639-2.lisp

@@ -494,7 +494,5 @@
 
 (defun get-iso-639-2-language (l)
   "Convert an ISO-639-2 language tag into a readable language."
-  (let* ((lang (getf *langs* (alexandria:make-keyword (string-upcase l)))))
+  (let* ((lang (getf *langs* (make-keyword (string-upcase l)))))
     (if lang lang "Bad ISO-639-2 language")))
-
-

+ 1 - 1
logging.lisp

@@ -19,7 +19,7 @@
                                      id3-frame::cat-log-id3-frame))
 
 (defmacro with-logging ((&optional file &key (categories *logging-categories*)) &body body)
-  (alexandria:with-gensyms (output-stream)
+  (with-gensyms (output-stream)
     `(let (,output-stream)
        (unwind-protect
             (setf ,output-stream (if ,file

+ 9 - 15
mp4-atom.lisp

@@ -333,11 +333,6 @@ Loop through this container and construct constituent atoms"
    (avg-bit-rate :accessor avg-bit-rate)) ; 4 bytes
   (:documentation "XXX-partial definition for Elementary Stream DescriptorS"))
 
-(defmacro while (test &body body)
-  `(do ()
-       ((not ,test))
-     ,@body))
-
 ;;; 3 bytes extended descriptor type tag string = 3 * 8-bit hex value
 ;;; types are Start = 0x80 ; End = 0xFE
 ;;; then, one byte of length
@@ -580,11 +575,10 @@ call traverse atom (unless length of path == 1, in which case, we've found our m
 
 (defmethod tag-get-value (atoms node)
   "Helper function to extract text from ILST atom's data atom"
-  (let ((atom (traverse atoms
-                        (list +mp4-atom-moov+ +mp4-atom-udta+ +mp4-atom-meta+ +mp4-atom-ilst+ node +itunes-ilst-data+))))
-    (if atom
-        (atom-value atom)
-        nil)))
+  (aif (traverse atoms
+                 (list +mp4-atom-moov+ +mp4-atom-udta+ +mp4-atom-meta+ +mp4-atom-ilst+ node +itunes-ilst-data+))
+       (atom-value it)
+       nil))
 
 (defun mp4-show-raw-tag-atoms (mp4-file-stream)
   (map-mp4-atom (mp4-atom::traverse (mp4-atoms mp4-file-stream)
@@ -622,12 +616,12 @@ return trak.mdia.mdhd and trak.mdia.minf.stbl.stsd"
   nil)
 
 (defclass audio-info ()
-  ((seconds         :accessor seconds :initform nil)
-   (channels        :accessor channels :initform nil)
+  ((seconds         :accessor seconds         :initform nil)
+   (channels        :accessor channels        :initform nil)
    (bits-per-sample :accessor bits-per-sample :initform nil)
-   (sample-rate     :accessor sample-rate :initform nil)
-   (max-bit-rate    :accessor max-bit-rate :initform nil)
-   (avg-bit-rate    :accessor avg-bit-rate :initform nil)))
+   (sample-rate     :accessor sample-rate     :initform nil)
+   (max-bit-rate    :accessor max-bit-rate    :initform nil)
+   (avg-bit-rate    :accessor avg-bit-rate    :initform nil)))
 
 (defmethod vpprint ((me audio-info) stream)
   (with-slots (seconds channels bits-per-sample sample-rate max-bit-rate avg-bit-rate) me

+ 0 - 6
mpeg.lisp

@@ -4,12 +4,6 @@
 ;;; Parsing MPEG audio frames.  See http://www.datavoyage.com/mpgscript/mpeghdr.htm for format of a frame.
 (in-package #:mpeg)
 
-(eval-when (:compile-toplevel :load-toplevel :execute)
-  (defconstant +optimize-fastest+ '(optimize (speed 3) (safety 0) (debug 0)))
-  (defmacro fastest (&body body)
-    `(locally (declare ,+optimize-fastest+)
-       ,@body)))
-
 (log5:defcategory cat-log-mpeg-frame)
 (defmacro log-mpeg-frame (&rest log-stuff) `(log5:log-for (cat-log-mpeg-frame) ,@log-stuff))
 

+ 2 - 2
packages.lisp

@@ -4,12 +4,12 @@
 
 (defpackage #:utils
   (:export #:warn-user *break-on-warn-user* #:printable-array #:upto-null #:has-extension #:redirect
-           #:get-bitfield)
+           #:it #:fastest #:get-bitfield #:while #:aif #:awhen #:with-gensyms #:make-keyword #:dump-data)
   (:use #:common-lisp))
 
 (defpackage #:iso-639-2
   (:export #:get-iso-639-2-language)
-  (:use #:common-lisp))
+  (:use #:common-lisp :utils))
 
 (defpackage #:audio-streams
   (:export #:octets #:make-octets *get-audio-info* #:audio-stream-condition

+ 1 - 1
taglib.asd

@@ -9,7 +9,7 @@
   :description "Pure Lisp implementation to read (and write, perhaps, one day) tags"
   :author "Mark VandenBrink"
   :license "Public Domain"
-  :depends-on (#:log5 #:alexandria)
+  :depends-on (#:log5)
   :components ((:file "packages")
                (:file "utils"         :depends-on ("packages"))
                (:file "audio-streams" :depends-on ("packages" "utils"))

+ 29 - 1
utils.lisp

@@ -56,5 +56,33 @@ Example: (get-bitmask 31 11) -->> #xffe00000"
 
 (defmacro get-bitfield (int start width)
   "Extract WIDTH bits from INT starting at START
-Example: (get-bitfield #xFFFBB240 31 11) -->> #x7ff"
+Example: (get-bitfield #xFFFBB240 31 11) -->> #x7ff.
+The above will expand to (ash (logand #xFFFBB240 #xFFE00000) -21) at COMPILE time."
   `(ash (logand ,int ,(utils::get-bitmask start width)) ,(- ( - start width -1))))
+
+;;;;;;;;;;;;;;;;;;;; convenience macros ;;;;;;;;;;;;;;;;;;;;
+(defmacro with-gensyms (syms &body body)
+  `(let ,(mapcar #'(lambda (s)
+                     `(,s (gensym)))
+                 syms)
+     ,@body))
+
+(defun make-keyword (name)
+  (intern (string name) :keyword))
+
+(defmacro while (test &body body)
+  `(do ()
+       ((not ,test))
+     ,@body))
+
+(defmacro aif (test-form then-form &optional else-form)
+  `(let ((it ,test-form))
+     (if it ,then-form ,else-form)))
+
+(defmacro awhen (test-form &body body)
+  `(aif ,test-form
+        (progn ,@body)))
+
+(defmacro fastest (&body body)
+  `(locally (declare (optimize (speed 3) (safety 0) (debug 0)))
+     ,@body))