Skip to content

Commit

Permalink
Create generate_cpp_from_json.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Aug 15, 2023
1 parent 4ec41f1 commit 72b3881
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tools/soundfonts/preset_categories/generate_cpp_from_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json

# Fill in the correct path here
with open("presetcategories.json") as f:
data = json.load(f)

indent = 0


def printi(*values: object, **kwargs) -> None:
print(" " * 4 * indent + values[0], *values[1:], **kwargs)


def handleItem(item):
global indent
if "items" in item:
printi("MsBasicItem {")
indent += 1
printi('/*title=*/ u"{}",'.format(item["name"]))
printi("/*subItems=*/ {")
indent += 1
for subitem in item["items"]:
handleItem(subitem)
indent -= 1
printi("}")
indent -= 1
printi("},")
print()
else:
printi(
"MsBasicItem {{ midi::Program({0:<3} {1}) }},".format(
str(item["bank"]) + ",", item["program"]
)
)


for item in data:
handleItem(item)

0 comments on commit 72b3881

Please sign in to comment.