From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/sound/collection_udo.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 site/sound/collection_udo.py (limited to 'site/sound/collection_udo.py') diff --git a/site/sound/collection_udo.py b/site/sound/collection_udo.py new file mode 100755 index 0000000..30124de --- /dev/null +++ b/site/sound/collection_udo.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +import json +import os +import cgi +import sys + + +def getdata(): + form = cgi.FieldStorage() + request = form.getvalue("collections") + collections = request.split(",") + + with open("map.json", "r") as f: + data = json.load(f) + + filecount = 0 + udo_data = str() + icollectionid = 0 + opcode_str1 = "opcode sounddb_getcollectionid, i, So\n\tScollection, i_ xin\n" + opcode_str2 = "opcode sounddb_getcollection, i[]i, S\n\tScollection xin\n" + first = True + for name, data in data.iteritems(): + if name not in collections: + continue + + safe_name = name.replace(".", "_") + + if not first: + opcode_str1 += "\telseif " + opcode_str2 += "\telseif " + else: + first = False + opcode_str1 += "\tif " + opcode_str2 += "\tif " + + opcode_str1 += "(strcmp(Scollection, \"{}\") == 0) then\n\t\ticollectionid = {}\n".format(name, icollectionid) + opcode_str2 += "(strcmp(Scollection, \"{0}\") == 0) then\n\t\ticollection[] = gisdbFn_{0}\n\t\ticollectionid = {1}\n".format( + safe_name, icollectionid + ) + + if data["type"] == "melsys": + melsys = True + note_data = [None for x in range(0, 128)] + note_str = "gisdbNotes_{}[] init 128, 2".format(safe_name) + else: + note_str = None + melsys = False + + udo_data += "gisdbFn_{}[] fillarray ".format(safe_name) + index = 0 + for item in data["sounds"]: + exists = False + if melsys: + if note_data[item["note"]]: + exists = True + else: + note_data[item["note"]] = {"fn": "gisdbFn_{}[{}]".format(safe_name, index), "ratio": 1} + if not exists: + udo_data += "ftgen(0, 0, 0, 1, \"{}\", 0, 0, 0),".format(item["path"]) + index += 1 + udo_data = udo_data[:-1] + "\n\n" + if melsys: + for note in note_data: + pass + icollectionid += 1 + + opcode_str1 += "\tendif\n\txout icollectionid\nendop\n" + opcode_str2 += "\tendif\n\txout icollection, icollectionid\nendop\n" + opcode_str = opcode_str1 + "\n" + opcode_str2 + "\nopcode sounddb_getcollection, i[], S\n\tScollection xin\n\ticollection[], i_ sounddb_getcollection Scollection\n\txout icollection\nendop\n" + + print udo_data + "\n" + opcode_str + + +if __name__ == "__main__": + sys.stdout.write("Content-Type: text/plain\n\n") + getdata() + -- cgit v1.2.3