 
 ;; Author: Mario Lang <mlang@delysid.org>
 ;; Keywords: audio, ecasound, eci, comint, process, pcomplete
-;; Version: 0.5
+;; Version: 0.6
 
 ;; This file is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by

  (interactive "nValue for Chain operator parameter: ")
  (eci-command (format "copp-set %f" value buffer-or-process)))

(defun eci-cop-register ()
  (let (result (cops (split-string (eci-command "cop-register") "\n")))
    (while cops
      (if (string-match "^[0-9]+\\. \\([^,]+\\), \\(-[a-zA-Z]+:\\(.*\\)\\)" (car cops))
	  (setq
	   result
	   (cons
	    (list (match-string-no-properties 1 (car cops))
		  (substring (car cops) (match-beginning 2)
			                (match-beginning 3))
		  (split-string (match-string-no-properties 3 (car cops)) ","))
	    result)))
      (setq cops (cdr cops)))
    (set (make-local-variable 'eci-cop-register)
	 result)))

(defun ecasound-cop-add ()
  "Interactively prompt for the name and argument of a chain operator to add."
  (interactive)
  (unless eci-cop-register
    (eci-cop-register))


(defun pcomplete/ecasound-iam-mode/ao-add ()
  (pcomplete-here (ecasound-input-file-or-device)))

(defun pcomplete/ecasound-iam-mode/cop-add ()
  (unless eci-cop-register
    (eci-cop-register))
  (unless eci-ladspa-register
    (eci-ladspa-register))
  (cond
   ((= pcomplete-last 1)
    (pcomplete-here (mapcar (lambda (elt) (nth 1 elt)) eci-cop-register)))
   ((> pcomplete-last 1)
    (if (and (= pcomplete-last 2)
	     (string= (pcomplete-arg) "-el"))
	    (progn (pcomplete-next-arg)
		   (pcomplete-here (mapcar (lambda (elt) (nth 1 elt))
					   eci-ladspa-register)))
      (if (and (string= (pcomplete-arg) "-el")
	       (> pcomplete-last 2))
	      (let* ((args (eci-register-find-arg (pcomplete-arg -1)
						  eci-ladspa-register))
		     (arg (nth (- pcomplete-last 3) args)))
		(if arg
		    (message "%s" arg)
		  (message "No help available")))
	(let* ((args (eci-register-find-arg (pcomplete-arg)
					    eci-cop-register))
	       (arg (nth (- pcomplete-last 2) args)))
	  (if arg
	      (message "%s" arg)
	    (message "No help available")))))))
  (throw 'pcompleted t))


