Skip to content

Commit

Permalink
Add info texts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattijs Kneppers committed Sep 10, 2024
1 parent eb22ea9 commit c3467c0
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
94 changes: 93 additions & 1 deletion maxdiff/patch_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def print_patcher(patcher_dict: dict, summarize: bool = True) -> dict | str:
name = get_box_text(box)
known_objects_map[name] = box

display_text = print_top_patcher_summary(patcher_dict)
display_text = print_parameter_info_texts(patcher_dict)
display_text += print_top_patcher_summary(patcher_dict)
display_text += print_patcher_summary_recursive(patcher_dict, known_objects_map)
return display_text
else:
Expand Down Expand Up @@ -479,6 +480,97 @@ def get_object_parameter_string(parameter: dict) -> str:
return parameter_string


def print_parameter_info_texts(patcher_dict: dict):
patcher = patcher_dict["patcher"]
display_text = get_parameters_string(patcher)
if display_text != "":
display_text = f"parameter texts:\n{display_text}"

return display_text


def get_parameters_string(patcher: dict) -> tuple[int, int]:
"""Recursively scans this patcher for parameters and returns a string representation"""
boxes = patcher["boxes"]
parameter_string = ""

for box_entry in boxes:
box = box_entry["box"]

param_info = get_param_info(box)

if param_info == None:
continue

if param_info["invisible"] == 2:
# This parameter is set to "Hidden"
continue

parameter_string += f' {param_info["longname"]}'

if param_info["invisible"] == 1:
parameter_string += " <not automatable>"

parameter_string += "\n"

if param_info["infotitle"]:
parameter_string += f' {param_info["infotitle"]}\n'
else:
parameter_string += " <no info title>\n"

parameter_string += " --------------\n"

if param_info["infotext"]:
parameter_string += f' {param_info["infotext"]}\n'
else:
parameter_string += " <no info text>\n"

if "patcher" in box:
patch = box["patcher"]
if box.get("maxclass") != "bpatcher" or (
box.get("maxclass") == "bpatcher" and box.get("embed") == 1
):
# get subpatcher or embedded bpatcher string
parameter_string += get_parameters_string(patch)

return parameter_string


def get_param_info(box:dict) -> dict:
param_info = {
"longname": None,
"shortname": None,
"infotitle" : None,
"infotext" : None,
"invisible": None
}

for key, value in box.items():
if key == "annotation_name":
param_info["infotitle"] = value

if key == "annotation":
param_info["infotext"] = value

if key == "saved_attribute_attributes":
# We take the attributes out or saved_attribute_attributes and present them as properties
for attrkey, attrvalue in value.items():
if attrvalue == "":
continue

if attrkey == "valueof":
if "parameter_longname" in attrvalue: param_info["longname"] = attrvalue["parameter_longname"]
if "parameter_longname" in attrvalue: param_info["shortname"] = attrvalue["parameter_longname"]
if "parameter_annotation_name" in attrvalue: param_info["infotitle"] = attrvalue["parameter_annotation_name"]
if "parameter_info" in attrvalue: param_info["infotext"] = attrvalue["parameter_info"]
if "parameter_invisible" in attrvalue: param_info["invisible"] = attrvalue["parameter_invisible"]

if param_info["longname"] == None:
return None

return param_info


