Skip to content

Commit

Permalink
Add new tools/topo2_list_vol_kcontrols.py
Browse files Browse the repository at this point in the history
Will be used in next commit to fix thesofproject#1068. See also discussion in earlier
attempt thesofproject#1068.
  • Loading branch information
marc-hb committed May 13, 2024
1 parent 3eaebc6 commit 4d4ce35
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tools/topo2_list_vol_kcontrols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

"""Parses the .tplg file argument and returns a list of volume
kcontrols, one per line.
Pro tip: try using these commands _interactively_ with ipython3
"""

# Keep this script short and simple. If you want to get something else
# from .tplg files, create another script.

import sys
from tplgtool2 import TplgBinaryFormat, TplgType, DapmType

TPLG_FORMAT = TplgBinaryFormat()


def main():
"Main"

parsed_tplg = TPLG_FORMAT.parse_file(sys.argv[1])

# pylint: disable=invalid-name
DAPMs = [
item for item in parsed_tplg if item.header.type == TplgType.DAPM_WIDGET.name
]

for dapm in DAPMs:

gain_blocks = [b for b in dapm.blocks if b.widget.id == DapmType.PGA.name]

for gb in gain_blocks:
# debug
# print(f"{gb.widget.id}: {gb.widget.name}")

# Either 1 volume kcontrol, or 1 volume + 1 switch
assert gb.widget.num_kcontrols > 0

# A switch is either a DapmType.SWITCH, or DapmType.MIXER
# with a max = 1. Exclude switches.
volume_kcontrols = [
kc
for kc in gb.kcontrols
if kc.hdr.type == DapmType.MIXER.name and kc.body.max != 1
]

for vkc in volume_kcontrols:
print(vkc.hdr.name)


if __name__ == "__main__":
main()

0 comments on commit 4d4ce35

Please sign in to comment.