;;
;;; c:\\program files\\acl62\\music48.cl
;;;
(load "c:\\program files\\acl62\\music47.cl")

(defun get-4-kinds-of-note-series ()
  (let* ((l1 (make-O))
      (l2 (make-R l1))
      (l3 (make-I l1))
      (l4 (make-IR l1)))
    (list `(O ,l1) `(R ,l2) `(I ,l3) `(IR ,l4))))

(defun get-note-series (n)
  (let* ((l (get-4-kinds-of-note-series))
      (l1 (list (first l))))
   (do ((nn (1- n) (1- nn))
      (w))
      ((<= nn 0) (append l1 (reverse w)))
     (let ((kind (nth (random 4) '(O R I IR))))
      (push (assoc kind l) w)))))

(defun get-and-squash-note-series (n)
  (let ((l (get-note-series n)))
   (list (mapcar #'first l) (mapcar #'second l))))

(defun get-and-squash-note-series-2 (n)
  (let ((l (get-note-series n)))
   (list (mapcar #'first l) (squash (mapcar #'second l)))))

(defun get-2-part-from-list (lst)
  (do ((l lst (cddr l))
     (w))
     ((null l) (reverse w))
   (push (list (first l) (second l)) w)))

(defun get-3-part-from-list (lst)
  (do ((l lst (cdddr l))
     (w))
     ((null l) (reverse w))
   (push (list (first l) (second l) (third l)) w)))

(defun get-4-part-from-list (lst)
  (do ((l lst (cddddr l))
     (w))
     ((null l) (reverse w))
    (push (list (first l) (second l) (third l) (fourth l)) w)))

(defun get-6-part-from-list (lst)
  (do ((l lst (cddr (cddddr l)))
     (w))
     ((null l) (reverse w))
   (push (list (first l) (second l) (third l) (fourth l) (fifth l) (sixth l)) w)))

(defun get-part-from-list-at-random (lst)
  (let ((n (random 4)))
   (case n
    (0 (get-2-part-from-list lst))
    (1 (get-3-part-from-list lst))
    (2 (get-4-part-from-list lst))
    (3 lst))))

(defun auto-comp-twelve (n)
  (let* ((l1 (get-note-series n))
      (l2 (mapcar #'first l1))
      (l3 (mapcar #'second l1)))
    (do ((ll1 l2 (cdr ll1))
       (ll2 l3 (cdr ll2))
       (w))
      ((null ll1) (reverse w))
     (let ((l4 (car ll1))
        (l5 (get-part-from-list-at-random (car ll2))))
       (format t "~% ~a : ~a." l4 l5)
       (push (list l4 l5) w)))))