yum-slop/TaSTT

Free self-hosted STT for VRChat.

git clone https://git.yummers.dev/yum-slop/TaSTT

yumBugfix: eliminate dead-end in certain animator layers4f3b938

v0.19.2
4.4 KiB135 linesraw
1from math import ceil
2from math import floor
3
4def replaceMacros(lines, macro_defs):
5    for k,v in macro_defs.items():
6        lines = lines.replace("%" + k + "%", v)
7    return lines
8
9class Config():
10    def __init__(self):
11        self.BOARD_ROWS=4
12        self.BOARD_COLS=48
13        self.CHARS_PER_CELL=256
14        self.BYTES_PER_CHAR=2
15        self.CHARS_PER_SYNC=10
16
17    def numRegions(self, which_layer):
18        num_cells = self.BOARD_ROWS * self.BOARD_COLS
19        layers_in_last_region = num_cells % self.CHARS_PER_SYNC
20        float_result = num_cells / self.CHARS_PER_SYNC
21        if which_layer >= layers_in_last_region:
22            return floor(float_result)
23        else:
24            return ceil(float_result)
25
26    def layerNeedsParity(self, which_layer):
27        num_cells = self.BOARD_ROWS * self.BOARD_COLS
28        layers_in_last_region = num_cells % self.CHARS_PER_SYNC
29        float_result = num_cells / self.CHARS_PER_SYNC
30        if which_layer >= layers_in_last_region:
31            return True
32        else:
33            return False
34
35config = Config()
36
37# Implementation detail. We use this parameter to return from the terminal
38# state of the FX layer to the starting state.
39def getDummyParam():
40    return "TaSTT_Dummy"
41
42def getToggleParam():
43    return "TaSTT_Toggle"
44
45def getScaleParam():
46    return "TaSTT_Scale"
47
48def getEnablePhonemeParam():
49    return "TaSTT_Enable_Phoneme"
50
51# When this is set to true, the board clears.
52def getClearBoardParam():
53    return "TaSTT_Clear_Board"
54
55def getLockWorldParam():
56    return "TaSTT_Lock_World"
57
58# Each layer controls a group of cells. There's only one letter per layer, thus
59# this is also the name of the parameter which sets the letter for a layer.
60def getLayerParam(which_layer: int, byte: int) -> str:
61    return "TaSTT_L%02dB%01d" % (which_layer, byte)
62
63def getLayerName(which_layer: int, byte: int) -> str:
64    return getLayerParam(which_layer, byte)
65
66def getBlendParam(which_layer: int, byte: int) -> str:
67    return "TaSTT_L%02dB%01d_Blend" % (which_layer, byte)
68
69def getDefaultStateName(which_layer:int , byte: int):
70    return "TaSTT_L%02dB%01d_Do_Nothing" % (which_layer, byte)
71
72def getActiveStateName(which_layer: int, byte: int):
73    return "TaSTT_L%02dB%01d_Active" % (which_layer, byte)
74
75def getSelectStateName(which_layer, select):
76    return "TaSTT_L%02d_S%02d_B%01d" % (which_layer, select, byte)
77
78def getBlendStateName(which_layer, select, byte):
79    return "TaSTT_L%02d_S%02d_B%01d_Blend" % (which_layer, select, byte)
80
81def getLetterStateName(which_layer, select, letter, byte):
82    return "TaSTT_L%02d_S%02d_L%03d_B%01d" % (which_layer, select, letter, byte)
83
84def getSelectParam() -> str:
85    return "TaSTT_Select"
86
87def getEnableParam():
88    return "TaSTT_Enable"
89
90def getSoundParam(i: int):
91    return f"TaSTT_Sound{str(i)}"
92
93def getEllipsisParam():
94    return "TaSTT_Ellipsis"
95
96def getBoardIndex(which_layer, select):
97    # Because we divide the board into a multiple of 8 cells, some cells may
98    # describe animations which don't exist, depending on the size of the board.
99    # We work around this by simply wrapping those animations back to the top
100    # of the board, and rely on the OSC controller to simply not reference
101    # those cells.
102    return (select * config.CHARS_PER_SYNC + which_layer) % (config.BOARD_ROWS * config.BOARD_COLS)
103
104def getShaderParamByRowColByte(row, col, byte):
105    return "_Letter_Row%02d_Col%02d_Byte%01d" % (row, col, byte)
106
107# Mapping from layer to shader param.
108def getShaderParam(which_layer, select, byte):
109    index = getBoardIndex(which_layer, select)
110
111    col = index % config.BOARD_COLS
112    row = floor(index / config.BOARD_COLS)
113
114    return getShaderParamByRowCol(row, col, byte)
115
116# The name of the animation which writes `letter` at a specific position in the
117# display.
118def getLetterAnimationName(row, col, letter, nth_byte):
119    return "R%02dC%02dL%02dB%01d" % (row, col, letter, nth_byte)
120
121# The name of the animation which clears the entire board.
122def getClearAnimationName():
123    return "TaSTT_Clear_Board"
124
125def getAnimationNameByLayerAndIndex(which_layer, select, letter, nth_byte):
126    index = getBoardIndex(which_layer, select)
127
128    col = index % config.BOARD_COLS
129    row = floor(index / config.BOARD_COLS)
130
131    return "R%02dC%02dL%02dB%01d" % (row, col, letter, nth_byte)
132
133# Returns the path to the animation for the given shader parameter + letter.
134def getAnimationPath(shader_param, letter):
135    return "generated/animations/%s_Letter%02d.anim" % (shader_param, letter)