@@ -21,9 +21,6 @@ Spline.PointEveryMs = 100
2121
2222function init()
2323 -- this runs once at when loading the extension
24- ofs.Bind("jitter", "Adds jitter to selection.")
25- ofs.Bind("random_noise", "Generates a random script.")
26- ofs.Bind("spline_smooth", "Adds spline smoothing to selection.")
2724 print("initialized")
2825end
2926
@@ -53,7 +50,7 @@ function gui()
5350 Random.MinStrokeDuration = ofs.Input("Min duration", Random.MinStrokeDuration)
5451 Random.MaxStrokeDuration = ofs.Input("Max duration", Random.MaxStrokeDuration)
5552 if ofs.Button("Add random noise") then
56- random_noise()
53+ binding. random_noise()
5754 end
5855
5956 if ofs.Button("Select all") then
@@ -69,11 +66,11 @@ function gui()
6966 Spline.PointEveryMs, splineChanged = ofs.Slider("Point per ms", Spline.PointEveryMs, 20, 500)
7067 if splineChanged then
7168 ofs.Undo()
72- spline_smooth()
69+ binding. spline_smooth()
7370 end
7471end
7572
76- function spline_smooth()
73+ function binding. spline_smooth()
7774 local catmullRom = function(v1, v2, v3, v4, s)
7875 s2 = s*s
7976 s3 = s*s*s
@@ -88,7 +85,7 @@ function spline_smooth()
8885 local script = ofs.Script(ofs.ActiveIdx())
8986 local actionCount = #script.actions
9087
91- if not ofs.HasSelection( script) then
88+ if not script:hasSelection( ) then
9289 return
9390 end
9491
@@ -109,41 +106,43 @@ function spline_smooth()
109106 -- since lua doesn't have a continue,
110107 -- we use a goto + a label at the bottom of the loop
111108 if not action2.selected or not action3.selected then goto continue end
112-
109+
110+
113111 local startTime = action2.at
114112 local endTime = action3.at
115113 local duration = endTime - startTime;
116114
117- pointCount = duration/Spline.PointEveryMs;
118-
119- for i=1, pointCount, 1 do
120- s = (i*Spline.PointEveryMs) / duration
121- time_ms = math.floor(action2.at + (i*Spline.PointEveryMs))
115+ local pointEverySecond = Spline.PointEveryMs / 1000.0
116+
117+ pointCount = duration/pointEverySecond
118+
119+ for i=1, pointCount-1, 1 do
120+ s = (i*pointEverySecond) / duration
121+ time_ms = action2.at + (i*pointEverySecond)
122122 spline_pos = catmullRom(action1.pos, action2.pos, action3.pos, action4.pos, s)
123123 spline_pos = clamp(spline_pos, 0, 100)
124- --ofs.AddAction(script, time_ms, spline_pos)
125124 table.insert( smoothedActions, {at=time_ms, pos=spline_pos} )
126125 end
127126 ::continue::
128127 end
129128
130129 for idx, action in ipairs(smoothedActions) do
131- ofs.AddAction(script, action.at, action.pos)
130+ script.actions:add(Action.new( action.at, action.pos) )
132131 end
133- ofs.Commit( script)
132+ script:commit( )
134133end
135134
136- function random_noise()
135+ function binding. random_noise()
137136 local script = ofs.Script(ofs.ActiveIdx())
138- ofs.ClearScript(script )
137+ script.actions:clear( )
139138
140139 local LastTimeMs = 0
141140 local LastPos = 0
142141 local TotalTimeMs = player.Duration() * 1000.0
143142
144143 local goingUp = true
145144 while LastTimeMs < TotalTimeMs do
146- ofs.AddAction(script, LastTimeMs, LastPos)
145+ script.actions:add(Action.new( LastTimeMs/1000.0 , LastPos) )
147146
148147 if goingUp then
149148 LastPos = LastPos + math.random(Random.MinStrokeLen, Random.MaxStrokeLen)
@@ -155,29 +154,29 @@ function random_noise()
155154 LastTimeMs = LastTimeMs + math.random(Random.MinStrokeDuration, Random.MaxStrokeDuration)
156155 end
157156
158- ofs.Commit( script)
157+ script:commit( )
159158end
160159
161160function select_all()
162161 local script = ofs.Script(ofs.ActiveIdx())
163162 for idx, action in ipairs(script.actions) do
164163 action.selected = true
165164 end
166- ofs.Commit( script)
165+ script:commit( )
167166end
168167
169168function select_none()
170169 local script = ofs.Script(ofs.ActiveIdx())
171170 for idx, action in ipairs(script.actions) do
172171 action.selected = false
173172 end
174- ofs.Commit( script)
173+ script:commit( )
175174end
176175
177- function jitter()
176+ function binding. jitter()
178177 local script = ofs.Script(ofs.ActiveIdx())
179178
180- if not ofs.HasSelection( script) then
179+ if not script:hasSelection( ) then
181180 return
182181 end
183182
@@ -198,7 +197,7 @@ function jitter()
198197 action.pos = action.pos + pos_jitter_value
199198 end
200199 end
201- ofs.Commit( script)
200+ script:commit( )
202201end
203202)" ;
204203
0 commit comments