Uses 911K of libraries. Click here for Pure Java version (9901L/55K).
1 | !7 |
2 | |
3 | srecord AudioSource(S description, S volume, S baseVolume, bool mute, int index) {}
|
4 | |
5 | cmodule ListAudioSources > DynObjectTable<AudioSource> {
|
6 | //transient SimpleLiveValue<Float> lvVolume = floatLiveValue(); // for selected source |
7 | transient JTextField tfVolume; |
8 | |
9 | start {
|
10 | set fieldsInOrder; |
11 | dontPersist(); |
12 | doEveryAndNow(10.0, r updateList); |
13 | } |
14 | |
15 | |
16 | void updateList enter {
|
17 | LS lines = lines(backtick("pactl list sources"));
|
18 | new Matches m; |
19 | new L<AudioSource> list; |
20 | for i over lines: |
21 | if (swic(lines.get(i), "Source #")) {
|
22 | int idx = parseFirstInt(lines.get(i)); |
23 | AudioSource as = nu(AudioSource, index := idx, description := lines.get(i)); |
24 | for (int j = i+1; j < l(lines); j++) {
|
25 | S line = lines.get(j); |
26 | if (!startsWithSpace(line)) break; |
27 | line = trim(line); |
28 | if (swic_trim(line, "Description:", m)) |
29 | as.description = m.rest(); |
30 | else if (swic_trim(line, "Base Volume:", m)) |
31 | as.baseVolume = m.rest(); |
32 | else if (swic_trim(line, "Volume:", m)) |
33 | as.volume = iround(parseFirstInt(m.rest())*100.0/65536) + "%"; |
34 | else if (swic_trim(line, "Mute:", m)) |
35 | as.mute = isYes(m.rest()); |
36 | } |
37 | list.add(as); |
38 | } |
39 | setData(list); |
40 | } |
41 | |
42 | visualize {
|
43 | JComponent c = super.visualize(); |
44 | onTableSelectionChanged(table, r {
|
45 | setText(tfVolume, selected() == null ? "" : firstIntAsString(selected().volume)) |
46 | }); |
47 | tfVolume = jTextField(); |
48 | onEnter(tfVolume, r {
|
49 | if (selected() == null) ret; |
50 | backtickToConsole("pactl set-source-volume " + selected().index + " " + iround(parseFirstInt(gtt(tfVolume))/100.0*65536));
|
51 | updateList(); |
52 | }); |
53 | |
54 | ret centerAndEastWithMargins(c, vstackWithSpacing( |
55 | tableDependentButton_extraCondition(table, "Mute", |
56 | rThread {
|
57 | muteSource(selected()) |
58 | }, func -> bool { !selected().mute }),
|
59 | tableDependentButton_extraCondition(table, "Unmute", |
60 | rThread {
|
61 | unmuteSource(selected()) |
62 | }, func -> bool { selected().mute }),
|
63 | jlabel("Volume:"),
|
64 | tfVolume |
65 | , |
66 | jbutton("Export as text", r { showText("Audio source settings", exportAsText()) })
|
67 | )); |
68 | } |
69 | |
70 | // API |
71 | |
72 | S getSourceName(int index) {
|
73 | ret getString(objectWhere(data, +index), 'description); |
74 | } |
75 | |
76 | AudioSource findSourceByName(S name) {
|
77 | ret objectWhereIC(data, description := name); |
78 | } |
79 | |
80 | void muteSource(AudioSource src) {
|
81 | if (src == null) ret; |
82 | backtickToConsole("pactl set-source-mute " + src.index + " 1");
|
83 | updateList(); |
84 | } |
85 | |
86 | void unmuteSource(AudioSource src) {
|
87 | if (src == null) ret; |
88 | backtickToConsole("pactl set-source-mute " + src.index + " 0");
|
89 | updateList(); |
90 | } |
91 | |
92 | bool isSourceMuted(AudioSource src) {
|
93 | ret src != null && src.mute; |
94 | } |
95 | |
96 | S exportAsText() {
|
97 | ret linesMap(data(), func(AudioSource src) -> S {
|
98 | (src.mute ? "Muted audio source" : "Audio source") |
99 | + " " + quote(src.description) + " has volume " + parseFirstInt(src.volume) + "." |
100 | }); |
101 | } |
102 | } |
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1020375 |
| Snippet name: | System Audio Sources [Linux, Pulse Audio, OK] |
| Eternal ID of this version: | #1020375/34 |
| Text MD5: | efcf138f6146f4a46a6bcd9f44d45f6c |
| Transpilation MD5: | 6ff4019215efeb4315d1c3089e81ca12 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code (Dynamic Module) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-02-17 13:27:32 |
| Source code size: | 3165 bytes / 102 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 734 / 19358 |
| Version history: | 33 change(s) |
| Referenced in: | [show references] |