Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 114 additions & 2 deletions 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 @@ -401,12 +402,14 @@ def get_parameters_string_block(patcher: dict) -> str:

if "parameterbanks" in parameters:
parameters_string += "banks:\n"
parameter_strings = []
for key, value in parameters["parameterbanks"].items():
parameters_string += (
parameter_strings.append(
f"\t{value['index']}"
+ (f" ({value['name']})" if value["name"] != "" else "")
+ f": {value['parameters']}"
)
parameters_string += "\n".join(parameter_strings)

return f"parameters:\n{parameters_string}\n"

Expand Down Expand Up @@ -479,6 +482,115 @@ def get_object_parameter_string(parameter: dict) -> str:
return parameter_string


def print_parameter_info_texts(patcher_dict: dict) -> str:
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) -> str:
"""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"]

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)

param_info = get_param_info(box)

if param_info == None:
continue

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

extra_messages = []

if param_info["invisible"] == 1 or param_info["invisible"] == 2:
extra_messages.append(" _not automatable_")

if param_info["invisible"] == 2:
extra_messages.append(" _not stored_")

if param_info["presentation"] != 1:
extra_messages.append(" _not in interface_")

if extra_messages:
parameter_string += " ".join(extra_messages) + "\n"

parameter_string += "\n"

parameter_string += "- "
if param_info["infotitle"]:
parameter_string += f'{param_info["infotitle"]}\n'
else:
parameter_string += f'_no info title_ => {param_info["longname"]}\n'

parameter_string += "- "
if param_info["infotext"]:
parameter_string += f'{param_info["infotext"]}\n'
else:
parameter_string += "_no info text_\n"

parameter_string += "\n"

return parameter_string


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

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

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
49 changes: 34 additions & 15 deletions maxdiff/tests/test_baselines/Test.amxd.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
MIDI Effect Device
-------------------
parameter texts:
### In a subpatcher ###
_not in interface_

- _no info title_ => In a subpatcher
- _no info text_

### Time Mode ###
_not automatable_ _not stored_ _not in interface_

- Time Mode
- Toggles between Beat Sync and Free running (Hz).

### Dial 2 ###
_not in interface_

- _no info title_ => Dial 2
- _no info text_

### Dial 1 ###
_not in interface_

- 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]
[AbstractionWithParameter]/[obj-1]: ['MyParameter', 'MyParameter', 0]
[AbstractionWithParameter]/[obj-1]: ['MyParameter[1]', 'MyParameter', 0] > override > ['MyParameter[1]', '-', '-']
[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): ['Dial 1', 'InsideBpatcher', '-', '-', '-', '-', '-', '-']
1 (MyBank2): ['Dial 2', 'In a subpatcher', '-', '-', '-', '-', '-', '-']
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}
Expand All @@ -29,14 +54,8 @@ 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.5-x64-1 | rect: [246, 585, 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 | external_mpe_tuning_enabled: 0 | platform_compatibility: 0 | autosave: 0
----------- objects -----------
[bpatcher ThisWasAnAbstractionBeforeEmbeddingIt.maxpat] embed: 1
----------- patcher -----------
appversion: 8.6.2-x64-1 | rect: [927, 431, 640, 480]
----------- objects -----------
[live.comment Embedded]
[live.numbox] parameter: <longname: EmbeddedParam | modmode: 3 | shortname: Embedded | type: 0 | unitstyle: 0>
[message 😋] fontsize: 20.0
[AbstractionWithParameter]
[AbstractionWithParameter]
Expand All @@ -47,7 +66,7 @@ appversion: 8.6.2-x64-1 | rect: [65, 399, 927, 289] | openrect: [0, 0, 0, 169] |
[button]
[gen @t exponent]
----------- patcher -----------
appversion: 8.6.2-x64-1 | classnamespace: dsp.gen | rect: [84, 144, 653, 641]
appversion: 8.6.5-x64-1 | classnamespace: dsp.gen | rect: [84, 144, 653, 641]
----------- objects -----------
[codebox]
//============================================================
Expand Down Expand Up @@ -90,7 +109,7 @@ appversion: 8.6.2-x64-1 | rect: [65, 399, 927, 289] | openrect: [0, 0, 0, 169] |
[coll @embed 1] coll_data: {'count': 2, 'data': [{'key': 0, 'value': ['test']}, {'key': 1, 'value': ['another', 'test']}]} | embed: 1 | precision: 6
[p MySubpatcher]
----------- patcher -----------
appversion: 8.6.2-x64-1 | rect: [805, 282, 271, 250]
appversion: 8.6.5-x64-1 | rect: [805, 282, 271, 250]
----------- objects -----------
[live.dial] parameter: <longname: In a subpatcher | modmode: 0 | shortname: live.dial | type: 0 | unitstyle: 0>
[t b b]
Expand All @@ -102,8 +121,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 | 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.