;;;
;;; (load "c:\\program files\\acl62\\music64.cl")
;;;
(load "c:\\program files\\acl62\\music63.cl")

;;;
;;;(get-forth-interval-at-random '("CM7" ion))--->(si do so re la mi)
;;;(get-forth-interval-at-random '("Dm7" dor))--->(si mi la re so do fa +la)
;;;(get-forth-interval-at-random '("G7" all))--->(so fa +la +re +so +do si mi la re)
;;;
(defun connect-lists-for-phrase-by-a-pair-4th (pair)
  (let ((lst (get-forth-interval-at-random pair)))
   (remove (car (avoid-note pair)) (connect-lists-for-phrase lst))))

(defun get-a-phrase-1-aux-4th (pair)
  (cut-list-at-length (+ (random 2) 1) (connect-lists-for-phrase-by-a-pair-4th pair)))

(defun get-a-phrase-2-aux-4th (pair)
  (cut-list-at-length (+ (random 4) 1) (connect-lists-for-phrase-by-a-pair-4th pair)))

(defun get-a-phrase-3-aux-4th (pair)
  (cut-list-at-length (+ (random 6) 1) (connect-lists-for-phrase-by-a-pair-4th pair)))

(defun get-a-phrase-4-aux-4th (pair)
  (cut-list-at-length (+ (random 8) 1) (connect-lists-for-phrase-by-a-pair-4th pair)))


(defun get-a-phrase-one-aux-4th (l)
  (cond ((equal (length l) 2)
       (do ((lst l (cddr lst))
          (w))
          ((null lst) (reverse w))
        (let ((l1 (cons (list (first lst) (second lst))
                  (get-a-phrase-4-aux-4th (list (first lst) (second lst))))))
         (push l1 w))))
      ((equal (length l) 4)
       (do ((lst l (cddr lst))
          (w))
          ((null lst) (reverse w))
        (let ((l2 (cons (list (first lst) (second lst))
                  (get-a-phrase-3-aux-4th (list (first lst) (second lst))))))
         (push l2 w))))
      ((equal (length l) 6)
       (do ((lst l (cddr lst))
          (w))
          ((null lst) (reverse w))
        (let ((l3 (cons (list (first lst) (second lst))
                  (get-a-phrase-2-aux-4th (list (first lst) (second lst))))))
         (push l3 w))))))



(defun get-a-phrase-two-aux-4th (l)
  (cond ((equal (length l) 2)
       (do ((lst l (cddr lst))
          (w))
          ((null lst) (reverse w))
         (let ((l1 (cons (list (first lst) (second lst))
                   (get-a-phrase-3-aux-4th (list (first lst) (second lst))))))
          (push l1 w))))
      ((equal (length l) 4)
       (do ((lst l (cddr lst))
          (n2)
          (w))
          ((null lst) (reverse w))
        (let ((l2 (cons (list (first lst) (second lst))
                  (get-a-phrase-2-aux-4th (list (first lst) (second lst))))))
         (push l2 w))))
      ((equal (length l) 6)
       (do ((lst l (cddr lst))
          (w))
          ((null lst) (reverse w))
         (let ((l3 (cons (list (first lst) (second lst))
                  (get-a-phrase-1-aux-4th (list (first lst) (second lst))))))
          (push l3 w))))))


(defun get-a-phrase-one-2-aux-4th (pair)
  (let ((l (get-a-phrase-one-aux-4th pair))
     (n))
    (setf n (number-of-notes l))
    (list l '***4beat*** (get-rythm-of-4beat n) '***3beat*** (get-rythm-of-3beat n))))

(defun get-a-phrase-two-2-aux-4th (pair)
  (let ((l (get-a-phrase-two-aux-4th pair))
     (n))
    (setf n (number-of-notes l))
    (list l '***4beat*** (get-rythm-of-4beat n) '***3beat*** (get-rythm-of-3beat n))))


;;;
;;;(get-phrases-one-4th '(("CM7" ion "A7" hmp5) ("Dm7" dor "G7" alt) ("CM7" ion)))
;;;
;;;((((CM7 ion) do) ((A7 hmp5) do so la mi si)) ***4beat*** (4 16pause 16 16 16 4 4) ***3beat***
;;; (4 3(8pause 8 8) 8 16 16))
;;;((((Dm7 dor) mi +la fa do so re) ((G7 alt) la re so fa)) ***4beat***
;;; (16 16 16 16 4 3(8pause 8pause 8) 16 16 16 16) ***3beat*** (3(8 8 8) 16 16 16 16 3(8 8 8)))
;;;((((CM7 ion) re so)) ***4beat*** (2 2) ***3beat*** (2 4))
;;;((((("CM7" ion) do) (("A7" hmp5) do so la mi si)) ***4beat*** (4 16pause 16 16 16 4 4) ***3beat***
;;; (4 "3(8pause 8 8)" 8 16 16))
;;; (((("Dm7" dor) mi +la fa do so re) (("G7" alt) la re so fa)) ***4beat***
;;; (16 16 16 16 4 "3(8pause 8pause 8)" 16 16 16 16) ***3beat*** ("3(8 8 8)" 16 16 16 16 "3(8 8 8)"))
;;; (((("CM7" ion) re so)) ***4beat*** (2 2) ***3beat*** (2 4)))
;;;
;;;(get-phrases-two-4th '(("CM7" ion "A7" hmp5) ("Dm7" dor "G7" alt) ("CM7" ion)))
;;;
;;;((((CM7 ion) si do) ((A7 hmp5) la)) ***4beat*** (2.5 8 8) ***3beat*** (4 4 4))
;;;((((Dm7 dor) re so) ((G7 alt) la)) ***4beat*** (2.5 8 8) ***3beat*** (4 4 4))
;;;((((CM7 ion) so)) ***4beat*** (1) ***3beat*** (2.5))
;;;((((("CM7" ion) si do) (("A7" hmp5) la)) ***4beat*** (2.5 8 8) ***3beat*** (4 4 4))
;;; (((("Dm7" dor) re so) (("G7" alt) la)) ***4beat*** (2.5 8 8) ***3beat*** (4 4 4))
;;; (((("CM7" ion) so)) ***4beat*** (1) ***3beat*** (2.5)))
;;;
(defun get-phrases-one-4th (l)
  (do ((lst l (cdr lst))
     (w))
     ((null lst) (reverse w))
   (let ((ll (get-a-phrase-one-2-aux-4th (car lst))))
    (format t "~%~a" ll)
    (push ll w))))

(defun get-phrases-two-4th (l)
  (do ((lst l (cdr lst))
     (w))
     ((null lst) (reverse w))
   (let ((ll (get-a-phrase-two-2-aux-4th (car lst))))
    (format t "~%~a" ll)
    (push ll w))))


;;;
;;;
;;;
(defun auto-comp-one-4th (wn)
  (tagbody
    (my-randomize)
    (format t "~%********** ~a ************" (second (first wn)))
    (format t "~%The original key is ~a." (first (first wn)))
    (format t "~%Enter a key.")
    loop1
    (setf l1 (read-sentence))
    (if (not (key-p (car l1)))
      (go loop1))
    (if (equal (car l1) (first (first wn)))
      (setf l2 (cdr wn))
     (setf l2 (modulate-key1-to-key2 (cdr wn) (first (first wn)) (car l1))))
    (format t "~%********* The key is ~a. **********" (car l1))
    ;(print l2)
    (get-phrases-one-4th l2)))


(defun auto-comp-two-4th (wn)
  (tagbody
    (my-randomize)
    (format t "~%********** ~a ************" (second (first wn)))
    (format t "~%The original key is ~a." (first (first wn)))
    (format t "~%Enter a key.")
    loop1
    (setf l1 (read-sentence))
    (if (not (key-p (car l1)))
      (go loop1))
    (if (equal (car l1) (first (first wn)))
      (setf l2 (cdr wn))
     (setf l2 (modulate-key1-to-key2 (cdr wn) (first (first wn)) (car l1))))
    (format t "~%********* The key is ~a. **********" (car l1))
    (get-phrases-two-4th l2)))