-
Notifications
You must be signed in to change notification settings - Fork 13
/
card.go
73 lines (70 loc) · 1.7 KB
/
card.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package pulseaudio
type Card struct {
Index uint32
Name string
Module uint32
Driver string
Profiles map[string]*profile
ActiveProfile *profile
PropList map[string]string
Ports []port
}
func (c *Client) Cards() ([]Card, error) {
b, err := c.request(commandGetCardInfoList)
if err != nil {
return nil, err
}
var cards []Card
for b.Len() > 0 {
var card Card
var profileCount uint32
err := bread(b,
uint32Tag, &card.Index,
stringTag, &card.Name,
uint32Tag, &card.Module,
stringTag, &card.Driver,
uint32Tag, &profileCount)
if err != nil {
return nil, err
}
card.Profiles = make(map[string]*profile)
for i := uint32(0); i < profileCount; i++ {
var profile profile
err = bread(b,
stringTag, &profile.Name,
stringTag, &profile.Description,
uint32Tag, &profile.Nsinks,
uint32Tag, &profile.Nsources,
uint32Tag, &profile.Priority,
uint32Tag, &profile.Available)
if err != nil {
return nil, err
}
card.Profiles[profile.Name] = &profile
}
var portCount uint32
var activeProfileName string
err = bread(b,
stringTag, &activeProfileName,
&card.PropList,
uint32Tag, &portCount)
if err != nil {
return nil, err
}
card.ActiveProfile = card.Profiles[activeProfileName]
card.Ports = make([]port, portCount)
for i := uint32(0); i < portCount; i++ {
card.Ports[i].Card = &card
err = bread(b, &card.Ports[i])
}
cards = append(cards, card)
}
return cards, nil
}
func (c *Client) SetCardProfile(cardIndex uint32, profileName string) error {
_, err := c.request(commandSetCardProfile,
uint32Tag, cardIndex,
stringNullTag,
stringTag, []byte(profileName), byte(0))
return err
}