-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmc_impl.py
121 lines (96 loc) · 3.83 KB
/
vmc_impl.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from pythonosc import osc_message_builder, osc_message
class AbstractBlend (object):
def __init__ (self, name: str):
self.title = name
def createBlendShapeMessage (self, value: float) -> osc_message.OscMessage:
message = osc_message_builder.OscMessageBuilder(address="/VMC/Ext/Blend/Val")
message.add_arg(self.title)
message.add_arg(value)
return message.build()
def getMessage (self) -> osc_message.OscMessage:
return self.createBlendShapeMessage(404)
class ToggleBlend (AbstractBlend):
def __init__ (self, name: str, minValue: float, maxValue: float):
super().__init__(name)
self.state = False
self.minValue = minValue
self.maxValue = maxValue
def toggle (self) -> None:
self.state = not self.state
def get (self) -> float:
if self.state:
return self.maxValue
else:
return self.minValue
def getMessage (self) -> osc_message.OscMessage:
return self.createBlendShapeMessage(self.get())
class SliderBlend (AbstractBlend):
def __init__ (self, name: str, minValue: float, maxValue: float, step: float):
super().__init__(name)
self.currentValue = minValue
self.step = step
self.minValue = minValue
self.maxValue = maxValue
def get (self) -> float:
return self.currentValue
def set (self, newValue: float) -> None:
self.currentValue = newValue
def getMessage (self) -> osc_message.OscMessage:
return self.createBlendShapeMessage(self.get())
class DurationBlend (AbstractBlend):
def __init__(self, name: str, progression:dict, offValue:float, sticky:bool):
super().__init__(name)
pairs = [(int(i), float(progression[i])) for i in progression]
pairs.sort(key=lambda x: x[0])
self.index = 0
self.values = []
self.currentOffValue = float(offValue)
self.trueOffValue = float(offValue)
self.sticky = bool(sticky)
self.reverse = False
for i in range(len(pairs)):
currentCheckpoint = pairs[i-1]
nextCheckpoint = pairs[i]
steps = nextCheckpoint[0] - currentCheckpoint[0]
if i == 0:
currentCheckpoint = pairs[i]
steps = currentCheckpoint[0]
steps = max(steps, 1)
stepSize = (nextCheckpoint[1] - currentCheckpoint[1]) / steps
for j in range(steps):
if j == steps - 1 or len(self.values) == 0:
self.values.append(nextCheckpoint[1])
else:
self.values.append(self.values[-1] + stepSize)
def get (self) -> float:
if self.index < 0:
return self.currentOffValue
else:
return self.values[self.index]
def start (self):
if self.reverse == False:
self.index = 0
else:
self.index = len(self.values) - 1
def step (self) -> bool:
if self.reverse == True:
self.index -= 1
if self.index < 0:
self.currentOffValue = self.values[0]
if self.sticky == True:
self.reverse = False
return False
else:
self.index += 1
if self.index >= len(self.values):
self.index = -1
if self.sticky == True:
self.reverse = True
self.currentOffValue = self.values[-1]
return False
return True
def getMessage (self) -> osc_message.OscMessage:
return self.createBlendShapeMessage(self.get())
def createBlendApplyMessage ():
message = osc_message_builder.OscMessageBuilder(address="/VMC/Ext/Blend/Apply")
return message.build()