def concat(a: str, b: str) -> str:
"""Concatenate two strings with a separator if both are non-empty."""
sep = " | "
Expand Down
22 changes: 16 additions & 6 deletions maxdiff/tests/test_baselines/Test.amxd.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
MIDI Effect Device
-------------------
parameter texts:
Dial 2
<no info title>
--------------
My Info View Text
Dial 1
My Info View Title
--------------
My Info View Text
parameters:
[p MySubpatcher]/[live.dial]: ['In a subpatcher', 'live.dial', 0]
[bpatcher ParamAbstraction.maxpat]/[obj-1]: ['InsideBpatcher', 'live.dial', 0]
Expand All @@ -8,16 +17,17 @@ parameters:
[bpatcher ParamAbstraction.maxpat]/[obj-1]: ['OverruledParamLongName', 'OverruledParamShortName', 0] > override > ['OverruledParamLongName', 'OverruledParamShortName', '-']
[live.tab]: ['Time Mode', 'Time Mode', 0]
[bpatcher ThisWasAnAbstractionBeforeEmbeddingIt.maxpat <embedded>]/[live.numbox]: ['EmbeddedParam', 'Embedded', 0]
[live.dial]: ['live.dial', 'live.dial', 0]
[live.dial]: ['live.dial[1]', 'live.dial', 0]
[live.dial]: ['Dial 1', 'Dial 1', 0]
[live.dial]: ['Dial 2', 'Dial 2', 0]
inherited_shortname: 1
banks:
0 (MyBank): ['live.dial', 'InsideBpatcher', '-', '-', '-', '-', '-', '-']
0 (MyBank): ['-', 'InsideBpatcher', '-', '-', '-', '-', '-', '-']
dependency_cache:
{'name': 'AbstractionWithParameter.maxpat', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1}
{'name': 'MyAbstraction.maxpat', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1}
{'name': 'ParamAbstraction.maxpat', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1}
{'name': 'beat-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1}
{'name': 'collContent.txt', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'fpic.png', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'PNG', 'implicit': 1}
{'name': 'hz-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1}

Expand All @@ -28,7 +38,7 @@ project:
collContent.txt

----------- patcher -----------
appversion: 8.6.2-x64-1 | rect: [65, 399, 927, 289] | openrect: [0, 0, 0, 169] | default_fontsize: 10.0 | default_fontname: Arial Bold | gridsize: [8, 8] | boxanimatetime: 500 | latency: 0 | is_mpe: 0 | platform_compatibility: 0 | autosave: 0
appversion: 8.6.2-x64-1 | rect: [149, 797, 927, 289] | openrect: [0, 0, 0, 169] | default_fontsize: 10.0 | default_fontname: Arial Bold | gridsize: [8, 8] | boxanimatetime: 500 | latency: 0 | is_mpe: 0 | platform_compatibility: 0 | autosave: 0
----------- objects -----------
[bpatcher ThisWasAnAbstractionBeforeEmbeddingIt.maxpat] embed: 1
----------- patcher -----------
Expand Down Expand Up @@ -101,8 +111,8 @@ appversion: 8.6.2-x64-1 | rect: [65, 399, 927, 289] | openrect: [0, 0, 0, 169] |
[live.banks]
[bpatcher ParamAbstraction.maxpat] offset: [-73, -62]
[bpatcher ParamAbstraction.maxpat] offset: [-73, -62]
[live.dial] activefgdialcolor: live_display_handle_two | parameter: <longname: live.dial[1] | modmode: 0 | shortname: live.dial | type: 0 | unitstyle: 0> | varname: live.dial[1]
[live.dial] parameter: <longname: live.dial | modmode: 0 | shortname: live.dial | type: 0 | unitstyle: 0>
[live.dial] activefgdialcolor: live_display_handle_two | annotation: My Info View Text | parameter: <longname: Dial 2 | modmode: 0 | shortname: Dial 2 | type: 0 | unitstyle: 0> | varname: live.dial[1]
[live.dial] annotation: My Info View Text | annotation_name: My Info View Title | parameter: <annotation_name: My Info View Title | info: My Info View Text | longname: Dial 1 | modmode: 0 | shortname: Dial 1 | type: 0 | unitstyle: 0>
[button] presentation: 1 | presentation_rect: [265, 26, 24, 24]
[bpatcher MyAbstraction.maxpat] offset: [-4, -12]
[comment A comment]
Expand Down
Binary file modified maxdiff/tests/test_files/Test.amxd
Binary file not shown.

0 comments on commit c3467c0

Please sign in to comment.