1;
2; Toplevel configuration for the ALSA Ordinary Mixer Interface
3;
4; Copyright (c) 2003 Jaroslav Kysela <perex@perex.cz>
5; License: GPL v2 (http://www.gnu.org/licenses/gpl.html)
6;
7
8(defun sndo_include (hctl stream)
9  (setq info (Acall "ctl_card_info" (Acall "hctl_ctl" hctl)))
10  (if (= (Aerror info) 0)
11    (progn
12      (setq info (Aresult info))
13      (setq driver (cdr (assq "driver" (unsetq info))))
14      (setq file (concat (path "data") "/alsa/cards/" (snd_card_alias driver) "/sndo" stream "-mixer.alisp"))
15      (setq r (include file))
16      (when (= r -2) (Asyserr "unable to find file " file))
17    )
18    (setq r (Aerror info))
19  )
20  (unsetq info driver file r)
21)
22
23(defun sndo_mixer_open_fcn (hctl stream pcm)
24  (setq fcn (concat "sndo" stream "_mixer_open"))
25  (setq r (if (exfun fcn) (funcall fcn hctl pcm) 0))
26  (when (= r 0)
27    (setq hctls (if hctls (cons hctls (cons hctl)) hctl))
28  )
29  (unsetq fcn r)
30)
31
32(defun sndo_mixer_open_hctl (name stream pcm)
33  (setq hctl (Acall "hctl_open" name nil))
34  (setq r (Aerror hctl))
35  (when (= r 0)
36    (setq hctl (Aresult hctl))
37    (setq r (sndo_include hctl stream))
38    (if (= r 0)
39       (setq r (sndo_mixer_open_fcn hctl stream pcm))
40       (Acall "hctl_close" hctl)
41    )
42  )
43  (unsetq hctl r)
44)
45
46(defun sndo_mixer_open_virtual (name stream pcm)
47  (setq file (concat (path "data") "/alsa/virtual/" name "/sndo" stream "-mixer.alisp"))
48  (setq r (include file))
49  (when (= r -2) (Asyserr "unable to find file " file))
50  (when (= r 0) (setq r (sndo_mixer_open_fcn nil stream pcm)))
51  (unsetq file r)
52)
53
54(defun sndo_mixer_open1 (name stream)
55  (if (compare-strings name 0 2 "hw:" 0 2)
56    (sndo_mixer_open_hctl name stream nil)
57    (sndo_mixer_open_virtual name stream nil)
58  )
59)
60
61(defun sndo_mixer_open (pname cname)
62  (setq r (sndo_mixer_open1 pname "p"))
63  (when (= r 0) (setq r (sndo_mixer_open1 cname "c")))
64  (when (!= r 0) (sndo_mixer_close))
65  (unsetq sndo_mixer_open
66	  sndo_mixer_open_pcm sndo_mixer_open_pcm1
67          sndo_mixer_open_virtual sndo_mixer_open_fcn
68	  sndo_include r)
69)
70
71(defun sndo_mixer_open_pcm1 (pcm stream)
72  (setq info (Acall "pcm_info" pcm))
73  (setq r (Aerror info))
74  (when (= r 0)
75    (setq info (Aresult info))
76    (setq card (cdr (assq "card" info)))
77    (setq r
78      (if (< card 0)
79	(sndo_mixer_open_virtual (Acall "pcm_name" pcm) stream pcm)
80        (sndo_mixer_open_hctl (format "hw:%i" card) stream pcm)
81      )
82    )
83  )
84  (unsetq info card r)
85)
86
87(defun sndo_mixer_open_pcm (ppcm cpcm)
88  (setq r (sndo_mixer_open_pcm1 ppcm "p"))
89  (when (= r 0) (setq r (sndo_mixer_open_pcm1 cpcm "c")))
90  (when (!= r 0) (sndo_mixer_close))
91  (unsetq sndo_mixer_open
92	  sndo_mixer_open_pcm sndo_mixer_open_pcm1
93          sndo_mixer_open_virtual sndo_mixer_open_fcn
94	  sndo_include r)
95)
96
97(defun sndo_mixer_close1 (hctl stream)
98  (when hctl
99    (progn
100      (setq fcn (concat "sndo" stream "_mixer_close"))
101      (when (exfun fcn) (funcall fcn hctl))
102      (unsetq fcn)
103      (Acall "hctl_close" hctl)
104    )
105  )
106)
107
108(defun sndo_mixer_close nil
109  (sndo_mixer_close1 (nth 1 hctls) "c")
110  (sndo_mixer_close1 (nth 0 hctls) "p")
111  (snd_card_alias_unset)
112  (unsetq hctls)
113)
114
115(include (concat (path "data") "/alsa/cards/aliases.alisp"))
116