-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.lua
1557 lines (1249 loc) · 54.1 KB
/
plugin.lua
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
THIS FILE IS AUTOGENERATED WITH THE COMPILE.PY FILE.
THIS IS DONE IN ORDER TO ALLOW A MULTIFILE MODULE STRUCTURE
FOR THE PROJECT.
For users:
Don't worry too much about it. You only really need the
plugin.lua file and the settings.ini file. Delete everything
else, if you really don't care about anything.
For developers:
Please refrain from editing the plugin.lua file directly.
Rather, do edit the modules directly and then compile with
the provided script.
]]
-- MODULES:
editor = {}
gui = {}
mathematics = {}
menu = {}
style = {}
sv = {}
util = {}
window = {}
-------------------------------------------------------------------------------------
-- modules\editor.lua
-------------------------------------------------------------------------------------
function editor.placeElements(elements, type)
if #elements == 0 then return end
local status = "Inserted " .. #elements .. " "
if not type or type == 0 then
actions.PlaceScrollVelocityBatch(elements)
status = status .. "SV"
elseif type == 1 then
actions.PlaceHitObjectBatch(elements)
status = status .. "note"
elseif type == 2 then
actions.PlaceTimingPointBatch(elements)
status = status .. "BPM Point"
end
local pluralS = #elements == 1 and "" or "s"
statusMessage = status .. pluralS .. "!"
end
function editor.removeElements(elements, type)
if #elements == 0 then return end
local status = "Removed " .. #elements .. " "
if not type or type == 0 then
actions.RemoveScrollVelocityBatch(elements)
status = status .. "SVs"
elseif type == 1 then
actions.RemoveHitObjectBatch(elements)
status = status .. "notes"
elseif type == 2 then
actions.RemoveTimingPointBatch(elements)
status = status .. "BPM Points"
end
statusMessage = status .. "!"
end
editor.typeAttributes = {
-- SV
[0] = {
"StartTime",
"Multiplier"
},
-- "Note"
[1] = {
"StartTime",
"Lane",
"EndTime",
-- "HitSound", left out because there's some trouble with comparing hitsound values
"EditorLayer"
},
-- BPM
[2] = {
"StartTime",
"Bpm",
-- "Signature", same reason
}
}
--- Manipulates a table of elements with specified functions and returns a new table
-- Iterates over each possible attribute for a given type, it will apply a function
-- if one has been defined for that type in the settings table.
-- @param elements Table of elements to manipulate
-- @param typeMode Number between 0 and 2, representing the type SV, note or BPM
-- @param settings Table, where each key is a attribute of a type and the value is a function to apply to that attribute
--[[
Example:
settings = {
StartTime = function(t) return t + 100 end
}
would shift all StartTimes by 100
]]
function editor.createNewTableOfElements(elements, typeMode, settings)
local newTable = {}
for i, element in pairs(elements) do
local newElement = {}
for _, attribute in pairs(editor.typeAttributes[typeMode]) do
if settings[attribute] then
newElement[attribute] = settings[attribute](element[attribute])
else
newElement[attribute] = element[attribute]
end
end
newTable[i] = newElement
end
local newElements = {}
for i, el in pairs(newTable) do
if typeMode == 0 then
newElements[i] = utils.CreateScrollVelocity(el.StartTime, el.Multiplier)
elseif typeMode == 1 then
newElements[i] = utils.CreateHitObject(el.StartTime, el.Lane, el.EndTime, nil)
elseif typeMode == 2 then
newElements[i] = utils.CreateTimingPoint(el.StartTime, el.Bpm, nil)
end
end
return newElements
end
-------------------------------------------------------------------------------------
-- modules\gui.lua
-------------------------------------------------------------------------------------
function gui.title(title, skipSeparator, helpMarkerText)
if not skipSeparator then
gui.spacing()
imgui.Separator()
end
gui.spacing()
imgui.Text(string.upper(title))
if helpMarkerText then
gui.helpMarker(helpMarkerText)
end
gui.spacing()
end
function gui.sameLine()
imgui.SameLine(0, style.SAMELINE_SPACING)
end
function gui.separator()
gui.spacing()
imgui.Separator()
end
function gui.spacing()
imgui.Dummy({0,5})
end
function gui.tooltip(text)
if imgui.IsItemHovered() then
imgui.BeginTooltip()
imgui.PushTextWrapPos(imgui.GetFontSize() * 25)
imgui.Text(text)
imgui.PopTextWrapPos()
imgui.EndTooltip()
end
end
function gui.helpMarker(text)
imgui.SameLine()
imgui.TextDisabled("(?)")
gui.tooltip(text)
end
function gui.startEndOffset(vars)
local widths = util.calcAbsoluteWidths({ 0.3, 0.7 })
local offsetStep = 1
-- ROW 1
if imgui.Button("Current", {widths[1], style.DEFAULT_WIDGET_HEIGHT}) then
vars["startOffset"] = state.SongTime
statusMessage = "Copied into start offset!"
end
gui.tooltip("Copies the current editor position into the start offset")
imgui.SameLine(0, style.SAMELINE_SPACING)
imgui.PushItemWidth(widths[2])
_, vars["startOffset"] = imgui.InputInt("Start offset in ms", vars["startOffset"], offsetStep)
imgui.PopItemWidth()
-- ROW 2
if imgui.Button(" Current ", {widths[1], style.DEFAULT_WIDGET_HEIGHT}) then
vars["endOffset"] = state.SongTime
statusMessage = "Copied into end offset!"
end
gui.tooltip("Copies the current editor position into the end offset")
imgui.SameLine(0, style.SAMELINE_SPACING)
imgui.PushItemWidth(widths[2])
_, vars["endOffset"] = imgui.InputInt("End offset in ms", vars["endOffset"], offsetStep)
imgui.PopItemWidth()
end
function gui.printVars(vars, title)
if imgui.CollapsingHeader(title, imgui_tree_node_flags.DefaultOpen) then
imgui.Columns(3)
gui.separator()
imgui.Text("var"); imgui.NextColumn();
imgui.Text("type"); imgui.NextColumn();
imgui.Text("value"); imgui.NextColumn();
gui.separator()
if vars == state then
local varList = { "DeltaTime", "UnixTime", "IsWindowHovered", "Values", "SongTime", "SelectedHitObjects", "CurrentTimingPoint" }
for _, value in pairs(varList) do
util.toString(value); imgui.NextColumn();
util.toString(type(vars[value])); imgui.NextColumn();
util.toString(vars[value]); imgui.NextColumn();
end
else
for key, value in pairs(vars) do
util.toString(key); imgui.NextColumn();
util.toString(type(value)); imgui.NextColumn();
util.toString(value); imgui.NextColumn();
end
end
imgui.Columns(1)
gui.separator()
end
end
function gui.plot(values, title, valueAttribute)
if not values or #values == 0 then return end
local trueValues
if valueAttribute and values[1][valueAttribute] then
trueValues = {}
for i, value in pairs(values) do
trueValues[i] = value[valueAttribute]
end
else
trueValues = values
end
imgui.PlotLines(
title,
trueValues, #trueValues,
0,
nil,
nil, nil,
imgui.CreateVector2( -- does not seem to work with a normal table
style.CONTENT_WIDTH,
200
)
)
end
-- utils.OpenUrl() has been removed so i'll have to make do with this
function gui.hyperlink(url)
imgui.PushItemWidth(imgui.GetContentRegionAvailWidth())
imgui.InputText("##"..url, url, #url, imgui_input_text_flags.AutoSelectAll)
imgui.PopItemWidth()
end
function gui.bulletList(listOfLines)
if type(listOfLines) ~= "table" then return end
for _, line in pairs(listOfLines) do
imgui.BulletText(line)
end
end
function gui.averageSV(vars, widths)
local newWidths = widths or util.calcAbsoluteWidths(style.BUTTON_WIDGET_RATIOS)
if imgui.Button("Reset", {newWidths[1], style.DEFAULT_WIDGET_HEIGHT}) then
--[[
I tried to implement a function where it takes the default values
but it seems that I'm unsuccessful in deep-copying the table
Something like this:
function util.resetToDefaultValues(currentVars, defaultVars, varsToReset)
for _, key in pairs(varsToReset) do
if currentVars[key] and defaultVars[key] then
currentVars[key] = defaultVars[key]
end
end
return currentVars
end
]]
vars.averageSV = 1.0
statusMessage = "Reset average SV"
end
imgui.SameLine(0, style.SAMELINE_SPACING)
imgui.PushItemWidth(newWidths[2])
_, vars.averageSV = imgui.DragFloat("Average SV", vars.averageSV, 0.01, -100, 100, "%.2fx")
imgui.PopItemWidth()
end
function gui.intermediatePoints(vars)
imgui.PushItemWidth(style.CONTENT_WIDTH)
_, vars.intermediatePoints = imgui.InputInt("Intermediate points", vars.intermediatePoints, 4)
imgui.PopItemWidth()
vars.intermediatePoints = mathematics.clamp(vars.intermediatePoints, 1, 500)
_, vars.skipEndSV = imgui.Checkbox("Skip end SV?", vars.skipEndSV)
end
function gui.insertButton()
return imgui.Button("Insert into map", style.FULLSIZE_WIDGET_SIZE)
end
-------------------------------------------------------------------------------------
-- modules\mathematics.lua
-------------------------------------------------------------------------------------
-- Simple recursive implementation of the binomial coefficient
function mathematics.binom(n, k)
if k == 0 or k == n then return 1 end
return mathematics.binom(n-1, k-1) + mathematics.binom(n-1, k)
end
-- Currently unused
function mathematics.bernsteinPolynomial(i,n,t) return mathematics.binom(n,i) * t^i * (1-t)^(n-i) end
-- Derivative for *any* bezier curve with at point t
-- Currently unused
function mathematics.bezierDerivative(P, t)
local n = #P
local sum = 0
for i = 0, n-2, 1 do sum = sum + mathematics.bernsteinPolynomial(i,n-2,t) * (P[i+2].y - P[i+1].y) end
return sum
end
function mathematics.cubicBezier(P, t)
return P[1] + 3*t*(P[2]-P[1]) + 3*t^2*(P[1]+P[3]-2*P[2]) + t^3*(P[4]-P[1]+3*P[2]-3*P[3])
end
function mathematics.round(x, n) return tonumber(string.format("%." .. (n or 0) .. "f", x)) end
function mathematics.clamp(x, min, max)
if x < min then x = min end
if x > max then x = max end
return x
end
function mathematics.min(t)
local min = t[1]
for _, value in pairs(t) do
if value < min then min = value end
end
return min
end
function mathematics.max(t)
local max = t[1]
for _, value in pairs(t) do
if value > max then max = value end
end
return max
end
mathematics.comparisonOperators = {
"=", "!=", "<", "<=", ">=", ">"
}
-- No minus/division/root since they are present in the given operators already
-- Add negative values to subtract, multiply with 1/x to divide by x etc.
mathematics.arithmeticOperators = {
"=", "+", "×", "^"
}
function mathematics.evaluateComparison(operator, value1, value2)
local compareFunctions = {
["="] = function (v1, v2) return v1 == v2 end,
["!="] = function (v1, v2) return v1 ~= v2 end,
["<"] = function (v1, v2) return v1 < v2 end,
["<="] = function (v1, v2) return v1 <= v2 end,
[">="] = function (v1, v2) return v1 >= v2 end,
[">"] = function (v1, v2) return v1 > v2 end
}
return compareFunctions[operator](value1, value2)
end
function mathematics.evaluateArithmetics(operator, oldValue, changeValue)
local arithmeticFunctions = {
["="] = function (v1, v2) return v2 end,
["+"] = function (v1, v2) return v1 + v2 end,
["×"] = function (v1, v2) return v1 * v2 end,
["^"] = function (v1, v2) return v1 ^ v2 end
}
return arithmeticFunctions[operator](oldValue, changeValue)
end
-------------------------------------------------------------------------------------
-- modules\menu.lua
-------------------------------------------------------------------------------------
function menu.information()
if imgui.BeginTabItem("Information") then
gui.title("Help", true)
function helpItem(item, text)
imgui.BulletText(item)
gui.helpMarker(text)
end
helpItem("Linear SV", "Creates an SV gradient based on two points in time")
helpItem("Stutter SV", "Creates a normalized stutter effect with start, equalize and end SV")
helpItem("Cubic Bezier", "Creates velocity points for a path defined by a cubic bezier curve")
helpItem("Range Editor", "Edit SVs/Notes/BPM points in the map in nearly limitless ways")
gui.title("About", false, "Hyperlinks have been removed so copy-able links have been provided to paste into your browser")
function listItem(text, url)
imgui.TextWrapped(text)
gui.hyperlink(url)
end
listItem("iceSV Wiki (in progress)", "https://github.com/IceDynamix/iceSV/wiki")
listItem("Github Repository", "https://github.com/IceDynamix/iceSV")
listItem("Heavily inspired by Evening's re:amber", "https://github.com/Eve-ning/reamber")
gui.tooltip("let's be real this is basically a direct quaver port")
imgui.EndTabItem()
end
end
function menu.linearSV()
local menuID = "linear"
if imgui.BeginTabItem("Linear") then
-- Initialize variables
local vars = {
startSV = 1,
endSV = 1,
intermediatePoints = 16,
startOffset = 0,
endOffset = 0,
skipEndSV = false,
lastSVs = {}
}
util.retrieveStateVariables(menuID, vars)
-- Create UI Elements
gui.title("Offset", true)
gui.startEndOffset(vars)
gui.title("Velocities")
local velocities = { vars.startSV, vars.endSV }
imgui.PushItemWidth(style.CONTENT_WIDTH)
_, velocities = imgui.DragFloat2("Start/End Velocity", velocities, 0.01, -10.0, 10.0, "%.2fx")
imgui.PopItemWidth()
vars.startSV, vars.endSV = table.unpack(velocities)
gui.helpMarker("Ctrl+Click to enter as text!")
local widths = util.calcAbsoluteWidths({0.7,0.3})
if imgui.Button("Swap start and end velocity", {widths[1], style.DEFAULT_WIDGET_HEIGHT}) then
vars.startSV, vars.endSV = vars.endSV, vars.startSV
end
gui.sameLine()
if imgui.Button("Reset", {widths[2], style.DEFAULT_WIDGET_HEIGHT}) then
vars.startSV = 1
vars.endSV = 1
end
gui.title("Utilities")
gui.intermediatePoints(vars)
gui.title("Calculate")
if gui.insertButton() then
vars.lastSVs = sv.linear(
vars.startSV,
vars.endSV,
vars.startOffset,
vars.endOffset,
vars.intermediatePoints,
vars.skipEndSV
)
editor.placeElements(vars.lastSVs)
end
if imgui.Button("Cross multiply in map", style.FULLSIZE_WIDGET_SIZE) then
baseSV = util.filter(
map.ScrollVelocities,
function (k, v)
return v.StartTime >= vars.startOffset
and v.StartTime <= vars.endOffset
end
)
crossSV = sv.linear(
vars.startSV,
vars.endSV,
vars.startOffset,
vars.endOffset,
500, -- used for more accurate linear values when looking up
vars.skipEndSV
)
newSV = sv.crossMultiply(baseSV, crossSV)
actions.RemoveScrollVelocityBatch(baseSV)
editor.placeElements(newSV)
end
gui.tooltip("Multiplies all SVs in the map between the given start and end offset linearly with the given parameters")
-- Save variables
util.saveStateVariables(menuID, vars)
imgui.EndTabItem()
end
end
function menu.stutterSV()
if imgui.BeginTabItem("Stutter") then
local menuID = "stutter"
local vars = {
skipEndSV = false,
skipFinalEndSV = false,
startSV = 1.5,
duration = 0.5,
averageSV = 1.0,
lastSVs = {},
allowNegativeValues = false,
effectDurationMode = 0,
effectDurationValue = 1
}
util.retrieveStateVariables(menuID, vars)
gui.title("Note", true)
imgui.Text("Select some hitobjects and play around!")
gui.title("Settings")
local modes = {
"Distance between notes",
"BPM/measure snap",
"Absolute length"
}
imgui.PushItemWidth(style.CONTENT_WIDTH)
_, vars.effectDurationMode = imgui.Combo("Effect duration mode", vars.effectDurationMode, modes, #modes)
imgui.PopItemWidth()
gui.helpMarker("This determines the effect duration of a single stutter. Hover over the help marker input box in each mode to find out more.")
local helpMarkerText = ""
imgui.PushItemWidth(style.CONTENT_WIDTH)
-- scale with distance between notes
if vars.effectDurationMode == 0 then
_, vars.effectDurationValue = imgui.SliderFloat("Duration Scale", vars.effectDurationValue, 0, 1, "%.2f")
helpMarkerText = "Scales the effect duration together with the distance between two offsets. If left on 1, then all stutters will seamlessly connect to each other."
-- snap
elseif vars.effectDurationMode == 1 then
_, vars.effectDurationValue = imgui.DragFloat("Duration Length", vars.effectDurationValue, 0.01, 0, 10e10, "%.2f")
helpMarkerText = "Input as a fraction of a beat, e.g. 0.25 would represent an interval of 1/4."
-- absolute
elseif vars.effectDurationMode == 2 then
_, vars.effectDurationValue = imgui.DragFloat("Duration Length", vars.effectDurationValue, 0.01, 0, 10e10, "%.2f")
helpMarkerText = "Fixed length, based on a millisecond value."
end
imgui.PopItemWidth()
gui.helpMarker(helpMarkerText)
gui.spacing()
local startSVBounds = {}
imgui.PushItemWidth(style.CONTENT_WIDTH)
if vars.allowNegativeValues then
startSVBounds = {-1000, 1000}
_, vars.startSV = imgui.DragFloat("Start velocity", vars.startSV, 0.01, startSVBounds[1], startSVBounds[2], "%.2fx")
else
startSVBounds = {0, vars.averageSV/vars.duration}
_, vars.startSV = imgui.SliderFloat("Start velocity", vars.startSV, startSVBounds[1], startSVBounds[2], "%.2fx")
end
gui.helpMarker(string.format("Current bounds: %.2fx - %.2fx", startSVBounds[1], startSVBounds[2]))
imgui.PopItemWidth()
imgui.PushItemWidth(style.CONTENT_WIDTH)
_, vars.duration = imgui.SliderFloat("Start SV Duration", vars.duration, 0.0, 1.0, "%.2f")
imgui.PopItemWidth()
-- Update limits after duration has changed
vars.startSV = mathematics.clamp(vars.startSV, startSVBounds[1], startSVBounds[2])
gui.spacing()
gui.averageSV(vars)
if not (vars.effectDurationMode == 0 and vars.effectDurationValue == 1) then
_, vars.skipEndSV = imgui.Checkbox("Skip end SV of individual stutters?", vars.skipEndSV)
gui.helpMarker("If you use any other mode than \"Distance between notes\" and Scale = 1, then the stutter SVs won't directy connect to each other anymore. This adjust the behavior for the end SV of each individual stutter.")
end
_, vars.skipFinalEndSV = imgui.Checkbox("Skip the final end SV?", vars.skipFinalEndSV)
_, vars.allowNegativeValues = imgui.Checkbox("Allow negative Values?", vars.allowNegativeValues)
gui.helpMarker(
"Unexpected things can happen with negative SV, so I do not recommend " ..
"turning on this option unless you are an expert. This will remove the " ..
"limits for start SV. It can then be negative and also exceed the " ..
"value, where the projected equalize SV would be start to become negative."
)
gui.title("Calculate")
if gui.insertButton() then
local offsets = {}
for i, hitObject in pairs(state.SelectedHitObjects) do
offsets[i] = hitObject.StartTime
end
if #offsets == 0 then
statusMessage = "No hitobjects selected!"
elseif #offsets == 1 then
statusMessage = "Needs hitobjects on different offsets selected!"
else
offsets = util.uniqueBy(offsets)
vars.lastSVs = sv.stutter(
table.sort(offsets),
vars.startSV,
vars.duration,
vars.averageSV,
vars.skipEndSV,
vars.skipFinalEndSV,
vars.effectDurationMode,
vars.effectDurationValue
)
editor.placeElements(vars.lastSVs)
end
end
imgui.Text("Projected equalize SV: " .. string.format("%.2fx", (vars.duration*vars.startSV-vars.averageSV)/(vars.duration-1)))
gui.helpMarker("This represents the velocity of the intermediate SV that is used to balance out the initial SV")
util.saveStateVariables(menuID, vars)
imgui.EndTabItem()
end
end
function menu.cubicBezierSV()
local menuID = "cubicBezier"
if imgui.BeginTabItem("Cubic Bezier") then
local vars = {
startOffset = 0,
endOffset = 0,
x1 = 0.35,
y1 = 0.00,
x2 = 0.65,
y2 = 1.00,
averageSV = 1.0,
intermediatePoints = 16,
skipEndSV = false,
lastSVs = {},
lastPositionValues = {},
stringInput = "cubic-bezier(.35,.0,.65,1)"
}
local xBounds = { 0.0, 1.0}
local yBounds = {-1.0, 2.0}
util.retrieveStateVariables(menuID, vars)
gui.title("Note", true)
gui.hyperlink("https://cubic-bezier.com/", "Create a cubic bezier here first!")
gui.title("Offset")
gui.startEndOffset(vars)
gui.title("Values")
local widths = util.calcAbsoluteWidths(style.BUTTON_WIDGET_RATIOS)
if imgui.Button("Parse", {widths[1], style.DEFAULT_WIDGET_HEIGHT}) then
local regex = "(-?%d*%.?%d+)"
captures = {}
for capture, _ in string.gmatch(vars.stringInput, regex) do
statusMessage = statusMessage .. "," .. capture
table.insert(captures, tonumber(capture))
end
if #captures >= 4 then
vars.x1, vars.y1, vars.x2, vars.y2 = table.unpack(captures)
statusMessage = "Copied values"
else
statusMessage = "Invalid string"
end
end
gui.sameLine()
imgui.PushItemWidth(widths[2])
_, vars.stringInput = imgui.InputText("String", vars.stringInput, 50, 4112)
imgui.PopItemWidth()
imgui.SameLine()
imgui.TextDisabled("(?)")
if imgui.IsItemHovered() then
imgui.BeginTooltip()
imgui.TextWrapped("Examples:")
gui.bulletList({
"cubic-bezier(.35,.0,.65,1)",
".17,.67,.83,.67",
"https://cubic-bezier.com/#.76,-0.17,.63,1.35"
})
imgui.TextWrapped("Or anything else that has 4 numbers")
imgui.EndTooltip()
end
imgui.PushItemWidth(style.CONTENT_WIDTH)
local coords = {}
_, coords = imgui.DragFloat4("x1, y1, x2, y2", {vars.x1, vars.y1, vars.x2, vars.y2}, 0.01, -5, 5, "%.2f")
vars.y2, vars.x1, vars.y1, vars.x2 = table.unpack(coords) -- the coords returned are in this order for some stupid reason??
imgui.PopItemWidth()
gui.helpMarker("x: 0.0 - 1.0\ny: -1.0 - 2.0")
-- Set limits here instead of in the DragFloat4, since this also covers the parsed string
vars.x1, vars.x2 = table.unpack(util.mapFunctionToTable({vars.x1, vars.x2}, mathematics.clamp, xBounds))
vars.y1, vars.y2 = table.unpack(util.mapFunctionToTable({vars.y1, vars.y2}, mathematics.clamp, yBounds))
gui.spacing()
gui.averageSV(vars, widths)
gui.title("Utilities")
gui.intermediatePoints(vars)
gui.title("Calculate")
if gui.insertButton() then
statusMessage = "pressed"
vars.lastSVs, vars.lastPositionValues = sv.cubicBezier(
vars.x1,
vars.y1,
vars.x2,
vars.y2,
vars.startOffset,
vars.endOffset,
vars.averageSV,
vars.intermediatePoints,
vars.skipEndSV
)
editor.placeElements(vars.lastSVs)
end
if #vars.lastSVs > 0 then
gui.title("Plots")
gui.plot(vars.lastPositionValues, "Position Data", "y")
gui.plot(vars.lastSVs, "Velocity Data", "Multiplier")
end
util.saveStateVariables(menuID, vars)
imgui.EndTabItem()
end
end
function menu.rangeEditor()
if imgui.BeginTabItem("Range Editor") then
local menuID = "range"
local vars = {
startOffset = 0,
endOffset = 0,
selections = {
[0] = {},
[1] = {},
[2] = {}
},
type = 0,
windowSelectedOpen = false,
selectionFilters = {
StartTime = {active = false, operator = 0, value = 0},
Multiplier = {active = false, operator = 0, value = 0},
EndTime = {active = false, operator = 0, value = 0},
Lane = {active = false, operator = 0, value = 0},
EditorLayer = {active = false, operator = 0, value = 0},
Bpm = {active = false, operator = 0, value = 0}
},
arithmeticActions = {
StartTime = {active = false, operator = 0, value = 0},
Multiplier = {active = false, operator = 0, value = 0},
EndTime = {active = false, operator = 0, value = 0},
Lane = {active = false, operator = 0, value = 0},
EditorLayer = {active = false, operator = 0, value = 0},
Bpm = {active = false, operator = 0, value = 0}
}
}
util.retrieveStateVariables(menuID, vars)
gui.title("Note", true)
imgui.TextWrapped("This is a very powerful tool and " ..
"can potentially erase hours of work, so please be careful and work on a " ..
"temporary difficulty if necessary! Please keep in mind that the selection " ..
"is cleared once you leave the editor (including testplaying).")
gui.title("Range")
gui.startEndOffset(vars)
gui.title("Selection", false, "You can think of the selection as your second clipboard. Once elements are in your selection, you can edit the element's values and/or paste them at different points in the map. Or just delete it, it's up to you.\n\nFilters limit SVs/Notes/BPM Points in the given range to be added/removed. Every active condition must be true (AND). A (OR) can be simulated by adding a range multiple times with different filters.")
local selectableTypes = {
"SVs",
"Notes",
"BPM Points"
}
imgui.PushItemWidth(style.CONTENT_WIDTH)
_, vars.type = imgui.Combo("Selection Type", vars.type, selectableTypes, #selectableTypes)
imgui.PopItemWidth()
local buttonWidths = util.calcAbsoluteWidths({0.5, 0.5})
local addRangeButtonWidth
if #vars.selections[vars.type] > 0 then addRangeButtonWidth = buttonWidths[1]
else addRangeButtonWidth = style.CONTENT_WIDTH end
gui.spacing()
local widths = util.calcAbsoluteWidths({0.25, 0.75}, style.CONTENT_WIDTH - style.DEFAULT_WIDGET_HEIGHT - style.SAMELINE_SPACING)
for i, attribute in pairs(editor.typeAttributes[vars.type]) do
if attribute == "StartTime" then goto continue end -- imagine a conitnue
_, vars.selectionFilters[attribute].active = imgui.Checkbox(
"##ActiveCheckbox" .. attribute, vars.selectionFilters[attribute].active
)
gui.sameLine()
if vars.selectionFilters[attribute].active then
imgui.PushItemWidth(widths[1])
_, vars.selectionFilters[attribute].operator = imgui.Combo(
"##comparisonOperator" .. attribute,
vars.selectionFilters[attribute].operator,
mathematics.comparisonOperators,
#mathematics.comparisonOperators
)
imgui.PopItemWidth()
gui.sameLine()
imgui.PushItemWidth(widths[2])
_, vars.selectionFilters[attribute].value = imgui.InputFloat(attribute, vars.selectionFilters[attribute].value)
imgui.PopItemWidth()
else
imgui.Text(attribute .. " Filter")
end
::continue::
end
gui.spacing()
if imgui.Button("Add range", {addRangeButtonWidth, style.DEFAULT_WIDGET_HEIGHT}) then
local elements = {
[0] = map.ScrollVelocities,
[1] = map.HitObjects,
[2] = map.TimingPoints
}
local previousCount = #vars.selections[vars.type]
-- Find
-- Range filter
local newElements = util.filter(
elements[vars.type],
function(i, element)
return element.StartTime >= vars.startOffset
and element.StartTime <= vars.endOffset
end
)
-- attribute filter
for attribute, filter in pairs(vars.selectionFilters) do
if filter.active then
newElements = util.filter(
newElements,
function(i, element)
return mathematics.evaluateComparison(
mathematics.comparisonOperators[filter.operator + 1],
element[attribute],
filter.value
) end
)
end
end
-- Add
newElements = util.mergeUnique(
vars.selections[vars.type],
newElements,
editor.typeAttributes[vars.type]
)
-- Sort
newElements = table.sort(
newElements,
function(a,b) return a.StartTime < b.StartTime end
)
vars.selections[vars.type] = newElements
if #vars.selections[vars.type] - previousCount == 0 then
statusMessage = string.format("No %s in range!", selectableTypes[vars.type + 1])
else
statusMessage = string.format(
"Added %s %s",
#vars.selections[vars.type] - previousCount,
selectableTypes[vars.type + 1]
)
end
end
if #vars.selections[vars.type] > 0 then
gui.sameLine()
if imgui.Button("Remove range", {buttonWidths[2], style.DEFAULT_WIDGET_HEIGHT}) then
local previousCount = #vars.selections[vars.type]
-- attribute filter
for attribute, filter in pairs(vars.selectionFilters) do
if filter.active then
vars.selections[vars.type] = util.filter(
vars.selections[vars.type],
function(i, element)
return not (mathematics.evaluateComparison(
mathematics.comparisonOperators[filter.operator + 1],
element[attribute],
filter.value
) and (
element.StartTime >= vars.startOffset and
element.StartTime <= vars.endOffset
))
end
)
end
end
if #vars.selections[vars.type] - previousCount == 0 then
statusMessage = string.format("No %s in range!", selectableTypes[vars.type + 1])
else
statusMessage = string.format(
"Removed %s %s",
previousCount - #vars.selections[vars.type],
selectableTypes[vars.type + 1]
)
end
end
gui.sameLine()
imgui.Text(string.format("%s %s in selection", #vars.selections[vars.type], selectableTypes[vars.type + 1]))