 
 ;;; Utility functions for converting strings to data-structures.
 
-(defun eci-process-cop-register (string)
-  (set
-   (make-local-variable 'eci-cop-register)
-   (mapcar
-    (lambda (cop)
-      (when (string-match
-	     "^[0-9]+\\. \\([^,]+\\), \\(-[a-zA-Z]+\\)\\(:\\(.*\\)\\)?" cop)
-	(list (match-string-no-properties 1 cop)
-	      (match-string-no-properties 2 cop)
-	      (when (match-string 3 cop)
-		(split-string (match-string-no-properties 4 cop) ",")))))
-    (split-string string "\n"))))
-
-(defun eci-process-preset-register (string)
-  (set
-   (make-local-variable 'eci-preset-register)
-   (mapcar
-    (lambda (preset)
-      (when (string-match
-	     "^[0-9]+\\. \\([^,]+\\), \\(-pn:[a-zA-Z_]+\\)\\(:\\(.*\\)\\)?" preset)
-	(list (match-string-no-properties 1 preset)
-	      (match-string-no-properties 2 preset)
-	      (when (match-string 3 preset)
-		(split-string (match-string-no-properties 4 preset) ",")))))
-    (split-string string "\n"))))
-
-(defun eci-process-ctrl-register (string)
-  (set
-   (make-local-variable 'eci-ctrl-register)
-   (mapcar
-    (lambda (ctrl)
-      (when (string-match
-	     "^[0-9]+\\. \\([^,]+\\), \\(-[a-zA-Z0-9]+\\)\\(:\\(.*\\)\\)?"
-	     ctrl)
-	(list (match-string-no-properties 1 ctrl)
-	      (match-string-no-properties 2 ctrl)
-	      (when (match-string 3 ctrl)
-		(split-string (match-string-no-properties 4 ctrl) ",")))))
-    (split-string string "\n"))))
-
-(defun eci-process-ladspa-register (string)
-  (let (result)
-    (with-temp-buffer
-      (insert string)
-      (goto-char (point-min))
-      (while (re-search-forward "[0-9]+\\. \\(.*\\)\n\t\\(-el:[^,\n]+\\),\\(.*\\)" nil t)
-	(let ((full-name (match-string-no-properties 1))
-	      (name (match-string-no-properties 2))
-	      (args (split-string (concat "'," (match-string-no-properties 3)
-					  ",'") "','")))
-	  (setq result (cons (list full-name name args) result)))))
-    (set (make-local-variable 'eci-ladspa-register)
-	 (nreverse result))))
+(defvar eci-cop-status-header
+  "### Chain operator status (chainsetup '\\([^']+\\)') ###\n")
 
 (defun eci-process-cop-status (string)
   (with-temp-buffer
     (insert string) (goto-char (point-min))
-    (when (re-search-forward
-	   "### Chain operator status (chainsetup '\\([^']+\\)') ###\n" nil t)
-      (let ((cs (match-string-no-properties 1)) result)
+    (when (re-search-forward eci-cop-status-header nil t)
+      (let (result)
 	(while (re-search-forward "Chain \"\\([^\"]+\\)\":\n" nil t)
 	  (let ((c (match-string-no-properties 1)) chain)
 	    (while (re-search-forward

  :group 'ecasound
  :type 'regexp)

(defconst ecasound-iam-commands
  '( ;; GENERAL
    "quit" "q"
    "start" "t"
    "stop" "s"
    "run"
    "debug"
    "help" "h"
    ;; GLOBAL
    "status" "st"
    "engine-status"
    ;; CHAINSETUPS
    "cs-add"
    "cs-remove"
    "cs-list"
    "cs-select"
    "cs-selected"
    "cs-index-select" "cs-iselect"
    "cs-load"
    "cs-save"
    "cs-save-as"
    "cs-edit"
    "cs-is-valid"
    "cs-connect"
    "cs-disconnect"
    "cs-connected"
    "cs-rewind" "rewind" "rw"
    "cs-forward" "forward" "fw"
    "cs-set-position" "cs-setpos" "setpos" "set-position"
    "cs-get-position" "cs-getpos" "getpos" "get-position"
    "cs-get-length" "get-length"
    "cs-set-length"
    "cs-toggle-loop"
    "cs-set-param"
    "cs-set-audio-format"
    "cs-status" "cs"
    ;; CHAINS
    "c-add"
    "c-remove"
    "c-list"
    "c-select"
    "c-index-select" "c-iselect"
    "c-select-all"
    "c-select-add"
    "c-deselect"
    "c-selected"
    "c-clear"
    "c-rename"
    "c-muting"
    "c-bypass"
    "c-forward" "c-fw"
    "c-rewind" "c-rw"
    "c-set-position" "c-setpos"
    "c-status"
    ;; AUDIO INPUT/OUTPUT OBJECTS
    "ai-add"
    "ao-add"
    "ai-select"
    "ao-select"
    "ai-index-select" "ai-iselect"
    "ao-index-select" "ao-iselect"
    "ai-selected"
    "ao-selected"
    "ai-attach"
    "ao-attach"
    "ai-remove"
    "ao-remove"
    "ai-forward" "ai-fw"
    "ao-forward" "ao-fw"
    "ai-rewind" "ai-rw"
    "ao-rewind" "ao-rw"
    "ai-set-position" "ai-setpos"
    "ao-set-position" "ao-setpos"
    "ai-get-position" "ai-getpos"
    "ao-get-position" "ao-getpos"
    "ai-get-length"
    "ao-get-length"
    "ai-get-format"
    "ao-get-format"
    "ai-wave-edit"
    "ao-wave-edit"
    "ai-list"
    "ao-list"
    "aio-register"
    "aio-status"
    ;; CHAIN OPERATORS
    "cop-add"
    "cop.list"
    "cop-remove"
    "cop-select"
    "cop-index-select" "cop-iselect"
    "cop-selected"
    "cop-set"
    "cop-status"
    "copp-list"
    "copp-select"
    "copp-index-select" "copp-iselect"
    "copp-selected"
    "copp-set"
    "copp-get"
    "cop-register"
    "preset-register"
    "ladspa-register"
    ;; CONTROLLERS
    "ctrl-add"
    "ctrl-remove"
    "ctrl-list"
    "ctrl-select"
    "ctrl-index-select" "ctrl-iselect"
    "ctrl-selected"
    "ctrl-status"
    "ctrl-register"
    ;; OBJECT MAPS
					; Unimplemented currently...
    )
  "Available Ecasound IAM commands.")
  
(defvar ecasound-iam-mode-map

		      (mapconcat #'identity (mapcar #'cadr args) "\n")
		    `(list ,@(mapcar #'cadr args))))
	`(interactive))
     ,@(cond
	((eq body nil)
	 `((eci-command
	    ,(if args
		 `(format ,(format "%S %s" name (mapconcat #'caddr args " "))
			  ,@(mapcar
			     (lambda (arg)
			       `(if (or (stringp ,(car arg)) (numberp ,(car arg)))
				    ,(car arg)
				  (mapconcat #'identity ,(car arg) ",")))
			     args))
	       (format "%S" name))
	    buffer-or-process)))
	((eq (car body) :hide-output)
	 `((let ((eci-hide-output (not (interactive-p))))
	     (eci-command
	      ,(if args
		   `(format ,(format "%S %s" name (mapconcat #'caddr args " "))
			    ,@(mapcar
			       (lambda (arg)
				 `(if (or (stringp ,(car arg)) (numberp ,(car arg)))
				      ,(car arg)
				    (mapconcat #'identity ,(car arg) ",")))
			       args))
		 (format "%S" name))
	      buffer-or-process))))
	(t body))))

(defmacro defecialias (alias def)
  `(defalias ',(intern (format "eci-%S" alias))
     ',(intern (format "eci-%S" def))))

(defeci int-cmd-list ()
  ""
  :hide-output)

(defeci map-cop-list ()
  ""
  :hide-output)

(defeci map-ctrl-list ()
  ""
  :hide-output)

(defeci map-ladspa-list ()
  ""
  :hide-output)

(defeci map-preset-list ()
  ""
  :hide-output)

(defeci run)

(defeci start)

(defeci cs-add ((chainsetup "sChainsetup to add: " "%s")))

(defeci cs-connect)

