aboutsummaryrefslogtreecommitdiff
path: root/wave_stats.py
blob: 26dd2dc903f383f223489bb0c3f2459da540ce41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Part of the Fifteen-Thieves Project
# Chris Xiong 2020
# License: Expat (MIT)
import sys
import os
import xv.util
import xv.amap

wavecnt = [0] * 1024
wavenames = []

def process_preset(t, is_rhy=False):
    if is_rhy:
        for rkey in range(0, 85):
            for rtone in range(0, 4):
                if t.value(f"sd_root.part[0].rhythm.rtone[{rkey}].rt_wmt[{rtone}].switch"):
                    try:
                        wavecnt[t.value(f"sd_root.part[0].rhythm.rtone[{rkey}].rt_wmt[{rtone}].wave_number_l")] += 1
                        wavecnt[t.value(f"sd_root.part[0].rhythm.rtone[{rkey}].rt_wmt[{rtone}].wave_number_r")] += 1
                    except IndexError:
                        pass
    else:
        for tone in range(0, 4):
            if t.value(f"sd_root.part[0].patch.tmt.tmt_block[{tone}].tone_switch"):
                try:
                    wavecnt[t.value(f"sd_root.part[0].patch.tone[{tone}].tn_wave.wave_number_l")] += 1
                    wavecnt[t.value(f"sd_root.part[0].patch.tone[{tone}].tn_wave.wave_number_r")] += 1
                except IndexError:
                    pass

if __name__ == "__main__":
    print("loading address mapping...", flush=True, file=sys.stderr)
    m = xv.amap.AddrMapTemplate("amaps/sd-80.amap")
    t = xv.amap.create_addr_map_tree(m)

    print("loading wave names...", file=sys.stderr)
    with open("data/sdwavelist","r") as f:
        for l in f:
            wavenames += [l.split('\t')[1].strip()]

    inst_dir = ["./data/patchparam/classical/", "./data/patchparam/contemporary/", "./data/patchparam/solo/"]
    #inst_dir += ["./data/patchparam/enhanced/", "./data/patchparam/special_1/", "./data/patchparam/special_2/"]

    rhy_dir = ["./data/rhythmparam/classical/", "./data/rhythmparam/contemporary/", "./data/rhythmparam/solo/"]
    #rhy_dir += ["./data/rhythmparam/enhanced/"]

    for i in inst_dir:
        for fn in os.listdir(i):
            mr = xv.util.load_memoryregion(os.path.join(i, fn))
            for addr, data in mr:
                ra = xv.util.b7belist2int(addr)
                t.data[ra:ra + len(data)] = data
            process_preset(t)

    for i in rhy_dir:
        for fn in os.listdir(i):
            mr = xv.util.load_memoryregion(os.path.join(i, fn))
            for addr, data in mr:
                ra = xv.util.b7belist2int(addr)
                t.data[ra:ra + len(data)] = data
            process_preset(t, True)

    for i, w in enumerate(wavenames):
        print(f"{w.ljust(16)}{wavecnt[i + 1]}")