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 14, 2024
1 parent 3eaebc6 commit b91f8af
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tools/topo2_list_vol_kcontrols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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
]

assert len(volume_kcontrols) == 1

# TODO: find how the kernel makes this "topology v1 versus v2"
# decision and mimic it here.
pga_prefix = f"{gb.widget.name} " if gb.widget.name.startswith("PGA") else ""

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


if __name__ == "__main__":
main()

0 comments on commit b91f8af

Please sign in to comment.